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 <crash...@googlemail.com>
Date:   Fri Apr 17 22:17:30 2015 +0200

    nhttpd: simplify encodeString function
    
    Signed-off-by: GetAway <get-a...@t-online.de>

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

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Tuxbox-cvs-commits mailing list
Tuxbox-cvs-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tuxbox-cvs-commits

Reply via email to