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