X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Fqstring_helpers.cpp;h=e39dc7fb3359b90a51d32e19c8be678006820214;hb=4ed0312c51704780af1c452d3a82a84171b3725a;hp=1e421ca132552e08e624e8abfb22e27d336d85aa;hpb=1e4f4fcd914932ea3ecc223eece2b4bb4bb469ff;p=lyx.git diff --git a/src/support/qstring_helpers.cpp b/src/support/qstring_helpers.cpp index 1e421ca132..e39dc7fb33 100644 --- a/src/support/qstring_helpers.cpp +++ b/src/support/qstring_helpers.cpp @@ -12,14 +12,25 @@ #include +#include "support/qstring_helpers.h" + +#include "support/debug.h" #include "support/docstring.h" -#include "support/docstring.h" +#include "support/qstring_helpers.h" +#include +#include #include #include namespace lyx { +LyXErr & operator<<(LyXErr & err, QString const & str) +{ + return err << fromqstr(str); +} + + QString toqstr(char const * str) { return QString::fromUtf8(str); @@ -35,13 +46,23 @@ QString toqstr(docstring const & ucs4) { // If possible we let qt do the work, since this version does not // need to be superfast. + if (ucs4.empty()) + return QString(); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return QString::fromStdU32String(reinterpret_cast(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) @@ -57,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