Last active
December 18, 2015 14:59
-
-
Save garethlewin/5801589 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
typedef std::map<std::wstring, std::wstring> tokenMap_t; | |
inline tokenMap_t GetURLTokens(std::wstring input) | |
{ | |
tokenMap_t result; | |
auto tokenStartPos = input.find_first_of(L"?#"); | |
while (tokenStartPos != std::string::npos) | |
{ | |
tokenStartPos++; | |
auto tokenEndPos = input.find_first_of(L"=&", tokenStartPos); | |
std::wstring token = input.substr(tokenStartPos, tokenEndPos-tokenStartPos); | |
std::wstring value; | |
if (tokenEndPos != std::string::npos && input[tokenEndPos] == L'=') | |
{ | |
tokenStartPos = tokenEndPos+1; | |
tokenEndPos = input.find(L"&", tokenStartPos); | |
value = input.substr(tokenStartPos, tokenEndPos-tokenStartPos); | |
} | |
result[token] = value; | |
tokenStartPos = tokenEndPos; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment