2017-01-03 10:14:32 +01:00
|
|
|
/***************************************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2016 Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
**
|
|
|
|
** Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
|
|
** software and associated documentation files (the "Software"), to deal in the Software
|
|
|
|
** without restriction, including without limitation the rights to use, copy, modify,
|
|
|
|
** merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
** permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
**
|
|
|
|
** The above copyright notice and this permission notice shall be included in all copies or
|
|
|
|
** substantial portions of the Software.
|
|
|
|
**
|
|
|
|
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
|
|
** NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
**
|
|
|
|
******************************************************************************************************/
|
|
|
|
|
|
|
|
#include "qmudef.h"
|
|
|
|
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QSet>
|
|
|
|
|
|
|
|
enum State
|
|
|
|
{
|
|
|
|
Init = 0,
|
|
|
|
Sign = 1,
|
|
|
|
Thousand = 2,
|
|
|
|
Mantissa = 3,
|
|
|
|
Dot = 4,
|
|
|
|
Abscissa = 5,
|
|
|
|
ExpMark = 6,
|
|
|
|
ExpSign = 7,
|
|
|
|
Exponent = 8,
|
|
|
|
Done = 9
|
|
|
|
};
|
|
|
|
|
|
|
|
enum InputToken
|
|
|
|
{
|
|
|
|
InputSign = 1,
|
|
|
|
InputThousand = 2,
|
|
|
|
InputDigit = 3,
|
|
|
|
InputDot = 4,
|
|
|
|
InputExp = 5
|
|
|
|
};
|
|
|
|
|
|
|
|
static const QChar QmuEOF = QChar(static_cast<ushort>(0xffff)); //guaranteed not to be a character.
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto GetChar(const QString &formula, int &index) -> QChar
|
2017-01-03 10:14:32 +01:00
|
|
|
{
|
|
|
|
if (index >= formula.size())
|
|
|
|
{
|
|
|
|
return QmuEOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return formula.at(index++);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto EatWhiteSpace(const QString &formula, int &index) -> QChar
|
2017-01-03 10:14:32 +01:00
|
|
|
{
|
|
|
|
QChar c;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c = GetChar(formula, index);
|
|
|
|
}
|
|
|
|
while ( c != QmuEOF && c.isSpace() );
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto CheckChar(QChar &c, const QLocale &locale, const QChar &decimal, const QChar &thousand) -> int
|
2017-01-03 10:14:32 +01:00
|
|
|
{
|
|
|
|
INIT_LOCALE_VARIABLES(locale);
|
2017-07-26 18:28:26 +02:00
|
|
|
Q_UNUSED(decimalPoint)
|
|
|
|
Q_UNUSED(groupSeparator)
|
2017-01-03 10:14:32 +01:00
|
|
|
|
|
|
|
if (c == positiveSign)
|
|
|
|
{
|
|
|
|
c = '+';
|
|
|
|
return InputToken::InputSign;
|
|
|
|
}
|
|
|
|
else if (c == negativeSign)
|
|
|
|
{
|
|
|
|
c = '-';
|
|
|
|
return InputToken::InputSign;
|
|
|
|
}
|
|
|
|
else if (c == sign0)
|
|
|
|
{
|
|
|
|
c = '0';
|
|
|
|
return InputToken::InputDigit;
|
|
|
|
}
|
|
|
|
else if (c == sign1)
|
|
|
|
{
|
|
|
|
c = '1';
|
|
|
|
return InputToken::InputDigit;
|
|
|
|
}
|
|
|
|
else if (c == sign2)
|
|
|
|
{
|
|
|
|
c = '2';
|
|
|
|
return InputToken::InputDigit;
|
|
|
|
}
|
|
|
|
else if (c == sign3)
|
|
|
|
{
|
|
|
|
c = '3';
|
|
|
|
return InputToken::InputDigit;
|
|
|
|
}
|
|
|
|
else if (c == sign4)
|
|
|
|
{
|
|
|
|
c = '4';
|
|
|
|
return InputToken::InputDigit;
|
|
|
|
}
|
|
|
|
else if (c == sign5)
|
|
|
|
{
|
|
|
|
c = '5';
|
|
|
|
return InputToken::InputDigit;
|
|
|
|
}
|
|
|
|
else if (c == sign6)
|
|
|
|
{
|
|
|
|
c = '6';
|
|
|
|
return InputToken::InputDigit;
|
|
|
|
}
|
|
|
|
else if (c == sign7)
|
|
|
|
{
|
|
|
|
c = '7';
|
|
|
|
return InputToken::InputDigit;
|
|
|
|
}
|
|
|
|
else if (c == sign8)
|
|
|
|
{
|
|
|
|
c = '8';
|
|
|
|
return InputToken::InputDigit;
|
|
|
|
}
|
|
|
|
else if (c == sign9)
|
|
|
|
{
|
|
|
|
c = '9';
|
|
|
|
return InputToken::InputDigit;
|
|
|
|
}
|
|
|
|
else if (c == decimal)
|
|
|
|
{
|
|
|
|
return InputToken::InputDot;
|
|
|
|
}
|
|
|
|
else if (c == thousand)
|
|
|
|
{
|
|
|
|
return InputToken::InputThousand;
|
|
|
|
}
|
|
|
|
else if (c == expLower)
|
|
|
|
{
|
|
|
|
c = 'e';
|
|
|
|
return InputToken::InputExp;
|
|
|
|
}
|
|
|
|
else if (c == expUpper)
|
|
|
|
{
|
|
|
|
c = 'E';
|
|
|
|
return InputToken::InputExp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto ReadVal(const QString &formula, qreal &val, const QLocale &locale, const QChar &decimal, const QChar &thousand)
|
|
|
|
-> qmusizetype
|
2017-01-03 10:14:32 +01:00
|
|
|
{
|
|
|
|
// Must not be equal
|
|
|
|
if (decimal == thousand || formula.isEmpty())
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
INIT_LOCALE_VARIABLES(locale);
|
2017-07-26 18:28:26 +02:00
|
|
|
Q_UNUSED(decimalPoint)
|
|
|
|
Q_UNUSED(groupSeparator)
|
2017-01-03 10:14:32 +01:00
|
|
|
|
2018-04-22 17:32:55 +02:00
|
|
|
QSet<QChar> reserved
|
|
|
|
{
|
|
|
|
positiveSign,
|
|
|
|
negativeSign,
|
|
|
|
sign0,
|
|
|
|
sign1,
|
|
|
|
sign2,
|
|
|
|
sign3,
|
|
|
|
sign4,
|
|
|
|
sign5,
|
|
|
|
sign6,
|
|
|
|
sign7,
|
|
|
|
sign8,
|
|
|
|
sign9,
|
|
|
|
expUpper,
|
|
|
|
expLower
|
|
|
|
};
|
2017-01-03 10:14:32 +01:00
|
|
|
|
|
|
|
if (reserved.contains(decimal) || reserved.contains(thousand))
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// row - current state, column - new state
|
|
|
|
static uchar table[9][6] =
|
|
|
|
{
|
|
|
|
/* None InputSign InputThousand InputDigit InputDot InputExp */
|
|
|
|
{ 0, State::Sign, 0, State::Mantissa, State::Dot, 0, }, // Init
|
|
|
|
{ 0, 0, 0, State::Mantissa, State::Dot, 0, }, // Sign
|
|
|
|
{ 0, 0, 0, State::Mantissa, 0, 0, }, // Thousand
|
|
|
|
{ State::Done, State::Done, State::Thousand, State::Mantissa, State::Dot, State::ExpMark,}, // Mantissa
|
|
|
|
{ 0, 0, 0, State::Abscissa, 0, 0, }, // Dot
|
|
|
|
{ State::Done, State::Done, 0, State::Abscissa, 0, State::ExpMark,}, // Abscissa
|
|
|
|
{ 0, State::ExpSign, 0, State::Exponent, 0, 0, }, // ExpMark
|
|
|
|
{ 0, 0, 0, State::Exponent, 0, 0, }, // ExpSign
|
|
|
|
{ State::Done, 0, 0, State::Exponent, 0, State::Done } // Exponent
|
|
|
|
};
|
|
|
|
|
|
|
|
int state = State::Init; // parse state
|
|
|
|
QString buf;
|
|
|
|
|
|
|
|
int index = 0; // start position
|
|
|
|
QChar c = EatWhiteSpace(formula, index);
|
|
|
|
|
|
|
|
while ( true )
|
|
|
|
{
|
2017-01-03 10:32:19 +01:00
|
|
|
const int input = CheckChar(c, locale, decimal, thousand);// input token
|
2017-01-03 10:14:32 +01:00
|
|
|
|
|
|
|
state = table[state][input];
|
|
|
|
|
|
|
|
if (state == 0)
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (state == Done)
|
|
|
|
{
|
|
|
|
// Convert to C locale
|
|
|
|
QLocale cLocale(QLocale::C);
|
2023-02-09 14:42:34 +01:00
|
|
|
const QChar cDecimal = LocaleDecimalPoint(cLocale);
|
|
|
|
const QChar cThousand = LocaleGroupSeparator(cLocale);
|
2017-01-03 10:14:32 +01:00
|
|
|
if (locale != cLocale && (cDecimal != decimal || cThousand != thousand))
|
|
|
|
{
|
|
|
|
if (decimal == cThousand)
|
|
|
|
{// Handle reverse to C locale case: thousand '.', decimal ','
|
2018-04-22 17:32:55 +02:00
|
|
|
const QChar tmpThousand = QLatin1Char('@');
|
2017-01-03 10:14:32 +01:00
|
|
|
buf.replace(thousand, tmpThousand);
|
|
|
|
buf.replace(decimal, cDecimal);
|
|
|
|
buf.replace(tmpThousand, cThousand);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf.replace(thousand, cThousand);
|
|
|
|
buf.replace(decimal, cDecimal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
const double d = cLocale.toDouble(buf, &ok);
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
val = d;
|
|
|
|
return buf.size();
|
|
|
|
}
|
2023-02-09 14:48:28 +01:00
|
|
|
|
|
|
|
val = 0;
|
|
|
|
return -1;
|
2017-01-03 10:14:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
buf.append(c);
|
|
|
|
c = GetChar(formula, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2017-07-26 18:28:26 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto NameRegExp() -> QString
|
2017-07-26 18:28:26 +02:00
|
|
|
{
|
|
|
|
static QString regex;
|
|
|
|
|
|
|
|
if (regex.isEmpty())
|
|
|
|
{
|
|
|
|
const QList<QLocale> allLocales =
|
|
|
|
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
|
|
|
|
|
|
|
|
QString positiveSigns;
|
|
|
|
QString negativeSigns;
|
|
|
|
QString decimalPoints;
|
|
|
|
QString groupSeparators;
|
|
|
|
|
2022-11-08 15:58:13 +01:00
|
|
|
for(const auto &locale : allLocales)
|
2017-07-26 18:28:26 +02:00
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
if (not positiveSigns.contains(LocalePositiveSign(locale)))
|
2017-07-26 18:28:26 +02:00
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
positiveSigns.append(LocalePositiveSign(locale));
|
2017-07-26 18:28:26 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 14:42:34 +01:00
|
|
|
if (not negativeSigns.contains(LocaleNegativeSign(locale)))
|
2017-07-26 18:28:26 +02:00
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
negativeSigns.append(LocaleNegativeSign(locale));
|
2017-07-26 18:28:26 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 14:42:34 +01:00
|
|
|
if (not decimalPoints.contains(LocaleDecimalPoint(locale)))
|
2017-07-26 18:28:26 +02:00
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
decimalPoints.append(LocaleDecimalPoint(locale));
|
2017-07-26 18:28:26 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 14:42:34 +01:00
|
|
|
if (not groupSeparators.contains(LocaleGroupSeparator(locale)))
|
2017-07-26 18:28:26 +02:00
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
groupSeparators.append(LocaleGroupSeparator(locale));
|
2017-07-26 18:28:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-20 19:19:30 +02:00
|
|
|
negativeSigns.replace('-', QLatin1String("\\-"));
|
2017-07-26 19:58:37 +02:00
|
|
|
groupSeparators.remove('\'');
|
2017-07-26 18:28:26 +02:00
|
|
|
|
|
|
|
//Same regexp in pattern.xsd shema file. Don't forget to synchronize.
|
|
|
|
// \p{Nd} - \p{Decimal_Digit_Number}
|
|
|
|
// \p{Zs} - \p{Space_Separator}
|
Fix matching new line character at the end of label. Closes smart-pattern/valentina#46.
Because Perl returns a string with a newline at the end when reading a line from a file, Perl’s regex engine matches $ at the position before the line break at the end of the string even when multi-line mode is turned off. Perl also matches $ at the very end of the string, regardless of whether that character is a line break. So ^\d+$ matches 123 whether the subject string is 123 or 123\n.
Most modern regex flavors have copied this behavior. That includes .NET, Java, PCRE, Delphi, PHP, and Python. This behavior is independent of any settings such as “multi-line mode”.
In all these flavors except Python, \Z also matches before the final line break. If you only want a match at the absolute very end of the string, use \z (lowercase z instead of uppercase Z). \A\d+\z does not match 123\n. \z matches after the line break, which is not matched by the shorthand character class.
2020-06-01 16:42:20 +02:00
|
|
|
// Here we use permanent start of string and end of string anchors \A and \z to match whole pattern as one
|
|
|
|
// string. In some cases, a user may pass multiline or line that ends with a new line. To cover case with a new
|
|
|
|
// line at the end of string use /z anchor.
|
2022-11-10 10:30:08 +01:00
|
|
|
regex = QString("\\A([^\\p{Nd}\\p{Zs}*\\/&|!<>^\\n\\()%1%2%3%4=?:;'\"]){1,1}"
|
|
|
|
"([^\\p{Zs}*\\/&|!<>^\\n\\()%1%2%3%4=?:;\"]){0,}\\z")
|
2018-03-14 14:39:15 +01:00
|
|
|
.arg(negativeSigns, positiveSigns, decimalPoints, groupSeparators);
|
2017-07-26 18:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return regex;
|
|
|
|
}
|
2018-04-22 17:32:38 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto FindFirstNotOf(const QString &string, const QString &chars, qmusizetype pos) -> qmusizetype
|
2018-04-22 17:32:38 +02:00
|
|
|
{
|
2023-02-09 16:23:11 +01:00
|
|
|
qmusizetype chPos = pos;
|
2018-04-22 17:32:38 +02:00
|
|
|
QString::const_iterator it = string.constBegin() + pos;
|
|
|
|
QString::const_iterator end = string.constEnd();
|
|
|
|
while (it != end)
|
|
|
|
{
|
|
|
|
if (not chars.contains(*it))
|
|
|
|
{
|
|
|
|
return chPos;
|
|
|
|
}
|
|
|
|
++it;
|
|
|
|
++chPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2023-02-09 14:42:34 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto SupportedLocale(const QLocale &locale) -> bool
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
return locale.positiveSign().size() == 1 &&
|
|
|
|
locale.negativeSign().size() == 1 &&
|
|
|
|
locale.toString(0).size() == 1 &&
|
|
|
|
locale.toString(1).size() == 1 &&
|
|
|
|
locale.toString(2).size() == 1 &&
|
|
|
|
locale.toString(3).size() == 1 &&
|
|
|
|
locale.toString(4).size() == 1 &&
|
|
|
|
locale.toString(5).size() == 1 &&
|
|
|
|
locale.toString(6).size() == 1 &&
|
|
|
|
locale.toString(7).size() == 1 &&
|
|
|
|
locale.toString(8).size() == 1 &&
|
|
|
|
locale.toString(9).size() == 1 &&
|
|
|
|
locale.exponential().size() == 1 &&
|
|
|
|
locale.decimalPoint().size() == 1 &&
|
|
|
|
locale.groupSeparator().size() == 1;
|
|
|
|
#else
|
2023-02-11 15:14:15 +01:00
|
|
|
Q_UNUSED(locale)
|
2023-02-09 14:42:34 +01:00
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocalePositiveSign(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
const QString sign = locale.positiveSign();
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
|
|
|
return sign.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QLocale::c().positiveSign().front();
|
|
|
|
#else
|
|
|
|
return locale.positiveSign();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleNegativeSign(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
const QString sign = locale.negativeSign();
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
|
|
|
return sign.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QLocale::c().negativeSign().front();
|
|
|
|
#else
|
|
|
|
return locale.negativeSign();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleSign0(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
const QString sign = locale.toString(0);
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
2023-02-21 08:57:49 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return sign.front();
|
2023-02-21 08:57:49 +01:00
|
|
|
#else
|
|
|
|
return sign.at(0);
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return {'0'};
|
2023-02-11 15:14:15 +01:00
|
|
|
#else
|
|
|
|
return QChar('0');
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleSign1(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
const QString sign = locale.toString(1);
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
2023-02-21 08:57:49 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return sign.front();
|
2023-02-21 08:57:49 +01:00
|
|
|
#else
|
|
|
|
return sign.at(0);
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return {'1'};
|
2023-02-11 15:14:15 +01:00
|
|
|
#else
|
|
|
|
return QChar('1');
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleSign2(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
const QString sign = locale.toString(2);
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
2023-02-21 08:57:49 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return sign.front();
|
2023-02-21 08:57:49 +01:00
|
|
|
#else
|
|
|
|
return sign.at(0);
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return {'2'};
|
2023-02-11 15:14:15 +01:00
|
|
|
#else
|
|
|
|
return QChar('2');
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleSign3(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
const QString sign = locale.toString(3);
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
2023-02-21 08:57:49 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return sign.front();
|
2023-02-21 08:57:49 +01:00
|
|
|
#else
|
|
|
|
return sign.at(0);
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return {'3'};
|
2023-02-11 15:14:15 +01:00
|
|
|
#else
|
|
|
|
return QChar('3');
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleSign4(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
const QString sign = locale.toString(4);
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
2023-02-21 08:57:49 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return sign.front();
|
2023-02-21 08:57:49 +01:00
|
|
|
#else
|
|
|
|
return sign.at(0);
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return {'4'};
|
2023-02-11 15:14:15 +01:00
|
|
|
#else
|
|
|
|
return QChar('4');
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleSign5(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
const QString sign = locale.toString(5);
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
2023-02-21 08:57:49 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return sign.front();
|
2023-02-21 08:57:49 +01:00
|
|
|
#else
|
|
|
|
return sign.at(0);
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return {'5'};
|
2023-02-11 15:14:15 +01:00
|
|
|
#else
|
|
|
|
return QChar('5');
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleSign6(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
const QString sign = locale.toString(6);
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
2023-02-21 08:57:49 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return sign.front();
|
2023-02-21 08:57:49 +01:00
|
|
|
#else
|
|
|
|
return sign.at(0);
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return {'6'};
|
2023-02-11 15:14:15 +01:00
|
|
|
#else
|
|
|
|
return QChar('6');
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleSign7(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
const QString sign = locale.toString(7);
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
2023-02-21 08:57:49 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return sign.front();
|
2023-02-21 08:57:49 +01:00
|
|
|
#else
|
|
|
|
return sign.at(0);
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return {'7'};
|
2023-02-11 15:14:15 +01:00
|
|
|
#else
|
|
|
|
return QChar('7');
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleSign8(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
const QString sign = locale.toString(8);
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
2023-02-21 08:57:49 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return sign.front();
|
2023-02-21 08:57:49 +01:00
|
|
|
#else
|
|
|
|
return sign.at(0);
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return {'8'};
|
2023-02-11 15:14:15 +01:00
|
|
|
#else
|
|
|
|
return QChar('8');
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleSign9(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
const QString sign = locale.toString(9);
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
2023-02-21 08:57:49 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return sign.front();
|
2023-02-21 08:57:49 +01:00
|
|
|
#else
|
|
|
|
return sign.at(0);
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2023-02-09 14:42:34 +01:00
|
|
|
return {'9'};
|
2023-02-11 15:14:15 +01:00
|
|
|
#else
|
|
|
|
return QChar('9');
|
|
|
|
#endif
|
2023-02-09 14:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleExpUpper(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
const QString sign = locale.exponential();
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
|
|
|
return sign.front().toUpper();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QLocale::c().exponential().front().toUpper();
|
|
|
|
#else
|
|
|
|
return locale.exponential().toUpper();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleExpLower(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
const QString sign = locale.exponential();
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
|
|
|
return sign.front().toLower();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QLocale::c().exponential().front().toLower();
|
|
|
|
#else
|
|
|
|
return locale.exponential().toLower();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleDecimalPoint(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
const QString sign = locale.decimalPoint();
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
|
|
|
return sign.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QLocale::c().decimalPoint().front();
|
|
|
|
#else
|
|
|
|
return locale.decimalPoint();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto LocaleGroupSeparator(const QLocale &locale) -> QChar
|
2023-02-09 14:42:34 +01:00
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
const QString sign = locale.groupSeparator();
|
|
|
|
if (sign.size() == 1)
|
|
|
|
{
|
|
|
|
return sign.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QLocale::c().groupSeparator().front();
|
|
|
|
#else
|
|
|
|
return locale.groupSeparator();
|
|
|
|
#endif
|
|
|
|
}
|