mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +02:00
nhttpd simplify encodeString function
This commit is contained in:
@@ -216,30 +216,25 @@ std::string decodeString(std::string encodedString) {
|
||||
//-----------------------------------------------------------------------------
|
||||
// HTMLEncode std::string
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string encodeString(std::string decodedString) {
|
||||
unsigned int len = sizeof(char) * decodedString.length() * 5 + 1;
|
||||
std::string result(len, '\0');
|
||||
char *newString = (char *) result.c_str();
|
||||
char one_char;
|
||||
if (len == result.length()) // got memory needed
|
||||
std::string encodeString(const std::string &decodedString)
|
||||
{
|
||||
char *dstring = (char *) decodedString.c_str();
|
||||
while ((one_char = *dstring++)) /* use the null character as a loop terminator */
|
||||
{
|
||||
if (isalnum(one_char))
|
||||
*newString++ = one_char;
|
||||
else
|
||||
newString += snprintf(newString,result.length(), "&#%d;",
|
||||
(unsigned char) one_char);
|
||||
}
|
||||
std::string result="";
|
||||
char buf[10]= {0};
|
||||
|
||||
*newString = '\0'; /* when done copying the string,need to terminate w/ null char */
|
||||
result.resize((unsigned int) (newString - result.c_str()), '\0');
|
||||
return result;
|
||||
for (unsigned int i=0; i<decodedString.length(); i++)
|
||||
{
|
||||
const char one_char = decodedString[i];
|
||||
if (isalnum(one_char)) {
|
||||
result += one_char;
|
||||
} else {
|
||||
return "";
|
||||
snprintf(buf,sizeof(buf), "&#%d;",(unsigned char) one_char);
|
||||
result +=buf;
|
||||
}
|
||||
}
|
||||
result+='\0';
|
||||
result.reserve();
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// returns string in lower case
|
||||
|
@@ -23,7 +23,7 @@ void correctTime(struct tm *zt);
|
||||
std::string itoa(unsigned int conv);
|
||||
std::string itoh(unsigned int conv);
|
||||
std::string decodeString(std::string encodedString);
|
||||
std::string encodeString(std::string decodedString);
|
||||
std::string encodeString(const std::string &decodedString);
|
||||
std::string string_tolower(std::string str);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user