Optimization. Use FindFirstNotOf() that supports QString natively.
--HG-- branch : develop
This commit is contained in:
parent
279674f491
commit
e845453f95
|
@ -328,3 +328,22 @@ QString NameRegExp()
|
||||||
|
|
||||||
return regex;
|
return regex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
int FindFirstNotOf(const QString &string, const QString &chars, int pos)
|
||||||
|
{
|
||||||
|
int chPos = pos;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -91,6 +91,7 @@ QT_WARNING_DISABLE_GCC("-Wattributes")
|
||||||
|
|
||||||
class QLocale;
|
class QLocale;
|
||||||
class QChar;
|
class QChar;
|
||||||
|
class QString;
|
||||||
|
|
||||||
#define INIT_LOCALE_VARIABLES(locale) \
|
#define INIT_LOCALE_VARIABLES(locale) \
|
||||||
const QChar positiveSign = (locale).positiveSign(); \
|
const QChar positiveSign = (locale).positiveSign(); \
|
||||||
|
@ -134,4 +135,6 @@ static inline bool QmuFuzzyComparePossibleNulls(double p1, double p2)
|
||||||
QMUPARSERSHARED_EXPORT int ReadVal(const QString &formula, qreal &val, const QLocale &locale, const QChar &decimal,
|
QMUPARSERSHARED_EXPORT int ReadVal(const QString &formula, qreal &val, const QLocale &locale, const QChar &decimal,
|
||||||
const QChar &thousand);
|
const QChar &thousand);
|
||||||
|
|
||||||
|
int FindFirstNotOf(const QString &string, const QString &chars, int pos = 0);
|
||||||
|
|
||||||
#endif // QMUDEF_H
|
#endif // QMUDEF_H
|
||||||
|
|
|
@ -381,11 +381,8 @@ void QmuParserBase::AddCallback(const QString &a_strName, const QmuParserCallbac
|
||||||
void QmuParserBase::CheckOprt(const QString &a_sName, const QmuParserCallback &a_Callback,
|
void QmuParserBase::CheckOprt(const QString &a_sName, const QmuParserCallback &a_Callback,
|
||||||
const QString &a_szCharSet) const
|
const QString &a_szCharSet) const
|
||||||
{
|
{
|
||||||
const std::wstring a_sNameStd = a_sName.toStdWString();
|
if ( a_sName.isEmpty() || (FindFirstNotOf(a_sName, a_szCharSet) != -1) ||
|
||||||
const std::wstring a_szCharSetStd = a_szCharSet.toStdWString();
|
(a_sName.at(0)>='0' && a_sName.at(0)<='9'))
|
||||||
|
|
||||||
if ( a_sNameStd.length() == false || (a_sNameStd.find_first_not_of(a_szCharSetStd)!=string_type::npos) ||
|
|
||||||
(a_sNameStd.at(0)>='0' && a_sNameStd.at(0)<='9'))
|
|
||||||
{
|
{
|
||||||
switch (a_Callback.GetCode())
|
switch (a_Callback.GetCode())
|
||||||
{
|
{
|
||||||
|
@ -410,11 +407,8 @@ void QmuParserBase::CheckOprt(const QString &a_sName, const QmuParserCallback &a
|
||||||
*/
|
*/
|
||||||
void QmuParserBase::CheckName(const QString &a_sName, const QString &a_szCharSet) const
|
void QmuParserBase::CheckName(const QString &a_sName, const QString &a_szCharSet) const
|
||||||
{
|
{
|
||||||
std::wstring a_sNameStd = a_sName.toStdWString();
|
if ( a_sName.isEmpty() || (FindFirstNotOf(a_sName, a_szCharSet) != -1) ||
|
||||||
std::wstring a_szCharSetStd = a_szCharSet.toStdWString();
|
(a_sName.at(0)>='0' && a_sName.at(0)<='9'))
|
||||||
|
|
||||||
if ( a_sNameStd.length() == false || (a_sNameStd.find_first_not_of(a_szCharSetStd)!=string_type::npos) ||
|
|
||||||
(a_sNameStd[0]>='0' && a_sNameStd[0]<='9'))
|
|
||||||
{
|
{
|
||||||
Error(ecINVALID_NAME);
|
Error(ecINVALID_NAME);
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,21 +325,17 @@ QT_WARNING_PUSH
|
||||||
QT_WARNING_DISABLE_MSVC(4309)
|
QT_WARNING_DISABLE_MSVC(4309)
|
||||||
int QmuParserTokenReader::ExtractToken ( const QString &a_szCharSet, QString &a_sTok, int a_iPos ) const
|
int QmuParserTokenReader::ExtractToken ( const QString &a_szCharSet, QString &a_sTok, int a_iPos ) const
|
||||||
{
|
{
|
||||||
const std::wstring m_strFormulaStd = m_strFormula.toStdWString();
|
int iEnd = FindFirstNotOf(m_strFormula, a_szCharSet, a_iPos);
|
||||||
const std::wstring a_szCharSetStd = a_szCharSet.toStdWString();
|
|
||||||
|
|
||||||
int iEnd = static_cast<int>(m_strFormulaStd.find_first_not_of ( a_szCharSetStd, static_cast<std::size_t>(a_iPos) ));
|
if (iEnd == -1)
|
||||||
|
|
||||||
if ( iEnd == static_cast<int>(string_type::npos) )
|
|
||||||
{
|
{
|
||||||
iEnd = static_cast<int>(m_strFormulaStd.length());
|
iEnd = m_strFormula.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign token string if there was something found
|
// Assign token string if there was something found
|
||||||
if (a_iPos != iEnd)
|
if (a_iPos != iEnd)
|
||||||
{
|
{
|
||||||
a_sTok = QString().fromStdWString ( std::wstring ( m_strFormulaStd.begin() + a_iPos,
|
a_sTok = m_strFormula.mid(a_iPos, iEnd - a_iPos);
|
||||||
m_strFormulaStd.begin() + iEnd ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return iEnd;
|
return iEnd;
|
||||||
|
@ -355,21 +351,17 @@ int QmuParserTokenReader::ExtractToken ( const QString &a_szCharSet, QString &a_
|
||||||
*/
|
*/
|
||||||
int QmuParserTokenReader::ExtractOperatorToken ( QString &a_sTok, int a_iPos ) const
|
int QmuParserTokenReader::ExtractOperatorToken ( QString &a_sTok, int a_iPos ) const
|
||||||
{
|
{
|
||||||
const std::wstring m_strFormulaStd = m_strFormula.toStdWString();
|
int iEnd = FindFirstNotOf(m_strFormula, m_pParser->ValidOprtChars(), a_iPos);
|
||||||
// Changed as per Issue 6: https://code.google.com/p/muparser/issues/detail?id=6
|
|
||||||
const std::wstring oprtCharsStd = m_pParser->ValidOprtChars().toStdWString();
|
|
||||||
|
|
||||||
int iEnd = static_cast<int>( m_strFormulaStd.find_first_not_of ( oprtCharsStd, static_cast<std::size_t>(a_iPos) ) );
|
if ( iEnd == -1 )
|
||||||
if ( iEnd == static_cast<int>( string_type::npos ) )
|
|
||||||
{
|
{
|
||||||
iEnd = static_cast<int>( m_strFormulaStd.length() );
|
iEnd = m_strFormula.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign token string if there was something found
|
// Assign token string if there was something found
|
||||||
if ( a_iPos != iEnd )
|
if ( a_iPos != iEnd )
|
||||||
{
|
{
|
||||||
a_sTok = QString().fromStdWString ( string_type ( m_strFormulaStd.begin() + a_iPos,
|
a_sTok = m_strFormula.mid(a_iPos, iEnd - a_iPos);
|
||||||
m_strFormulaStd.begin() + iEnd ) );
|
|
||||||
return iEnd;
|
return iEnd;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user