From 77854ea7bd165f8d9afd2cba1490335a67001ab7 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Enar=20V=C3=A4ikene?= <enar@vaikene.net>
Date: Wed, 30 Nov 2011 15:54:27 +0200
Subject: [PATCH] Numeric character and character entity references are now
 also supported when converting strings to QVariant values. Documentation
 fixes and updates.

---
 src/libs/Common/inifile.h | 14 ++++++++++++--
 src/libs/Common/util.cpp  |  5 +++++
 src/libs/Common/util.h    | 10 ++++++++--
 src/libs/Common/version.h |  4 ++--
 4 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/src/libs/Common/inifile.h b/src/libs/Common/inifile.h
index 2ebe1c1..ecf8737 100644
--- a/src/libs/Common/inifile.h
+++ b/src/libs/Common/inifile.h
@@ -47,7 +47,10 @@ namespace Internal {
  * @code
  * [main]
  * # The full name of this parameter is 'main/name'
- * name = MyApplication
+ * name = "My Application"
+ *
+ * # 4-byte binary version number 1.0.7.10 with the name 'main/version'
+ * version = &#x01;&#x00;&#x07;&#x0a;
  *
  * [extensions/about]
  * # The full name of this parameter is 'extensions/about/module'
@@ -66,7 +69,14 @@ namespace Internal {
  * @li Int - only base 10 (decimal) is allowed;
  * @li Time - 24h time string in the format HH:MM:SS
  * @li UInt - base 16 (hex) if the string is prefixed with '0x'; base 8 if the string starts with '0'; otherwise
- * the value is expected to be base 10 (decimal).
+ * the value is expected to be base 10 (decimal);
+ * @li ByteArray - non-printable bytes and special characters are encoded as numeric character or character entity references;
+ * @li String - non-printable and special characters are encoded as numeric character or character entity references.
+ *
+ * Strings and Byte array values can be enclosed in single or double quotes. The IniFile class does this automatically when
+ * saving String or Byte array values with leading or trailing spaces. Quotes are removed from the parameter value prior
+ * returning the value to the application. Use character entity references "&quot;" and "&apos;" if quotes should be part of
+ * the parameter value.
  */
 class COMMON_EXPORT IniFile
 {
diff --git a/src/libs/Common/util.cpp b/src/libs/Common/util.cpp
index 33f6b4d..30874eb 100644
--- a/src/libs/Common/util.cpp
+++ b/src/libs/Common/util.cpp
@@ -87,6 +87,11 @@ QVariant eVaf::Common::toVariant(QString const & value, QVariant const & default
                     if (ok)
                         return QVariant(c);
                 }
+                else if (value.startsWith('&')) {
+                    QString c = strFromEscapedCharArray(value.toLatin1());
+                    if (c.size() > 0)
+                        return QVariant(c.at(0));
+                }
                 else
                     return QVariant(value.at(0));
             }
diff --git a/src/libs/Common/util.h b/src/libs/Common/util.h
index 8237e7c..486da25 100644
--- a/src/libs/Common/util.h
+++ b/src/libs/Common/util.h
@@ -70,8 +70,10 @@ inline bool isFalse(QString const & str)
  * @li QVariant::Int - base 10 is used;
  * @li QVariant::Double - the decimal point is expecte to be '.' regardless which locale is used;
  * @li QVariant::Bool - tries to use isTrue() and isFalse() methods; otherwise performs a conversion to QVariant::uint;
- * @li QVariant::Char - if the string begins with "\0x", expects it to be an ASCII code in hex; if the
- * string begins with "\0", expects it to be an ASCII code in oct; otherwise uses the first character in the string;
+ * @li QVariant::Char - if the string begins with "\0x", expects it to be a UTF-16 code in hex; if the
+ * string begins with "\0", expects it to be a UTF-16 code in oct; if the string begins with "&", expects it to
+ * be a numeric character reference ("&#nnnn;" or "&#xhhhh;") or a predefined character entity reference;
+ * otherwise uses the first character in the string;
  */
 
 COMMON_EXPORT QVariant toVariant(QString const & value, QVariant const & defaultValue);
@@ -85,6 +87,8 @@ COMMON_EXPORT QVariant toVariant(QString const & value, QVariant const & default
  * be output directly as a printable 7-bit character are output as numeric character references. The result can be
  * directly inserted into XML or HTML documents and later converted back with the eVaf::Common::strFromEscapedCharArray()
  * function.
+ *
+ * For example, "Groß" becomes "Gro&#xdf;".
  */
 COMMON_EXPORT QByteArray strToEscapedCharArray(QString const & str);
 
@@ -107,6 +111,8 @@ COMMON_EXPORT QString strFromEscapedCharArray(QByteArray const & str);
  * directly as printable 7-bit characters are output as numeric character references. The result can be directly
  * inserted into XML or HTML documents and later converted back with the eVaf::Common::binFromEscapedCharArray()
  * function.
+ *
+ * For example, "Hello\r\n" becomes "Hello&#xd;&#xa;".
  */
 COMMON_EXPORT QByteArray binToEscapedCharArray(QByteArray const & src);
 
diff --git a/src/libs/Common/version.h b/src/libs/Common/version.h
index fb1c67f..b164cb5 100644
--- a/src/libs/Common/version.h
+++ b/src/libs/Common/version.h
@@ -25,12 +25,12 @@
 /**
  * Module/library version number in the form major,minor,release,build
  */
-#define VER_FILE_VERSION                0,2,2,10
+#define VER_FILE_VERSION                0,2,2,11
 
 /**
  * Module/library version number in the string format (shall end with \0)
  */
-#define VER_FILE_VERSION_STR            "0.2.2.10\0"
+#define VER_FILE_VERSION_STR            "0.2.2.11\0"
 
 /**
  * Module/library name (shall end with \0)
-- 
2.49.0