[Commits] : Tuxbox-GIT: apps branch master updated. CVS-Final-530-gffe9220
Tuxbox Sources
Brought to you by:
dbt1
|
From: GetAway <tux...@ne...> - 2015-04-17 20:18:34
|
Project "Tuxbox-GIT: apps":
The branch, master has been updated
via ffe922052372ccea16f63bb29d726ffa040befc6 (commit)
from 22f2c379569e8fe6d9da34c78957bd3260348a4b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ffe922052372ccea16f63bb29d726ffa040befc6
Author: Jacek Jendrzej <cra...@go...>
Date: Fri Apr 17 22:17:30 2015 +0200
nhttpd: simplify encodeString function
Signed-off-by: GetAway <get...@t-...>
diff --git a/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/helper.cpp b/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/helper.cpp
index e84274b..74e3fff 100644
--- a/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/helper.cpp
+++ b/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/helper.cpp
@@ -239,31 +239,24 @@ std::string decodeString(std::string encodedString)
//-----------------------------------------------------------------------------
// 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' );
- char *newString = (char *)result.c_str();
- char *dstring = (char *)decodedString.c_str();
- char one_char;
- if(len == result.length()) // got memory needed
- {
- 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;
- }
- else
+ for (unsigned int i=0; i<decodedString.length(); i++)
{
- return "";
- }
+ const char one_char = decodedString[i];
+ if (isalnum(one_char)) {
+ result += one_char;
+ } else {
+ snprintf(buf,sizeof(buf), "&#%d;",(unsigned char) one_char);
+ result +=buf;
+ }
+ }
+ result+='\0';
+ result.reserve();
+ return result;
}
//-----------------------------------------------------------------------------
diff --git a/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/helper.h b/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/helper.h
index 2d570ac..a5dc11e 100644
--- a/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/helper.h
+++ b/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/helper.h
@@ -22,7 +22,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);
//-----------------------------------------------------------------------------
-----------------------------------------------------------------------
Summary of changes:
.../neutrino/daemons/nhttpd/yhttpd_core/helper.cpp | 37 ++++++++------------
.../neutrino/daemons/nhttpd/yhttpd_core/helper.h | 2 +-
2 files changed, 16 insertions(+), 23 deletions(-)
--
Tuxbox-GIT: apps
|