From ba87499ecae1dd22787737e814624e47abef45b6 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 20 Jun 2010 00:35:09 -0400 Subject: [PATCH] FF4 - Removed encodings for ',' -> ',', ''' -> '&squot;', and ':' -> '&colon'. - Retained decodings to provide backward compatibility. --- src/Att.cpp | 43 +++++++++++++++++++------------------------ src/tests/att.t.cpp | 6 +++--- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/Att.cpp b/src/Att.cpp index 1aa0539bb..b68c55d93 100644 --- a/src/Att.cpp +++ b/src/Att.cpp @@ -744,12 +744,12 @@ void Att::dequote (std::string& value) const //////////////////////////////////////////////////////////////////////////////// // Encode values prior to serialization. // \t -> &tab; -// ' -> &squot; +// ' -> &squot; <-- deprecated, no need to encode/decod single quotes. // " -> &dquot; -// , -> , +// , -> , <-- deprecated, no need to encode/decode commas. // [ -> &open; // ] -> &close; -// : -> : +// : -> : <-- deprecated, no need to encode/decode colons. void Att::encode (std::string& value) const { std::string::size_type i; @@ -757,23 +757,14 @@ void Att::encode (std::string& value) const while ((i = value.find ('\t')) != std::string::npos) value.replace (i, 1, "&tab;"); // no i18n - while ((i = value.find ('\'')) != std::string::npos) - value.replace (i, 1, "&squot;"); // no i18n - while ((i = value.find ('"')) != std::string::npos) value.replace (i, 1, "&dquot;"); // no i18n - while ((i = value.find (',')) != std::string::npos) - value.replace (i, 1, ","); // no i18n - while ((i = value.find ('[')) != std::string::npos) value.replace (i, 1, "&open;"); // no i18n while ((i = value.find (']')) != std::string::npos) value.replace (i, 1, "&close;"); // no i18n - - while ((i = value.find (':')) != std::string::npos) - value.replace (i, 1, ":"); // no i18n } //////////////////////////////////////////////////////////////////////////////// @@ -789,28 +780,32 @@ void Att::decode (std::string& value) const { std::string::size_type i; - while ((i = value.find ("&tab;")) != std::string::npos) // no i18n + // Supported encodings. + while ((i = value.find ("&tab;")) != std::string::npos) value.replace (i, 5, "\t"); - while ((i = value.find ("&dquot;")) != std::string::npos) // no i18n + while ((i = value.find ("&dquot;")) != std::string::npos) value.replace (i, 7, "\""); - while ((i = value.find ("&squot;")) != std::string::npos) // no i18n - value.replace (i, 7, "'"); - - while ((i = value.find (""")) != std::string::npos) // no i18n + while ((i = value.find (""")) != std::string::npos) value.replace (i, 6, "\""); - while ((i = value.find (",")) != std::string::npos) // no i18n - value.replace (i, 7, ","); - - while ((i = value.find ("&open;")) != std::string::npos) // no i18n + while ((i = value.find ("&open;")) != std::string::npos) value.replace (i, 6, "["); - while ((i = value.find ("&close;")) != std::string::npos) // no i18n + while ((i = value.find ("&close;")) != std::string::npos) value.replace (i, 7, "]"); - while ((i = value.find (":")) != std::string::npos) // no i18n + // Support for deprecated encodings. These cannot be removed or old files + // will not be parsable. Not just old files - completed.data can contain + // tasks formatted/encoded using these. + while ((i = value.find ("&squot;")) != std::string::npos) + value.replace (i, 7, "'"); + + while ((i = value.find (",")) != std::string::npos) + value.replace (i, 7, ","); + + while ((i = value.find (":")) != std::string::npos) value.replace (i, 7, ":"); } diff --git a/src/tests/att.t.cpp b/src/tests/att.t.cpp index 66df3d8e5..816587fb6 100644 --- a/src/tests/att.t.cpp +++ b/src/tests/att.t.cpp @@ -77,7 +77,7 @@ int main (int argc, char** argv) a5.value ("\""); t.is (a5.composeF4 (), "name:\"&dquot;\"", "Att::composeF4 encoded \""); a5.value ("\t\",[]:"); - t.is (a5.composeF4 (), "name:\"&tab;&dquot;,&open;&close;:\"", "Att::composeF4 fully encoded \\t\",[]:"); + t.is (a5.composeF4 (), "name:\"&tab;&dquot;,&open;&close;:\"", "Att::composeF4 fully encoded \\t\",[]:"); Att a6 ("name", 6); t.is (a6.value_int (), 6, "Att::value_int get"); @@ -187,8 +187,8 @@ int main (int argc, char** argv) n = Nibbler ("name:\"&tab;",&open;&close;:\""); a7.parse (n); - t.is (a7.composeF4 (), "name:\"&tab;&dquot;,&open;&close;:\"", - "Att::parse (name:\"&tab;",&open;&close;:\")"); + t.is (a7.composeF4 (), "name:\"&tab;&dquot;,&open;&close;:\"", + "Att::parse (name:\"&tab;",&open;&close;:\")"); n = Nibbler ("total gibberish"); good = true;