Last active
August 29, 2015 14:02
-
-
Save garethlewin/526c62faba37b37c4670 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ParseHeader(const uint8_t* header, | |
size_t headerSize, | |
std::string& verb, | |
std::string& url, | |
urlParameters_t& params) | |
{ | |
using std::begin; | |
using std::end; | |
using std::find; | |
using std::find_first_of; | |
using std::string; | |
const uint8_t urlDelims[] = {' ', '?'}; | |
const uint8_t newlineDelims[] = {'\n', '\r'}; | |
const uint8_t* pos = header; | |
const uint8_t* endOfLine = find_first_of(pos, pos + headerSize, begin(newlineDelims), end(newlineDelims)); | |
if (endOfLine != header+headerSize) | |
{ | |
verb = string(pos, find(pos, endOfLine, ' ')); | |
pos += verb.length(); | |
if (*pos++ == ' ') | |
{ | |
url = string(pos, find_first_of(pos, endOfLine, begin(urlDelims), end(urlDelims))); | |
pos += url.length(); | |
if (*pos++ == '?') | |
{ | |
const uint8_t* endOfParams = find_first_of (pos, endOfLine, begin(newlineDelims), end(newlineDelims)); | |
if (endOfParams != pos) | |
{ | |
const uint8_t* delim = nullptr; | |
do | |
{ | |
delim = find(pos, endOfParams, '&'); | |
const uint8_t* equalSign = find(pos, delim, '='); | |
string paramName(pos, equalSign); | |
string paramValue; | |
if (equalSign != delim) | |
{ | |
paramValue = string (equalSign+1, delim); | |
} | |
params.push_back( urlParameter_t(paramName, paramValue) ); | |
pos = delim+1; | |
} while (delim != endOfParams); | |
} | |
} | |
} | |
url.append("blah"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment