diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/xml_encode_decode.cc | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/server/src/xml_encode_decode.cc b/server/src/xml_encode_decode.cc index c5e4917..caf28b2 100644 --- a/server/src/xml_encode_decode.cc +++ b/server/src/xml_encode_decode.cc @@ -46,7 +46,7 @@ std::string xml_encode(std::string str) 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][0]); + pos += strlen(xml_map[map][1]); } } @@ -62,7 +62,7 @@ std::string xml_decode(std::string str) 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][1]); + pos += strlen(xml_map[map][0]); } } @@ -73,22 +73,19 @@ std::string xml_decode(std::string str) int main() { - std::string in = "&A<B>C\"D\'E"; - printf("Input: \"%s\"\n", in.c_str()); - + std::string in = "&A<B>C\"D\'<>\"&E<>"; std::string enc = xml_encode(in); - printf("Encoded: \"%s\"\n", enc.c_str()); - std::string denc = xml_encode(enc); - printf("DoubleEncoded: \"%s\"\n", denc.c_str()); - std::string dec = xml_decode(denc); - printf("Decoded: \"%s\"\n", dec.c_str()); - std::string ddec = xml_decode(dec); - printf("DoubleDecoded: \"%s\"\n", ddec.c_str()); - if( in == ddec && enc == dec) return 0; + printf("Input: \"%s\" %d\n", in.c_str(), in.length()); + printf("Encoded: \"%s\" %d\n", enc.c_str(), enc.length()); + printf("DoubleEncoded: \"%s\" %d\n", denc.c_str(), denc.length()); + printf("Decoded: \"%s\" %d\n", dec.c_str(), dec.length()); + printf("DoubleDecoded: \"%s\" %d\n", ddec.c_str(), ddec.length()); + + if( in == ddec && enc == dec) return 0; return 1; } |