From b7c2fd0d9cd8242b68332c2cc6a6d069e25ee2fc Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 3 Jul 2014 13:38:18 -0400 Subject: [PATCH] Legacy - Now maps unsupported duration values to supported values. --- src/Task.cpp | 12 +++--------- src/legacy.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.h | 2 ++ 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 32b104188..ec6e6d78c 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -555,6 +555,7 @@ bool Task::is_overdue () const // void Task::parse (const std::string& input) { + // TODO Is this simply a 'chomp'? std::string copy; if (input[input.length () - 1] == '\n') copy = input.substr (0, input.length () - 1); @@ -588,15 +589,8 @@ void Task::parse (const std::string& input) nl.skip (':') && nl.getQuoted ('"', value)) { - // Experimental legacy value translation of 'recur:m' --> 'recur:mo'. - if (name == "recur" && - digitsOnly (value.substr (0, value.length () - 1)) && - value[value.length () - 1] == 'm') - value += 'o'; - - // TW-1274, Standardization. - if (name == "modification") - name = "modified"; + legacyAttributeMap (name); + legacyValueMap (name, value); if (name.substr (0, 11) == "annotation_") ++annotation_count; diff --git a/src/legacy.cpp b/src/legacy.cpp index abe386503..79dc277d7 100644 --- a/src/legacy.cpp +++ b/src/legacy.cpp @@ -25,6 +25,7 @@ //////////////////////////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -161,3 +162,55 @@ std::string legacyCheckForDeprecatedColumns () } //////////////////////////////////////////////////////////////////////////////// +void legacyAttributeMap (std::string& name) +{ + // TW-1274 + if (name == "modification") + name = "modified"; +} + +//////////////////////////////////////////////////////////////////////////////// +void legacyValueMap (const std::string& name, std::string& value) +{ + // One-time initialization value mapping. + static std::map mapping; + if (mapping.size () == 0) + { + mapping["hrs"] = "hours"; + mapping["hrs"] = "hours"; + mapping["hr"] = "hours"; + mapping["mins"] = "minutes"; + mapping["mnths"] = "months"; + mapping["mths"] = "months"; + mapping["mth"] = "months"; + mapping["mos"] = "months"; + mapping["qrtrs"] = "quarters"; + mapping["qtrs"] = "quarters"; + mapping["qtr"] = "quarters"; + mapping["secs"] = "seconds"; + mapping["sec"] = "seconds"; + mapping["s"] = "seconds"; + mapping["wks"] = "weeks"; + mapping["wk"] = "weeks"; + mapping["yrs"] = "years"; + mapping["yr"] = "years"; + } + + if (name == "recur") + { + std::size_t letter = value.find_first_not_of ("0123456789."); + if (letter == std::string::npos) + letter = 0; + + std::map ::iterator i = mapping.find (value.substr (letter)); + if (i != mapping.end ()) + { + if (letter) + value = value.substr (0, letter) + i->second; + else + value = i->second; + } + } +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/main.h b/src/main.h index df6990882..0e7925e3d 100644 --- a/src/main.h +++ b/src/main.h @@ -86,6 +86,8 @@ void legacySortColumnMap (std::string&); std::string legacyCheckForDeprecatedColor (); std::string legacyCheckForDeprecatedVariables (); std::string legacyCheckForDeprecatedColumns (); +void legacyAttributeMap (std::string&); +void legacyValueMap (const std::string&, std::string&); // list template ///////////////////////////////////////////////////////////////////////////////