Fixed translation numbers in scientific notation.

(grafted from ad76bd9f92578e8f4a6f9ae21ad569eec1abec8f)

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-10-30 11:34:01 +02:00
parent ca31168b86
commit 0bd69403d7
12 changed files with 42 additions and 19 deletions

View File

@ -68,6 +68,7 @@
- Fix locking file after double save as.
- Key --ignoremargins still required margins.
- [#978] Don't show errors in History dialog.
- Fixed translation numbers in scientific notation.
# Version 0.6.1 October 23, 2018
- [#885] Regression. Broken support for multi size measurements.

View File

@ -118,6 +118,7 @@ void QmuFormulaBase::SetSepForTr(bool osSeparator, bool fromUser)
const QLocale loc = QLocale();
setLocale(loc);
SetArgSep(';');
setCNumbers(not osSeparator);
if (osSeparator)
{
setDecimalPoint(loc.decimalPoint());

View File

@ -383,12 +383,12 @@ qreal QmuParser::Max(const qreal *a_afArg, int a_iArgc)
* @param [out] a_fVal Pointer where the value should be stored in case one is found.
* @return 1 if a value was found 0 otherwise.
*/
int QmuParser::IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, const QChar &decimal,
const QChar &thousand)
int QmuParser::IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, bool cNumbers,
const QChar &decimal, const QChar &thousand)
{
qreal fVal(0);
const int pos = ReadVal(a_szExpr, fVal, locale, decimal, thousand);
int pos = ReadVal(a_szExpr, fVal, locale != QLocale::c() && cNumbers ? QLocale::c() : locale, decimal, thousand);
if (pos == -1)
{
@ -495,8 +495,8 @@ void QmuParser::InitFun()
*/
void QmuParser::InitConst()
{
DefineConst("_pi", static_cast<qreal>(M_PI));
DefineConst("_e", static_cast<qreal>(M_E));
DefineConst(QStringLiteral("_pi"), static_cast<qreal>(M_PI));
DefineConst(QStringLiteral("_e"), static_cast<qreal>(M_E));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -58,7 +58,7 @@ namespace qmu
virtual void OnDetectVar(const QString &pExpr, int &nStart, int &nEnd) override;
qreal Diff(qreal *a_Var, qreal a_fPos, qreal a_fEpsilon = 0) const;
protected:
static int IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale,
static int IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, bool cNumbers,
const QChar &decimal, const QChar &thousand);
// hyperbolic functions
static qreal Sinh(qreal);

View File

@ -54,7 +54,7 @@ OBJECTS_DIR = obj
include(qmuparser.pri)
VERSION = 2.6.0
VERSION = 2.7.0
# Allow MAC OS X to find library inside a bundle
macx:QMAKE_SONAME_PREFIX = @rpath

View File

@ -205,6 +205,7 @@ void QmuParserBase::ResetLocale()
setLocale(QLocale::c());
m_decimalPoint = m_locale.decimalPoint();
m_thousandsSeparator = m_locale.groupSeparator();
m_cNumbers = false;
SetArgSep(';');
}
@ -278,6 +279,18 @@ void QmuParserBase::setThousandsSeparator(const QChar &c)
m_thousandsSeparator = c;
}
//---------------------------------------------------------------------------------------------------------------------
bool QmuParserBase::getCNumbers() const
{
return m_cNumbers;
}
//---------------------------------------------------------------------------------------------------------------------
void QmuParserBase::setCNumbers(bool cNumbers)
{
m_cNumbers = cNumbers;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Returns the version of muparser.
@ -1356,7 +1369,7 @@ void QmuParserBase::CreateRPN() const
for (;;)
{
opt = m_pTokenReader->ReadNextToken(m_locale, m_decimalPoint, m_thousandsSeparator);
opt = m_pTokenReader->ReadNextToken(m_locale, m_cNumbers, m_decimalPoint, m_thousandsSeparator);
switch (opt.GetCode())
{

View File

@ -133,6 +133,9 @@ public:
QChar getThousandsSeparator() const;
void setThousandsSeparator(const QChar &c);
bool getCNumbers() const;
void setCNumbers(bool cNumbers);
protected:
/**
* @brief Typedef for the token reader.
@ -143,6 +146,7 @@ protected:
QLocale m_locale;///< The locale used by the parser
QChar m_decimalPoint;
QChar m_thousandsSeparator;
bool m_cNumbers{false}; ///< Search numbers in c locale
funmap_type m_FunDef; ///< Map of function names and pointers.
std::unique_ptr<token_reader_type> m_pTokenReader; ///< Managed pointer to the token reader object.
static bool g_DbgDumpCmdCode;

View File

@ -33,8 +33,8 @@
@brief This file contains standard definitions used by the parser.
*/
#define QMUP_VERSION "2.6.0"
#define QMUP_VERSION_DATE "20180121; GC"
#define QMUP_VERSION "2.7.0"
#define QMUP_VERSION_DATE "20191030; GC"
// Detect whether the compiler supports C++11 noexcept exception specifications.
# if defined(__clang__)
@ -308,7 +308,7 @@ typedef qreal ( *strfun_type2 ) ( const QString &, qreal );
typedef qreal ( *strfun_type3 ) ( const QString &, qreal, qreal );
/** @brief Callback used for functions that identify values in a string. */
typedef int ( *identfun_type ) ( const QString &sExpr, int *nPos, qreal *fVal, const QLocale &locale,
typedef int ( *identfun_type ) ( const QString &sExpr, int *nPos, qreal *fVal, const QLocale &locale, bool cNumbers,
const QChar &decimal, const QChar &thousand );
/** @brief Callback used for variable creation factory functions. */

View File

@ -75,11 +75,13 @@ QmuParserTester::QmuParserTester(QObject *parent)
//---------------------------------------------------------------------------------------------------------------------
int QmuParserTester::IsHexVal ( const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale,
const QChar &decimal, const QChar &thousand )
bool cNumbers, const QChar &decimal, const QChar &thousand )
{
Q_UNUSED(locale)
Q_UNUSED(decimal)
Q_UNUSED(thousand)
Q_UNUSED(cNumbers)
if ( a_szExpr.size() <= 2 || ( a_szExpr.at(0) != '0' || a_szExpr.at(1) != 'x' ) )
{
return 0;

View File

@ -307,7 +307,7 @@ private:
}
// Custom value recognition
static int IsHexVal (const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale,
static int IsHexVal (const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, bool cNumbers,
const QChar &decimal, const QChar &thousand);
// cppcheck-suppress functionStatic

View File

@ -213,7 +213,8 @@ void QmuParserTokenReader::ReInit()
/**
* @brief Read the next token from the string.
*/
QmuParserTokenReader::token_type QmuParserTokenReader::ReadNextToken(const QLocale &locale, const QChar &decimal,
QmuParserTokenReader::token_type QmuParserTokenReader::ReadNextToken(const QLocale &locale, bool cNumbers,
const QChar &decimal,
const QChar &thousand)
{
assert ( m_pParser );
@ -246,7 +247,7 @@ QmuParserTokenReader::token_type QmuParserTokenReader::ReadNextToken(const QLoca
{
return SaveBeforeReturn ( tok ); // Check for function argument separators
}
if ( IsValTok ( tok, locale, decimal, thousand ) )
if ( IsValTok ( tok, locale, cNumbers, decimal, thousand ) )
{
return SaveBeforeReturn ( tok ); // Check for values / constant tokens
}
@ -757,7 +758,7 @@ bool QmuParserTokenReader::IsPostOpTok ( token_type &a_Tok )
* @param a_Tok [out] If a value token is found it will be placed here.
* @return true if a value token has been found.
*/
bool QmuParserTokenReader::IsValTok ( token_type &a_Tok, const QLocale &locale, const QChar &decimal,
bool QmuParserTokenReader::IsValTok ( token_type &a_Tok, const QLocale &locale, bool cNumbers, const QChar &decimal,
const QChar &thousand )
{
assert ( m_pConstDef );
@ -794,7 +795,7 @@ bool QmuParserTokenReader::IsValTok ( token_type &a_Tok, const QLocale &locale,
for ( item = m_vIdentFun.begin(); item != m_vIdentFun.end(); ++item )
{
int iStart = m_iPos;
if ( ( *item ) ( m_strFormula.mid ( m_iPos ), &m_iPos, &fVal, locale, decimal, thousand ) == 1 )
if ( ( *item ) ( m_strFormula.mid ( m_iPos ), &m_iPos, &fVal, locale, cNumbers, decimal, thousand ) == 1 )
{
// 2013-11-27 Issue 2: https://code.google.com/p/muparser/issues/detail?id=2
strTok = m_strFormula.mid ( iStart, m_iPos-iStart );

View File

@ -66,7 +66,7 @@ public:
QChar GetArgSep() const;
void IgnoreUndefVar(bool bIgnore);
void ReInit();
token_type ReadNextToken(const QLocale &locale, const QChar &decimal, const QChar &thousand);
token_type ReadNextToken(const QLocale &locale, bool cNumbers, const QChar &decimal, const QChar &thousand);
private:
/**
@ -111,7 +111,8 @@ private:
bool IsFunTok(token_type &a_Tok);
bool IsPostOpTok(token_type &a_Tok);
bool IsOprt(token_type &a_Tok);
bool IsValTok(token_type &a_Tok, const QLocale &locale, const QChar &decimal, const QChar &thousand);
bool IsValTok(token_type &a_Tok, const QLocale &locale, bool cNumbers, const QChar &decimal,
const QChar &thousand);
bool IsVarTok(token_type &a_Tok);
bool IsStrVarTok(token_type &a_Tok);
bool IsUndefVarTok(token_type &a_Tok);