From 1ae51ff94d0f1f27a4e4cc657371578db13c3ca1 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 8 Feb 2019 20:26:14 +0100 Subject: Make code compile again (fix bitrot dating back from 2013). --- src/xml_encode_decode.cc | 79 +++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 37 deletions(-) (limited to 'src/xml_encode_decode.cc') 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 + /* char xml_map[][2][16] = - { - { "&", "&" }, // & must be first - { "\'", "'" }, - { "\"", "&qout;" }, - { ">", ">" }, - { "<", "<" }, - { "", "" } // End marker - }; +{ + { "&", "&" }, // & must be first + { "\'", "'" }, + { "\"", "&qout;" }, + { ">", ">" }, + { "<", "<" }, + { "", "" } // End marker +}; */ char xml_map[][2][16] = - { - { "&", "&" }, // & must be first - { "\'", "'" }, - { "\"", """ }, - { ">", ">" }, - { "<", "<" }, - { "", "" } // End marker - }; +{ + { "&", "&" }, // & must be first + { "\'", "'" }, + { "\"", """ }, + { ">", ">" }, + { "<", "<" }, + { "", "" } // 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 -- cgit v1.2.3