]> git.lyx.org Git - lyx.git/blobdiff - src/support/qstring_helpers.cpp
Fix bug #12772
[lyx.git] / src / support / qstring_helpers.cpp
index 19cac062fb5b2ecdc7f70c7162d9b00fd78644be..e39dc7fb3359b90a51d32e19c8be678006820214 100644 (file)
@@ -18,7 +18,8 @@
 #include "support/docstring.h"
 #include "support/qstring_helpers.h"
 
-#include <QRegExp>
+#include <QRegularExpression>
+#include <QLocale>
 #include <QString>
 #include <QVector>
 
@@ -57,7 +58,7 @@ QString toqstr(docstring const & ucs4)
 QString toqstr(char_type ucs4)
 {
 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
-       return QString::fromStdU32String(std::u32string(ucs4, 1));
+       return QString::fromStdU32String(std::u32string(1, ucs4));
 #else
        union { char_type c; uint i; } u = { ucs4 };
        return QString::fromUcs4(&u.i, 1);
@@ -82,9 +83,10 @@ QString charFilterRegExp(QString const & filter)
        QString re = ".*";
        for (QChar const & c : filter) {
                if (c.isLower())
-                       re +=  "["+ QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
+                       re +=  "[" + QRegularExpression::escape(c)
+                                  + QRegularExpression::escape(c.toUpper()) + "]";
                else
-                       re +=  QRegExp::escape(c);
+                       re +=  QRegularExpression::escape(c);
        }
        return re;
 }
@@ -94,13 +96,34 @@ QString charFilterRegExpC(QString const & filter)
        QString re = "(";
        for (QChar const & c : filter) {
                if (c.isLower())
-                       re +=  "["+ QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
+                       re +=  "[" + QRegularExpression::escape(c)
+                              + QRegularExpression::escape(c.toUpper()) + "]";
                else
-                       re +=  QRegExp::escape(c);
+                       re +=  QRegularExpression::escape(c);
        }
        return re + ")";
 }
 
+QString locLengthString(QString const & str)
+{
+       QLocale loc;
+       QString res = str;
+       return res.replace(QString("."), loc.decimalPoint());
+}
+
+
+docstring locLengthDocString(docstring const str)
+{
+       return qstring_to_ucs4(locLengthString(toqstr(str)));
+}
+
+
+QString unlocLengthString(QString const & str)
+{
+       QLocale loc;
+       QString res = str;
+       return res.replace(loc.decimalPoint(), QString("."));
+}
 
 
 } // namespace lyx