]> git.lyx.org Git - lyx.git/blobdiff - src/support/qstring_helpers.cpp
Fix bug #12772
[lyx.git] / src / support / qstring_helpers.cpp
index 5a79ad11b63e94fd5a3ce1ce65b7a3b41c91652b..e39dc7fb3359b90a51d32e19c8be678006820214 100644 (file)
 
 #include <config.h>
 
-#include "support/qstring_helpers.h"\r
-\r
-#include "support/debug.h"\r
+#include "support/qstring_helpers.h"
+
+#include "support/debug.h"
 #include "support/docstring.h"
+#include "support/qstring_helpers.h"
 
+#include <QRegularExpression>
+#include <QLocale>
 #include <QString>
 #include <QVector>
 
 namespace lyx {
 
-LyXErr & operator<<(LyXErr & err, QString const & str)\r
-{\r
-       return err << fromqstr(str);\r
-}\r
-\r
-\r
+LyXErr & operator<<(LyXErr & err, QString const & str)
+{
+       return err << fromqstr(str);
+}
+
+
 QString toqstr(char const * str)
 {
        return QString::fromUtf8(str);
@@ -45,13 +48,21 @@ QString toqstr(docstring const & ucs4)
        // need to be superfast.
        if (ucs4.empty())
                return QString();
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+       return QString::fromStdU32String(reinterpret_cast<std::u32string const &>(ucs4));
+#else
        return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length());
+#endif
 }
 
 QString toqstr(char_type ucs4)
 {
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+       return QString::fromStdU32String(std::u32string(1, ucs4));
+#else
        union { char_type c; uint i; } u = { ucs4 };
        return QString::fromUcs4(&u.i, 1);
+#endif
 }
 
 docstring qstring_to_ucs4(QString const & qstr)
@@ -67,4 +78,52 @@ std::string fromqstr(QString const & str)
        return str.isEmpty() ? std::string() : std::string(str.toUtf8());
 }
 
+QString charFilterRegExp(QString const & filter)
+{
+       QString re = ".*";
+       for (QChar const & c : filter) {
+               if (c.isLower())
+                       re +=  "[" + QRegularExpression::escape(c)
+                                  + QRegularExpression::escape(c.toUpper()) + "]";
+               else
+                       re +=  QRegularExpression::escape(c);
+       }
+       return re;
+}
+
+QString charFilterRegExpC(QString const & filter)
+{
+       QString re = "(";
+       for (QChar const & c : filter) {
+               if (c.isLower())
+                       re +=  "[" + QRegularExpression::escape(c)
+                              + QRegularExpression::escape(c.toUpper()) + "]";
+               else
+                       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