50 static const QChar
QmuEOF = QChar(
static_cast<ushort
>(0xffff));
53 static QChar
GetChar(
const QString &formula,
int &index)
55 if (index >= formula.size())
60 return formula.at(index++);
71 while ( c !=
QmuEOF && c.isSpace() );
77 static int CheckChar(QChar &c,
const QLocale &locale,
const QChar &decimal,
const QChar &thousand)
80 Q_UNUSED(decimalPoint)
81 Q_UNUSED(groupSeparator)
83 if (c == positiveSign)
88 else if (c == negativeSign)
143 else if (c == decimal)
147 else if (c == thousand)
151 else if (c == expLower)
156 else if (c == expUpper)
170 int ReadVal(
const QString &formula, qreal &val,
const QLocale &locale,
const QChar &decimal,
const QChar &thousand)
173 if (decimal == thousand || formula.isEmpty())
180 Q_UNUSED(decimalPoint)
181 Q_UNUSED(groupSeparator)
183 QSet<QChar> reserved;
184 reserved << positiveSign
199 if (reserved.contains(decimal) || reserved.contains(thousand))
206 static uchar table[9][6] =
228 const int input =
CheckChar(c, locale, decimal, thousand);
230 state = table[state][input];
237 else if (state ==
Done)
240 QLocale cLocale(QLocale::C);
241 const QChar cDecimal = cLocale.decimalPoint();
242 const QChar cThousand = cLocale.groupSeparator();
243 if (locale != cLocale && (cDecimal != decimal || cThousand != thousand))
245 if (decimal == cThousand)
247 const QChar tmpThousand =
'@';
248 buf.replace(thousand, tmpThousand);
249 buf.replace(decimal, cDecimal);
250 buf.replace(tmpThousand, cThousand);
254 buf.replace(thousand, cThousand);
255 buf.replace(decimal, cDecimal);
260 const double d = cLocale.toDouble(buf, &ok);
283 static QString regex;
288 QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
290 QString positiveSigns;
291 QString negativeSigns;
292 QString decimalPoints;
293 QString groupSeparators;
295 for(
int i = 0; i < allLocales.size(); ++i)
297 if (not positiveSigns.contains(allLocales.at(i).positiveSign()))
299 positiveSigns.append(allLocales.at(i).positiveSign());
302 if (not negativeSigns.contains(allLocales.at(i).negativeSign()))
304 negativeSigns.append(allLocales.at(i).negativeSign());
307 if (not decimalPoints.contains(allLocales.at(i).decimalPoint()))
309 decimalPoints.append(allLocales.at(i).decimalPoint());
312 if (not groupSeparators.contains(allLocales.at(i).groupSeparator()))
314 groupSeparators.append(allLocales.at(i).groupSeparator());
318 negativeSigns.replace(
'-',
"\\-");
319 groupSeparators.remove(
'\'');
324 regex = QString(
"^([^\\p{Nd}\\p{Zs}*/&|!<>^\\()%1%2%3%4=?:;'\"]){1,1}"
325 "([^\\p{Zs}*/&|!<>^\\()%1%2%3%4=?:;\"]){0,}$")
326 .arg(negativeSigns).arg(positiveSigns).arg(decimalPoints).arg(groupSeparators);
static const QChar QmuEOF
static QChar GetChar(const QString &formula, int &index)
int ReadVal(const QString &formula, qreal &val, const QLocale &locale, const QChar &decimal, const QChar &thousand)
static QChar EatWhiteSpace(const QString &formula, int &index)
static int CheckChar(QChar &c, const QLocale &locale, const QChar &decimal, const QChar &thousand)
#define INIT_LOCALE_VARIABLES(locale)