Mode [un]locLengthString() methods to support/qstring_helpers

This commit is contained in:
Juergen Spitzmueller 2022-08-09 17:27:53 +02:00
parent 079bc8ca40
commit 9214f92599
4 changed files with 30 additions and 22 deletions

View File

@ -214,22 +214,6 @@ QString formatLocFPNumber(double d)
} }
QString locLengthString(QString const & str)
{
QLocale loc;
QString res = str;
return res.replace(QString("."), loc.decimalPoint());
}
QString unlocLengthString(QString const & str)
{
QLocale loc;
QString res = str;
return res.replace(loc.decimalPoint(), QString("."));
}
bool SortLocaleAware(QString const & lhs, QString const & rhs) bool SortLocaleAware(QString const & lhs, QString const & rhs)
{ {
return QString::localeAwareCompare(lhs, rhs) < 0; return QString::localeAwareCompare(lhs, rhs) < 0;

View File

@ -72,12 +72,6 @@ void doubleToWidget(QLineEdit * input, std::string const & value,
*/ */
QString formatLocFPNumber(double d); QString formatLocFPNumber(double d);
/// Method to replace dot with localized decimal separator
QString locLengthString(QString const & str);
/// Method to replace localized decimal separator by dot
QString unlocLengthString(QString const & str);
/// Method to sort QStrings locale-aware (e.g. in combo widgets) /// Method to sort QStrings locale-aware (e.g. in combo widgets)
bool SortLocaleAware(QString const & lhs, QString const & rhs); bool SortLocaleAware(QString const & lhs, QString const & rhs);

View File

@ -19,6 +19,7 @@
#include "support/qstring_helpers.h" #include "support/qstring_helpers.h"
#include <QRegExp> #include <QRegExp>
#include <QLocale>
#include <QString> #include <QString>
#include <QVector> #include <QVector>
@ -101,6 +102,26 @@ QString charFilterRegExpC(QString const & filter)
return re + ")"; 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 } // namespace lyx

View File

@ -92,6 +92,15 @@ QString charFilterRegExp(QString const & filter);
*/ */
QString charFilterRegExpC(QString const & filter); QString charFilterRegExpC(QString const & filter);
/// Method to replace dot with localized decimal separator
QString locLengthString(QString const & str);
/// Same for doscstring
docstring locLengthDocString(docstring const str);
/// Method to replace localized decimal separator by dot
QString unlocLengthString(QString const & str);
} // namespace lyx } // namespace lyx
#endif // QSTRING_HELPERS_H #endif // QSTRING_HELPERS_H