Porting new change from muparser.

--HG--
branch : feature
This commit is contained in:
dismine 2014-05-05 10:29:14 +03:00
parent bdb788e7a7
commit 60ba211f2a
6 changed files with 64 additions and 56 deletions

View File

@ -160,7 +160,12 @@ protected:
virtual std::string do_grouping() const virtual std::string do_grouping() const
{ {
return std::string(1, m_nGroup); // fix for issue 4: https://code.google.com/p/muparser/issues/detail?id=4
// courtesy of Jens Bartsch
// original code:
// return std::string(1, (char)m_nGroup);
// new code:
return std::string(1, static_cast<char>(m_cThousandsSep > 0 ? m_nGroup : CHAR_MAX));
} }
private: private:
int m_nGroup; int m_nGroup;

View File

@ -32,8 +32,8 @@
@brief This file contains standard definitions used by the parser. @brief This file contains standard definitions used by the parser.
*/ */
#define QMUP_VERSION "2.2.3" #define QMUP_VERSION "2.2.4"
#define QMUP_VERSION_DATE "20121222; SF" #define QMUP_VERSION_DATE "20140504; GC"
#define QMUP_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" #define QMUP_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

View File

@ -109,10 +109,9 @@ QmuParserErrorMsg::QmuParserErrorMsg()
* @brief Default constructor. * @brief Default constructor.
*/ */
QmuParserError::QmuParserError() QmuParserError::QmuParserError()
: m_strMsg(), m_strFormula(), m_strTok(), m_iPos ( -1 ), m_iErrc ( ecUNDEFINED ), : m_sMsg(), m_sExpr(), m_sTok(), m_iPos ( -1 ), m_iErrc ( ecUNDEFINED ),
m_ErrMsg ( QmuParserErrorMsg::Instance() ) m_ErrMsg ( QmuParserErrorMsg::Instance() )
{ {}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
@ -121,12 +120,12 @@ QmuParserError::QmuParserError()
* It does not contain any information but the error code. * It does not contain any information but the error code.
*/ */
QmuParserError::QmuParserError ( EErrorCodes a_iErrc ) QmuParserError::QmuParserError ( EErrorCodes a_iErrc )
: m_strMsg(), m_strFormula(), m_strTok(), m_iPos ( -1 ), m_iErrc ( a_iErrc ), : m_sMsg(), m_sExpr(), m_sTok(), m_iPos ( -1 ), m_iErrc ( a_iErrc ),
m_ErrMsg ( QmuParserErrorMsg::Instance() ) m_ErrMsg ( QmuParserErrorMsg::Instance() )
{ {
m_strMsg = m_ErrMsg[m_iErrc]; m_sMsg = m_ErrMsg[m_iErrc];
ReplaceSubString ( m_strMsg, "$POS$", QString().setNum ( m_iPos ) ); ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) );
ReplaceSubString ( m_strMsg, "$TOK$", m_strTok ); ReplaceSubString ( m_sMsg, "$TOK$", m_sTok );
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -134,7 +133,7 @@ QmuParserError::QmuParserError ( EErrorCodes a_iErrc )
* @brief Construct an error from a message text. * @brief Construct an error from a message text.
*/ */
QmuParserError::QmuParserError ( const QString &sMsg ) QmuParserError::QmuParserError ( const QString &sMsg )
: m_strMsg(sMsg), m_strFormula(), m_strTok(), m_iPos ( -1 ), m_iErrc ( ecUNDEFINED ), : m_sMsg(sMsg), m_sExpr(), m_sTok(), m_iPos ( -1 ), m_iErrc ( ecUNDEFINED ),
m_ErrMsg ( QmuParserErrorMsg::Instance() ) m_ErrMsg ( QmuParserErrorMsg::Instance() )
{} {}
@ -146,16 +145,13 @@ QmuParserError::QmuParserError ( const QString &sMsg )
* @param [in] sExpr The expression related to the error. * @param [in] sExpr The expression related to the error.
* @param [in] a_iPos the position in the expression where the error occured. * @param [in] a_iPos the position in the expression where the error occured.
*/ */
QmuParserError::QmuParserError ( EErrorCodes iErrc, QmuParserError::QmuParserError ( EErrorCodes iErrc, const QString &sTok, const QString &sExpr, int iPos )
const QString &sTok, : m_sMsg(), m_sExpr ( sExpr ), m_sTok ( sTok ), m_iPos ( iPos ), m_iErrc ( iErrc ),
const QString &sExpr,
int iPos )
: m_strMsg(), m_strFormula ( sExpr ), m_strTok ( sTok ), m_iPos ( iPos ), m_iErrc ( iErrc ),
m_ErrMsg ( QmuParserErrorMsg::Instance() ) m_ErrMsg ( QmuParserErrorMsg::Instance() )
{ {
m_strMsg = m_ErrMsg[m_iErrc]; m_sMsg = m_ErrMsg[m_iErrc];
ReplaceSubString ( m_strMsg, "$POS$", QString().setNum ( m_iPos ) ); ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) );
ReplaceSubString ( m_strMsg, "$TOK$", m_strTok ); ReplaceSubString ( m_sMsg, "$TOK$", m_sTok );
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -165,13 +161,13 @@ QmuParserError::QmuParserError ( EErrorCodes iErrc,
* @param [in] iPos the position in the expression where the error occured. * @param [in] iPos the position in the expression where the error occured.
* @param [in] sTok The token string related to this error. * @param [in] sTok The token string related to this error.
*/ */
QmuParserError::QmuParserError ( EErrorCodes iErrc, int iPos, const QString &sTok ) QmuParserError::QmuParserError ( EErrorCodes a_iErrc, int a_iPos, const QString &sTok )
: m_strMsg(), m_strFormula(), m_strTok ( sTok ), m_iPos ( iPos ), m_iErrc ( iErrc ), : m_sMsg(), m_sExpr(), m_sTok ( sTok ), m_iPos ( a_iPos ), m_iErrc ( a_iErrc ),
m_ErrMsg ( QmuParserErrorMsg::Instance() ) m_ErrMsg ( QmuParserErrorMsg::Instance() )
{ {
m_strMsg = m_ErrMsg[m_iErrc]; m_sMsg = m_ErrMsg[m_iErrc];
ReplaceSubString ( m_strMsg, "$POS$", QString().setNum ( m_iPos ) ); ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) );
ReplaceSubString ( m_strMsg, "$TOK$", m_strTok ); ReplaceSubString ( m_sMsg, "$TOK$", m_sTok );
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -181,20 +177,19 @@ QmuParserError::QmuParserError ( EErrorCodes iErrc, int iPos, const QString &sTo
* @param [in] sTok The token string related to this error. * @param [in] sTok The token string related to this error.
*/ */
QmuParserError::QmuParserError ( const QString &szMsg, int iPos, const QString &sTok ) QmuParserError::QmuParserError ( const QString &szMsg, int iPos, const QString &sTok )
: m_strMsg ( szMsg ), m_strFormula(), m_strTok ( sTok ), m_iPos ( iPos ), m_iErrc ( ecGENERIC ), : m_sMsg ( szMsg ), m_sExpr(), m_sTok ( sTok ), m_iPos ( iPos ), m_iErrc ( ecGENERIC ),
m_ErrMsg ( QmuParserErrorMsg::Instance() ) m_ErrMsg ( QmuParserErrorMsg::Instance() )
{ {
ReplaceSubString ( m_strMsg, "$POS$", QString().setNum ( m_iPos ) ); ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) );
ReplaceSubString ( m_strMsg, "$TOK$", m_strTok ); ReplaceSubString ( m_sMsg, "$TOK$", m_sTok );
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** @brief Copy constructor. */ /** @brief Copy constructor. */
QmuParserError::QmuParserError ( const QmuParserError &a_Obj ) QmuParserError::QmuParserError ( const QmuParserError &a_Obj )
: m_strMsg ( a_Obj.m_strMsg ), m_strFormula ( a_Obj.m_strFormula ), m_strTok ( a_Obj.m_strTok ), : m_sMsg ( a_Obj.m_sMsg ), m_sExpr ( a_Obj.m_sExpr ), m_sTok ( a_Obj.m_sTok ),
m_iPos ( a_Obj.m_iPos ), m_iErrc ( a_Obj.m_iErrc ), m_ErrMsg ( QmuParserErrorMsg::Instance() ) m_iPos ( a_Obj.m_iPos ), m_iErrc ( a_Obj.m_iErrc ), m_ErrMsg ( QmuParserErrorMsg::Instance() )
{ {}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** @brief Assignment operator. */ /** @brief Assignment operator. */
@ -205,9 +200,9 @@ QmuParserError& QmuParserError::operator= ( const QmuParserError &a_Obj )
return *this; return *this;
} }
m_strMsg = a_Obj.m_strMsg; m_sMsg = a_Obj.m_sMsg;
m_strFormula = a_Obj.m_strFormula; m_sExpr = a_Obj.m_sExpr;
m_strTok = a_Obj.m_strTok; m_sTok = a_Obj.m_sTok;
m_iPos = a_Obj.m_iPos; m_iPos = a_Obj.m_iPos;
m_iErrc = a_Obj.m_iErrc; m_iErrc = a_Obj.m_iErrc;
return *this; return *this;
@ -252,9 +247,9 @@ void QmuParserError::ReplaceSubString ( QString &strSource, const QString &strFi
// cppcheck-suppress unusedFunction // cppcheck-suppress unusedFunction
void QmuParserError::Reset() void QmuParserError::Reset()
{ {
m_strMsg.clear(); m_sMsg.clear();
m_strFormula.clear(); m_sExpr.clear();
m_strTok.clear(); m_sTok.clear();
m_iPos = -1; m_iPos = -1;
m_iErrc = ecUNDEFINED; m_iErrc = ecUNDEFINED;
} }
@ -265,7 +260,7 @@ void QmuParserError::Reset()
*/ */
void QmuParserError::SetFormula ( const QString &a_strFormula ) void QmuParserError::SetFormula ( const QString &a_strFormula )
{ {
m_strFormula = a_strFormula; m_sExpr = a_strFormula;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -274,7 +269,7 @@ void QmuParserError::SetFormula ( const QString &a_strFormula )
*/ */
const QString& QmuParserError::GetExpr() const const QString& QmuParserError::GetExpr() const
{ {
return m_strFormula; return m_sExpr;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -283,7 +278,7 @@ const QString& QmuParserError::GetExpr() const
*/ */
const QString& QmuParserError::GetMsg() const const QString& QmuParserError::GetMsg() const
{ {
return m_strMsg; return m_sMsg;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -292,7 +287,7 @@ const QString& QmuParserError::GetMsg() const
* *
* If the error is not related to a distinct position this will return -1 * If the error is not related to a distinct position this will return -1
*/ */
std::size_t QmuParserError::GetPos() const int QmuParserError::GetPos() const
{ {
return m_iPos; return m_iPos;
} }
@ -303,7 +298,7 @@ std::size_t QmuParserError::GetPos() const
*/ */
const QString& QmuParserError::GetToken() const const QString& QmuParserError::GetToken() const
{ {
return m_strTok; return m_sTok;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -134,14 +134,14 @@ public:
void SetFormula ( const QString &a_strFormula ); void SetFormula ( const QString &a_strFormula );
const QString& GetExpr() const; const QString& GetExpr() const;
const QString& GetMsg() const; const QString& GetMsg() const;
std::size_t GetPos() const; int GetPos() const;
const QString& GetToken() const; const QString& GetToken() const;
EErrorCodes GetCode() const; EErrorCodes GetCode() const;
private: private:
QString m_strMsg; ///< The message string QString m_sMsg; ///< The message string
QString m_strFormula; ///< Formula string QString m_sExpr; ///< Formula string
QString m_strTok; ///< Token related with the error QString m_sTok; ///< Token related with the error
int m_iPos; ///< Formula position related to the error int m_iPos; ///< Formula position related to the error
EErrorCodes m_iErrc; ///< Error code EErrorCodes m_iErrc; ///< Error code
const QmuParserErrorMsg &m_ErrMsg; const QmuParserErrorMsg &m_ErrMsg;

View File

@ -1352,9 +1352,16 @@ int QmuParserTester::EqnTest ( const QString &a_str, double a_fRes, bool a_fPass
// The tests equations never result in infinity, if they do thats a bug. // The tests equations never result in infinity, if they do thats a bug.
// reference: // reference:
// http://sourceforge.net/projects/muparser/forums/forum/462843/topic/5037825 // http://sourceforge.net/projects/muparser/forums/forum/462843/topic/5037825
if ( numeric_limits<qreal>::has_infinity ) #if defined(Q_CC_MSVC)
#pragma warning(push)
#pragma warning(disable:4127)
#endif
if (std::numeric_limits<qreal>::has_infinity)
#if defined(Q_CC_MSVC)
#pragma warning(pop)
#endif
{ {
bCloseEnough &= (qFuzzyCompare( fabs ( fVal[i] ), numeric_limits<qreal>::infinity())==false ); bCloseEnough &= (qFuzzyCompare( fabs ( fVal[i] ), std::numeric_limits<qreal>::infinity())==false );
} }
} }

View File

@ -643,7 +643,7 @@ bool QmuParserTokenReader::IsInfixOpTok ( token_type &a_Tok )
} }
// iteraterate over all postfix operator strings // iteraterate over all postfix operator strings
funmap_type::const_reverse_iterator it = m_pInfixOprtDef->rbegin(); auto it = m_pInfixOprtDef->rbegin();
for ( ; it != m_pInfixOprtDef->rend(); ++it ) for ( ; it != m_pInfixOprtDef->rend(); ++it )
{ {
if ( sTok.indexOf ( it->first ) != 0 ) if ( sTok.indexOf ( it->first ) != 0 )
@ -752,7 +752,7 @@ bool QmuParserTokenReader::IsOprt ( token_type &a_Tok )
// are part of long token names (like: "add123") will be found instead // are part of long token names (like: "add123") will be found instead
// of the long ones. // of the long ones.
// Length sorting is done with ascending length so we use a reverse iterator here. // Length sorting is done with ascending length so we use a reverse iterator here.
funmap_type::const_reverse_iterator it = m_pOprtDef->rbegin(); auto it = m_pOprtDef->rbegin();
for ( ; it != m_pOprtDef->rend(); ++it ) for ( ; it != m_pOprtDef->rend(); ++it )
{ {
const QString &sID = it->first; const QString &sID = it->first;
@ -781,7 +781,7 @@ bool QmuParserTokenReader::IsOprt ( token_type &a_Tok )
} }
m_iPos += sID.length(); m_iPos += sID.length();
m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noEND | noBC | noASSIGN; m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noEND | noASSIGN;
return true; return true;
} }
} }
@ -825,7 +825,7 @@ bool QmuParserTokenReader::IsPostOpTok ( token_type &a_Tok )
} }
// iteraterate over all postfix operator strings // iteraterate over all postfix operator strings
funmap_type::const_reverse_iterator it = m_pPostOprtDef->rbegin(); auto it = m_pPostOprtDef->rbegin();
for ( ; it != m_pPostOprtDef->rend(); ++it ) for ( ; it != m_pPostOprtDef->rend(); ++it )
{ {
if ( sTok.indexOf ( it->first ) != 0 ) if ( sTok.indexOf ( it->first ) != 0 )
@ -890,7 +890,8 @@ bool QmuParserTokenReader::IsValTok ( token_type &a_Tok )
int iStart = m_iPos; int iStart = m_iPos;
if ( ( *item ) ( m_strFormula.mid ( m_iPos ), &m_iPos, &fVal ) == 1 ) if ( ( *item ) ( m_strFormula.mid ( m_iPos ), &m_iPos, &fVal ) == 1 )
{ {
strTok = m_strFormula.mid ( iStart, m_iPos ); // 2013-11-27 Issue 2: https://code.google.com/p/muparser/issues/detail?id=2
strTok = m_strFormula.mid ( iStart, m_iPos-iStart );
if ( m_iSynFlags & noVAL ) if ( m_iSynFlags & noVAL )
{ {
Error ( ecUNEXPECTED_VAL, m_iPos - strTok.length(), strTok ); Error ( ecUNEXPECTED_VAL, m_iPos - strTok.length(), strTok );
@ -913,7 +914,7 @@ bool QmuParserTokenReader::IsValTok ( token_type &a_Tok )
*/ */
bool QmuParserTokenReader::IsVarTok ( token_type &a_Tok ) bool QmuParserTokenReader::IsVarTok ( token_type &a_Tok )
{ {
if ( m_pVarDef->size() == false) if ( m_pVarDef->empty())
{ {
return false; return false;
} }
@ -952,7 +953,7 @@ bool QmuParserTokenReader::IsVarTok ( token_type &a_Tok )
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool QmuParserTokenReader::IsStrVarTok ( token_type &a_Tok ) bool QmuParserTokenReader::IsStrVarTok ( token_type &a_Tok )
{ {
if ( m_pStrVarDef == false || m_pStrVarDef->size() == false) if ( m_pStrVarDef == false || m_pStrVarDef->empty() )
{ {
return false; return false;
} }