JSON Strings and GC Tokens

.. fix json writing so that user metadata no longer conflicts
   with the tokens used by GoldenCheetah, e.g. a user entered
   "NM" in the workout code and that conflicted with the
   token used to delimit a torque value.

.. all user strings are now saved with a space " " appended to
   the value and when read, if there is a trailing space it is
   removed.
This commit is contained in:
Mark Liversedge
2014-11-12 06:28:31 +00:00
parent 4dcde2a8ca
commit 2b4c328071

View File

@@ -78,6 +78,9 @@ static QString protect(const QString string)
s.replace("\f", "\\f"); // formfeed
s.replace("/", "\\/"); // solidus
// add a trailing space to avoid conflicting with GC special tokens
s += " ";
return s;
}
@@ -91,6 +94,9 @@ static QString unprotect(const char * string)
// in quotes. Lets strip those first
QString s = string2.mid(1,string2.length()-2);
// does it end with a space (to avoid token conflict) ?
if (s.endsWith(" ")) s = s.mid(0, s.length()-1);
// now un-escape the control characters
s.replace("\\t", "\t"); // tab
s.replace("\\n", "\n"); // newline