From 1e867ede415c6a0280ab9bd1e959d159678ce50f Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 8 Sep 2008 09:55:13 +0000 Subject: Fixed fizzling bug in xml_encoder_decoder. --- server/src/xml_encode_decode.cc | 23 ++++++++++------------- 1 file 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 = "&AC\"D\'E"; - printf("Input: \"%s\"\n", in.c_str()); - + std::string in = "&AC\"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; } -- cgit v1.2.3