diff options
author | deva <deva> | 2008-09-08 09:55:13 +0000 |
---|---|---|
committer | deva <deva> | 2008-09-08 09:55:13 +0000 |
commit | 1e867ede415c6a0280ab9bd1e959d159678ce50f (patch) | |
tree | e3ff7efe6e3da4c6329156dda0f63826b9a971eb /server/src/xml_encode_decode.cc | |
parent | 2ee36211ba872bc6a944a85a3104a751d4fda254 (diff) |
Fixed fizzling bug in xml_encoder_decoder.
Diffstat (limited to 'server/src/xml_encode_decode.cc')
-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; } |