Permalink
Browse files

CURL::Encode: don't use locale-dependent isalnum, refactoring, add co…

…mments
  • Loading branch information...
1 parent f6b77fe commit 6a641bf832dc621f253d268b2d29b7766acd4085 @Karlson2k Karlson2k committed Jan 14, 2014
Showing with 9 additions and 12 deletions.
  1. +9 −12 xbmc/URL.cpp
View
@@ -745,24 +745,21 @@ void CURL::Decode(CStdString& strURLData)
void CURL::Encode(CStdString& strURLData)
{
- CStdString strResult;
+ std::string strResult;
/* wonder what a good value is here is, depends on how often it occurs */
strResult.reserve( strURLData.length() * 2 );
- for (int i = 0; i < (int)strURLData.size(); ++i)
+ for (size_t i = 0; i < strURLData.size(); ++i)
{
- int kar = (unsigned char)strURLData[i];
- //if (kar == ' ') strResult += '+'; // obsolete
- if (isalnum(kar) || strchr("-_.!()" , kar) ) // Don't URL encode these according to RFC1738
- {
- strResult += kar;
- }
+ const char kar = strURLData[i];
+
+ // Don't URL encode "-_.!()" according to RFC1738
+ // TODO: Update it to "-_.~" after Gotham according to RFC3986
+ if (StringUtils::isasciialphanum(kar) || kar == '-' || kar == '.' || kar == '_' || kar == '!' || kar == '(' || kar == ')')
+ strResult.push_back(kar);
else
- {
- CStdString strTmp = StringUtils::Format("%%%02.2x", kar);
- strResult += strTmp;
- }
+ strResult += StringUtils::Format("%%%02.2x", (unsigned int)((unsigned char)kar)); // TODO: Change to "%%%02.2X" after Gotham
}
strURLData = strResult;
}

0 comments on commit 6a641bf

Please sign in to comment.