summaryrefslogtreecommitdiff
path: root/src/xml_encode_decode.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/xml_encode_decode.cc')
-rw-r--r--src/xml_encode_decode.cc79
1 files changed, 42 insertions, 37 deletions
diff --git a/src/xml_encode_decode.cc b/src/xml_encode_decode.cc
index 1c0e377..b1777d9 100644
--- a/src/xml_encode_decode.cc
+++ b/src/xml_encode_decode.cc
@@ -26,59 +26,64 @@
*/
#include "xml_encode_decode.h"
#include <string.h>
+
/*
char xml_map[][2][16] =
- {
- { "&", "&amp;" }, // & must be first
- { "\'", "&apos;" },
- { "\"", "&qout;" },
- { ">", "&gt;" },
- { "<", "&lt;" },
- { "", "" } // End marker
- };
+{
+ { "&", "&amp;" }, // & must be first
+ { "\'", "&apos;" },
+ { "\"", "&qout;" },
+ { ">", "&gt;" },
+ { "<", "&lt;" },
+ { "", "" } // End marker
+};
*/
char xml_map[][2][16] =
- {
- { "&", "&#38;" }, // & must be first
- { "\'", "&#39;" },
- { "\"", "&#34;" },
- { ">", "&#62;" },
- { "<", "&#60;" },
- { "", "" } // End marker
- };
+{
+ { "&", "&#38;" }, // & must be first
+ { "\'", "&#39;" },
+ { "\"", "&#34;" },
+ { ">", "&#62;" },
+ { "<", "&#60;" },
+ { "", "" } // End marker
+};
#define MAX_MAPS 5
std::string xml_encode(std::string str)
{
- size_t pos;
+ size_t pos;
- for( int map = 0; map < MAX_MAPS; map++ ) {
- pos = 0;
- while( ( pos = str.find(xml_map[map][0], pos) ) != std::string::npos) {
- str.replace(pos, strlen(xml_map[map][0]), xml_map[map][1]);
- pos += strlen(xml_map[map][1]);
- }
- }
+ for(int map = 0; map < MAX_MAPS; map++)
+ {
+ pos = 0;
+ while((pos = str.find(xml_map[map][0], pos)) != std::string::npos)
+ {
+ str.replace(pos, strlen(xml_map[map][0]), xml_map[map][1]);
+ pos += strlen(xml_map[map][1]);
+ }
+ }
- return str;
+ return str;
}
std::string xml_decode(std::string str)
{
- size_t pos;
-
- // Traverse backwards, to handle '&' last.
- for( int map = MAX_MAPS - 1; map > -1; map-- ) {
- pos = 0;
- while( ( pos = str.find(xml_map[map][1], pos) ) != std::string::npos) {
- str.replace(pos, strlen(xml_map[map][1]), xml_map[map][0]);
- pos += strlen(xml_map[map][0]);
- }
- }
-
- return str;
+ size_t pos;
+
+ // Traverse backwards, to handle '&' last.
+ for(int map = MAX_MAPS - 1; map > -1; map--)
+ {
+ pos = 0;
+ while((pos = str.find(xml_map[map][1], pos)) != std::string::npos)
+ {
+ str.replace(pos, strlen(xml_map[map][1]), xml_map[map][0]);
+ pos += strlen(xml_map[map][0]);
+ }
+ }
+
+ return str;
}
#ifdef TEST_XML_ENCODE_DECODE