]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.cpp
Fix bug 9798.
[lyx.git] / src / support / lstrings.cpp
index 02ecbe1d9e9d93eb5ce36b7891195c0d27a7cc79..21fe05aa09389fb1e04b7518529d64793fe395ab 100644 (file)
@@ -164,6 +164,26 @@ bool isNumber(char_type c)
 }
 
 
+bool isEuropeanNumberSeparator(char_type c)
+{
+       if (!is_utf16(c))
+               // assume that no non-utf16 character is a numeral
+               // c outside the UCS4 range is catched as well
+               return false;
+       return ucs4_to_qchar(c).direction() == QChar::DirES;
+}
+
+
+bool isEuropeanNumberTerminator(char_type c)
+{
+       if (!is_utf16(c))
+               // assume that no non-utf16 character is a numeral
+               // c outside the UCS4 range is catched as well
+               return false;
+       return ucs4_to_qchar(c).direction() == QChar::DirET;
+}
+
+
 bool isDigitASCII(char_type c)
 {
        return '0' <= c && c <= '9';
@@ -1317,7 +1337,8 @@ docstring wrapParas(docstring const & str, int const indent,
 namespace {
 
 template<typename String> vector<String> const
-getVectorFromStringT(String const & str, String const & delim, bool keepempty)
+getVectorFromStringT(String const & str, String const & delim,
+                     bool keepempty, bool trimit)
 {
 // Lars would like this code to go, but for now his replacement (below)
 // doesn't fullfil the same function. I have, therefore, reactivated the
@@ -1326,14 +1347,15 @@ getVectorFromStringT(String const & str, String const & delim, bool keepempty)
        vector<String> vec;
        if (str.empty())
                return vec;
-       String keys = rtrim(str);
+       String keys = trimit ? rtrim(str) : str;
        while (true) {
                size_t const idx = keys.find(delim);
                if (idx == String::npos) {
-                       vec.push_back(ltrim(keys));
+                       vec.push_back(trimit ? ltrim(keys) : keys);
                        break;
                }
-               String const key = trim(keys.substr(0, idx));
+               String const key = trimit ?
+                       trim(keys.substr(0, idx)) : keys.substr(0, idx);
                if (!key.empty() || keepempty)
                        vec.push_back(key);
                size_t const start = idx + delim.size();
@@ -1371,18 +1393,16 @@ template<typename String> const String
 
 
 vector<string> const getVectorFromString(string const & str,
-                                        string const & delim,
-                                        bool keepempty)
+        string const & delim, bool keepempty, bool trimit)
 {
-       return getVectorFromStringT<string>(str, delim, keepempty);
+       return getVectorFromStringT<string>(str, delim, keepempty, trimit);
 }
 
 
 vector<docstring> const getVectorFromString(docstring const & str,
-                                           docstring const & delim,
-                                           bool keepempty)
+        docstring const & delim, bool keepempty, bool trimit)
 {
-       return getVectorFromStringT<docstring>(str, delim, keepempty);
+       return getVectorFromStringT<docstring>(str, delim, keepempty, trimit);
 }
 
 
@@ -1431,6 +1451,14 @@ std::string formatFPNumber(double x)
 }
 
 
+docstring to_percent_encoding(docstring const & in, docstring const & ex)
+{
+       QByteArray input = toqstr(in).toUtf8();
+       QByteArray excludes = toqstr(ex).toUtf8();
+       return qstring_to_ucs4(QString(input.toPercentEncoding(excludes)));
+}
+
+
 docstring bformat(docstring const & fmt, int arg1)
 {
        LATTEST(contains(fmt, from_ascii("%1$d")));