Added 'endsWith' utility function. This will make compiling the democlient easier.

This commit is contained in:
Daniel Marjamäki 2017-04-01 18:14:18 +02:00
parent 4bf439936c
commit 1faca91c1d
13 changed files with 38 additions and 27 deletions

View File

@ -300,7 +300,7 @@ endif
###### Build ###### Build
$(SRCDIR)/analyzerinfo.o: lib/analyzerinfo.cpp lib/cxx11emu.h lib/analyzerinfo.h lib/config.h lib/errorlogger.h lib/suppressions.h lib/importproject.h lib/platform.h lib/path.h $(SRCDIR)/analyzerinfo.o: lib/analyzerinfo.cpp lib/cxx11emu.h lib/analyzerinfo.h lib/config.h lib/errorlogger.h lib/suppressions.h lib/importproject.h lib/platform.h lib/path.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/analyzerinfo.o $(SRCDIR)/analyzerinfo.cpp $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/analyzerinfo.o $(SRCDIR)/analyzerinfo.cpp
$(SRCDIR)/astutils.o: lib/astutils.cpp lib/cxx11emu.h lib/astutils.h lib/settings.h lib/config.h lib/library.h lib/mathlib.h lib/standards.h lib/errorlogger.h lib/suppressions.h lib/platform.h lib/importproject.h lib/timer.h lib/symboldatabase.h lib/token.h lib/valueflow.h lib/tokenize.h lib/tokenlist.h $(SRCDIR)/astutils.o: lib/astutils.cpp lib/cxx11emu.h lib/astutils.h lib/settings.h lib/config.h lib/library.h lib/mathlib.h lib/standards.h lib/errorlogger.h lib/suppressions.h lib/platform.h lib/importproject.h lib/timer.h lib/symboldatabase.h lib/token.h lib/valueflow.h lib/tokenize.h lib/tokenlist.h
@ -390,19 +390,19 @@ $(SRCDIR)/cppcheck.o: lib/cppcheck.cpp lib/cxx11emu.h lib/cppcheck.h lib/config.
$(SRCDIR)/errorlogger.o: lib/errorlogger.cpp lib/cxx11emu.h lib/errorlogger.h lib/config.h lib/suppressions.h lib/path.h lib/cppcheck.h lib/settings.h lib/library.h lib/mathlib.h lib/standards.h lib/platform.h lib/importproject.h lib/timer.h lib/check.h lib/token.h lib/valueflow.h lib/tokenize.h lib/tokenlist.h lib/analyzerinfo.h lib/utils.h $(SRCDIR)/errorlogger.o: lib/errorlogger.cpp lib/cxx11emu.h lib/errorlogger.h lib/config.h lib/suppressions.h lib/path.h lib/cppcheck.h lib/settings.h lib/library.h lib/mathlib.h lib/standards.h lib/platform.h lib/importproject.h lib/timer.h lib/check.h lib/token.h lib/valueflow.h lib/tokenize.h lib/tokenlist.h lib/analyzerinfo.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/errorlogger.o $(SRCDIR)/errorlogger.cpp $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/errorlogger.o $(SRCDIR)/errorlogger.cpp
$(SRCDIR)/importproject.o: lib/importproject.cpp lib/cxx11emu.h lib/importproject.h lib/config.h lib/platform.h lib/path.h lib/settings.h lib/library.h lib/mathlib.h lib/standards.h lib/errorlogger.h lib/suppressions.h lib/timer.h lib/tokenize.h lib/tokenlist.h lib/token.h lib/valueflow.h $(SRCDIR)/importproject.o: lib/importproject.cpp lib/cxx11emu.h lib/importproject.h lib/config.h lib/platform.h lib/path.h lib/settings.h lib/library.h lib/mathlib.h lib/standards.h lib/errorlogger.h lib/suppressions.h lib/timer.h lib/tokenize.h lib/tokenlist.h lib/token.h lib/valueflow.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/importproject.o $(SRCDIR)/importproject.cpp $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/importproject.o $(SRCDIR)/importproject.cpp
$(SRCDIR)/library.o: lib/library.cpp lib/cxx11emu.h lib/library.h lib/config.h lib/mathlib.h lib/standards.h lib/errorlogger.h lib/suppressions.h lib/path.h lib/tokenlist.h lib/token.h lib/valueflow.h lib/symboldatabase.h lib/astutils.h $(SRCDIR)/library.o: lib/library.cpp lib/cxx11emu.h lib/library.h lib/config.h lib/mathlib.h lib/standards.h lib/errorlogger.h lib/suppressions.h lib/path.h lib/tokenlist.h lib/token.h lib/valueflow.h lib/symboldatabase.h lib/astutils.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/library.o $(SRCDIR)/library.cpp $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/library.o $(SRCDIR)/library.cpp
$(SRCDIR)/mathlib.o: lib/mathlib.cpp lib/cxx11emu.h lib/mathlib.h lib/config.h lib/errorlogger.h lib/suppressions.h $(SRCDIR)/mathlib.o: lib/mathlib.cpp lib/cxx11emu.h lib/mathlib.h lib/config.h lib/errorlogger.h lib/suppressions.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/mathlib.o $(SRCDIR)/mathlib.cpp $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/mathlib.o $(SRCDIR)/mathlib.cpp
$(SRCDIR)/path.o: lib/path.cpp lib/cxx11emu.h lib/path.h lib/config.h $(SRCDIR)/path.o: lib/path.cpp lib/cxx11emu.h lib/path.h lib/config.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/path.o $(SRCDIR)/path.cpp $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/path.o $(SRCDIR)/path.cpp
$(SRCDIR)/pathmatch.o: lib/pathmatch.cpp lib/cxx11emu.h lib/pathmatch.h lib/config.h lib/path.h $(SRCDIR)/pathmatch.o: lib/pathmatch.cpp lib/cxx11emu.h lib/pathmatch.h lib/config.h lib/path.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/pathmatch.o $(SRCDIR)/pathmatch.cpp $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/pathmatch.o $(SRCDIR)/pathmatch.cpp
$(SRCDIR)/platform.o: lib/platform.cpp lib/cxx11emu.h lib/platform.h lib/config.h $(SRCDIR)/platform.o: lib/platform.cpp lib/cxx11emu.h lib/platform.h lib/config.h
@ -432,7 +432,7 @@ $(SRCDIR)/token.o: lib/token.cpp lib/cxx11emu.h lib/token.h lib/config.h lib/val
$(SRCDIR)/tokenize.o: lib/tokenize.cpp lib/cxx11emu.h lib/tokenize.h lib/errorlogger.h lib/config.h lib/suppressions.h lib/tokenlist.h lib/mathlib.h lib/settings.h lib/library.h lib/standards.h lib/platform.h lib/importproject.h lib/timer.h lib/check.h lib/token.h lib/valueflow.h lib/path.h lib/symboldatabase.h lib/templatesimplifier.h lib/utils.h $(SRCDIR)/tokenize.o: lib/tokenize.cpp lib/cxx11emu.h lib/tokenize.h lib/errorlogger.h lib/config.h lib/suppressions.h lib/tokenlist.h lib/mathlib.h lib/settings.h lib/library.h lib/standards.h lib/platform.h lib/importproject.h lib/timer.h lib/check.h lib/token.h lib/valueflow.h lib/path.h lib/symboldatabase.h lib/templatesimplifier.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/tokenize.o $(SRCDIR)/tokenize.cpp $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/tokenize.o $(SRCDIR)/tokenize.cpp
$(SRCDIR)/tokenlist.o: lib/tokenlist.cpp lib/cxx11emu.h lib/tokenlist.h lib/config.h lib/token.h lib/valueflow.h lib/mathlib.h lib/path.h lib/preprocessor.h lib/settings.h lib/library.h lib/standards.h lib/errorlogger.h lib/suppressions.h lib/platform.h lib/importproject.h lib/timer.h $(SRCDIR)/tokenlist.o: lib/tokenlist.cpp lib/cxx11emu.h lib/tokenlist.h lib/config.h lib/token.h lib/valueflow.h lib/mathlib.h lib/path.h lib/preprocessor.h lib/settings.h lib/library.h lib/standards.h lib/errorlogger.h lib/suppressions.h lib/platform.h lib/importproject.h lib/timer.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/tokenlist.o $(SRCDIR)/tokenlist.cpp $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/tokenlist.o $(SRCDIR)/tokenlist.cpp
$(SRCDIR)/valueflow.o: lib/valueflow.cpp lib/cxx11emu.h lib/valueflow.h lib/config.h lib/astutils.h lib/errorlogger.h lib/suppressions.h lib/mathlib.h lib/settings.h lib/library.h lib/standards.h lib/platform.h lib/importproject.h lib/timer.h lib/symboldatabase.h lib/token.h lib/tokenlist.h $(SRCDIR)/valueflow.o: lib/valueflow.cpp lib/cxx11emu.h lib/valueflow.h lib/config.h lib/astutils.h lib/errorlogger.h lib/suppressions.h lib/mathlib.h lib/settings.h lib/library.h lib/standards.h lib/platform.h lib/importproject.h lib/timer.h lib/symboldatabase.h lib/token.h lib/tokenlist.h

View File

@ -18,6 +18,7 @@
#include "analyzerinfo.h" #include "analyzerinfo.h"
#include "path.h" #include "path.h"
#include "utils.h"
#include <tinyxml2.h> #include <tinyxml2.h>
#include <sstream> #include <sstream>
@ -110,7 +111,7 @@ std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir
} }
std::string filename = Path::fromNativeSeparators(buildDir); std::string filename = Path::fromNativeSeparators(buildDir);
if (filename.back() != '/') if (!endsWith(filename, '/'))
filename += '/'; filename += '/';
const std::string::size_type pos = sourcefile.rfind('/'); const std::string::size_type pos = sourcefile.rfind('/');
if (pos == std::string::npos) if (pos == std::string::npos)

View File

@ -1734,7 +1734,7 @@ void CheckClass::checkConst()
continue; continue;
} else if (func->isOperator() && Token::Match(previous, ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator } else if (func->isOperator() && Token::Match(previous, ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator
const std::string& opName = func->tokenDef->str(); const std::string& opName = func->tokenDef->str();
if (opName.compare(8, 5, "const") != 0 && (opName.back() == '&' || opName.back() == '*')) if (opName.compare(8, 5, "const") != 0 && (endsWith(opName,'&') || endsWith(opName,'*')))
continue; continue;
} else { } else {
// don't warn for unknown types.. // don't warn for unknown types..

View File

@ -137,7 +137,7 @@ void ErrorLogger::ErrorMessage::setmsg(const std::string &msg)
// as an empty message to the user if --verbose is used. // as an empty message to the user if --verbose is used.
// Even this doesn't cause problems with messages that have multiple // Even this doesn't cause problems with messages that have multiple
// lines, none of the the error messages should end into it. // lines, none of the the error messages should end into it.
assert(!(msg.back() =='\n')); assert(!endsWith(msg,'\n'));
// The summary and verbose message are separated by a newline // The summary and verbose message are separated by a newline
// If there is no newline then both the summary and verbose messages // If there is no newline then both the summary and verbose messages

View File

@ -22,6 +22,7 @@
#include "tokenize.h" #include "tokenize.h"
#include "token.h" #include "token.h"
#include "tinyxml2.h" #include "tinyxml2.h"
#include "utils.h"
#include <fstream> #include <fstream>
void ImportProject::ignorePaths(const std::vector<std::string> &ipaths) void ImportProject::ignorePaths(const std::vector<std::string> &ipaths)
@ -70,7 +71,7 @@ void ImportProject::FileSettings::setDefines(std::string defs)
} }
while (defs.find(";;") != std::string::npos) while (defs.find(";;") != std::string::npos)
defs.erase(defs.find(";;"),1); defs.erase(defs.find(";;"),1);
if (!defs.empty() && defs.back() == ';') if (!defs.empty() && endsWith(defs,';'))
defs.erase(defs.size() - 1U); // TODO: Use std::string::pop_back() as soon as travis supports it defs.erase(defs.size() - 1U); // TODO: Use std::string::pop_back() as soon as travis supports it
bool eq = false; bool eq = false;
for (std::size_t pos = 0; pos < defs.size(); ++pos) { for (std::size_t pos = 0; pos < defs.size(); ++pos) {
@ -123,13 +124,13 @@ void ImportProject::FileSettings::setIncludePaths(const std::string &basepath, c
continue; continue;
std::string s(Path::fromNativeSeparators(*it)); std::string s(Path::fromNativeSeparators(*it));
if (s[0] == '/' || (s.size() > 1U && s.compare(1,2,":/") == 0)) { if (s[0] == '/' || (s.size() > 1U && s.compare(1,2,":/") == 0)) {
if (s.back() != '/') if (!endsWith(s,'/'))
s += '/'; s += '/';
I.push_back(s); I.push_back(s);
continue; continue;
} }
if (s.back() == '/') // this is a temporary hack, simplifyPath can crash if path ends with '/' if (endsWith(s,'/')) // this is a temporary hack, simplifyPath can crash if path ends with '/'
s.erase(s.size() - 1U); // TODO: Use std::string::pop_back() as soon as travis supports it s.erase(s.size() - 1U); // TODO: Use std::string::pop_back() as soon as travis supports it
if (s.find("$(")==std::string::npos) { if (s.find("$(")==std::string::npos) {
@ -154,7 +155,7 @@ void ImportProject::import(const std::string &filename)
importCompileCommands(fin); importCompileCommands(fin);
} else if (filename.find(".sln") != std::string::npos) { } else if (filename.find(".sln") != std::string::npos) {
std::string path(Path::getPathFromFilename(Path::fromNativeSeparators(filename))); std::string path(Path::getPathFromFilename(Path::fromNativeSeparators(filename)));
if (!path.empty() && path.back() != '/') if (!path.empty() && !endsWith(path,'/'))
path += '/'; path += '/';
importSln(fin,path); importSln(fin,path);
} else if (filename.find(".vcxproj") != std::string::npos) { } else if (filename.find(".vcxproj") != std::string::npos) {

View File

@ -24,6 +24,7 @@
#include "token.h" #include "token.h"
#include "symboldatabase.h" #include "symboldatabase.h"
#include "astutils.h" #include "astutils.h"
#include "utils.h"
#include <string> #include <string>
@ -87,7 +88,7 @@ Library::Error Library::load(const char exename[], const char path[])
while (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND && !cfgfolders.empty()) { while (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND && !cfgfolders.empty()) {
const std::string cfgfolder(cfgfolders.front()); const std::string cfgfolder(cfgfolders.front());
cfgfolders.pop_front(); cfgfolders.pop_front();
const char *sep = (!cfgfolder.empty() && cfgfolder.back()=='/' ? "" : "/"); const char *sep = (!cfgfolder.empty() && endsWith(cfgfolder,'/') ? "" : "/");
const std::string filename(cfgfolder + sep + fullfilename); const std::string filename(cfgfolder + sep + fullfilename);
error = doc.LoadFile(filename.c_str()); error = doc.LoadFile(filename.c_str());
if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND) if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND)

View File

@ -20,6 +20,7 @@
#include "mathlib.h" #include "mathlib.h"
#include "errorlogger.h" #include "errorlogger.h"
#include "utils.h"
#include <algorithm> // VS2013: std::min and std::max #include <algorithm> // VS2013: std::min and std::max
#include <cmath> #include <cmath>
@ -524,7 +525,7 @@ MathLib::bigint MathLib::toLongNumber(const std::string & str)
return static_cast<bigint>(doubleval); return static_cast<bigint>(doubleval);
} }
if (str[0] == '\'' && str.size() >= 3U && str.back() == '\'') { if (str[0] == '\'' && str.size() >= 3U && endsWith(str,'\'')) {
return characterLiteralToLongNumber(str.substr(1,str.size()-2)); return characterLiteralToLongNumber(str.substr(1,str.size()-2));
} }
@ -537,7 +538,7 @@ MathLib::bigint MathLib::toLongNumber(const std::string & str)
double MathLib::toDoubleNumber(const std::string &str) double MathLib::toDoubleNumber(const std::string &str)
{ {
if (str[0] == '\'' && str.size() >= 3U && str.back() == '\'') if (str[0] == '\'' && str.size() >= 3U && endsWith(str,'\''))
return characterLiteralToLongNumber(str.substr(1,str.size()-2)); return characterLiteralToLongNumber(str.substr(1,str.size()-2));
if (isIntHex(str)) if (isIntHex(str))
return static_cast<double>(toLongNumber(str)); return static_cast<double>(toLongNumber(str));

View File

@ -20,6 +20,7 @@
#undef __STRICT_ANSI__ #undef __STRICT_ANSI__
#endif #endif
#include "path.h" #include "path.h"
#include "utils.h"
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
@ -227,7 +228,7 @@ std::string Path::getRelativePath(const std::string& absolutePath, const std::ve
if (absolutePath == *i || i->empty()) // Seems to be a file, or path is empty if (absolutePath == *i || i->empty()) // Seems to be a file, or path is empty
continue; continue;
bool endsWithSep = i->back() == '/'; bool endsWithSep = endsWith(*i,'/');
if (absolutePath.compare(0, i->length(), *i) == 0 && absolutePath[i->length() - (endsWithSep?1:0)] == '/') { if (absolutePath.compare(0, i->length(), *i) == 0 && absolutePath[i->length() - (endsWithSep?1:0)] == '/') {
std::string rest = absolutePath.substr(i->length() + (endsWithSep?0:1)); std::string rest = absolutePath.substr(i->length() + (endsWithSep?0:1));
return rest; return rest;

View File

@ -18,6 +18,7 @@
#include "pathmatch.h" #include "pathmatch.h"
#include "path.h" #include "path.h"
#include "utils.h"
#include <algorithm> #include <algorithm>
#include <ctype.h> #include <ctype.h>
@ -43,8 +44,8 @@ bool PathMatch::Match(const std::string &path) const
std::transform(findpath.begin(), findpath.end(), findpath.begin(), ::tolower); std::transform(findpath.begin(), findpath.end(), findpath.begin(), ::tolower);
// Filtering directory name // Filtering directory name
if (excludedPath.back() == '/') { if (endsWith(excludedPath,'/')) {
if (findpath.back() != '/') if (!endsWith(findpath,'/'))
findpath = RemoveFilename(findpath); findpath = RemoveFilename(findpath);
if (excludedPath.length() > findpath.length()) if (excludedPath.length() > findpath.length())

View File

@ -74,9 +74,9 @@ void Token::update_property_info()
_tokType = eName; _tokType = eName;
} else if (std::isdigit((unsigned char)_str[0]) || (_str.length() > 1 && _str[0] == '-' && std::isdigit((unsigned char)_str[1]))) } else if (std::isdigit((unsigned char)_str[0]) || (_str.length() > 1 && _str[0] == '-' && std::isdigit((unsigned char)_str[1])))
_tokType = eNumber; _tokType = eNumber;
else if (_str.length() > 1 && _str[0] == '"' && _str.back() == '"') else if (_str.length() > 1 && _str[0] == '"' && endsWith(_str,'"'))
_tokType = eString; _tokType = eString;
else if (_str.length() > 1 && _str[0] == '\'' && _str.back() == '\'') else if (_str.length() > 1 && _str[0] == '\'' && endsWith(_str,'\''))
_tokType = eChar; _tokType = eChar;
else if (_str == "=" || _str == "<<=" || _str == ">>=" || else if (_str == "=" || _str == "<<=" || _str == ">>=" ||
(_str.size() == 2U && _str[1] == '=' && std::strchr("+-*/%&^|", _str[0]))) (_str.size() == 2U && _str[1] == '=' && std::strchr("+-*/%&^|", _str[0])))

View File

@ -1855,7 +1855,7 @@ void Tokenizer::combineOperators()
} }
if (prev->isName() && prev->isUpperCaseName()) if (prev->isName() && prev->isUpperCaseName())
continue; continue;
if (prev->isName() && prev->str().back() == ':') if (prev->isName() && endsWith(prev->str(), ':'))
simplify = true; simplify = true;
break; break;
} }
@ -2648,7 +2648,7 @@ void Tokenizer::setVarIdPass1()
(tok->str() == "(" && isFunctionHead(tok,"{")) || (tok->str() == "(" && isFunctionHead(tok,"{")) ||
(tok->str() == "(" && !scopeStack.top().isExecutable && isFunctionHead(tok,";:")) || (tok->str() == "(" && !scopeStack.top().isExecutable && isFunctionHead(tok,";:")) ||
(tok->str() == "," && !scopeStack.top().isExecutable) || (tok->str() == "," && !scopeStack.top().isExecutable) ||
(tok->isName() && tok->str().back() == ':'))) { (tok->isName() && endsWith(tok->str(), ':')))) {
// No variable declarations in sizeof // No variable declarations in sizeof
if (Token::simpleMatch(tok->previous(), "sizeof (")) { if (Token::simpleMatch(tok->previous(), "sizeof (")) {
@ -2662,7 +2662,7 @@ void Tokenizer::setVarIdPass1()
const Token *tok2 = (tok->isName()) ? tok : tok->next(); const Token *tok2 = (tok->isName()) ? tok : tok->next();
// private: protected: public: etc // private: protected: public: etc
while (tok2 && tok2->str().back() == ':') { while (tok2 && endsWith(tok2->str(), ':')) {
tok2 = tok2->next(); tok2 = tok2->next();
} }
if (!tok2) if (!tok2)

View File

@ -24,6 +24,7 @@
#include "preprocessor.h" #include "preprocessor.h"
#include "settings.h" #include "settings.h"
#include "errorlogger.h" #include "errorlogger.h"
#include "utils.h"
#include <cstring> #include <cstring>
#include <sstream> #include <sstream>
@ -301,8 +302,8 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
} else if (std::strchr("+-", ch) && } else if (std::strchr("+-", ch) &&
CurrentToken.length() > 0 && CurrentToken.length() > 0 &&
std::isdigit((unsigned char)CurrentToken[0]) && std::isdigit((unsigned char)CurrentToken[0]) &&
(CurrentToken.back() == 'e' || (endsWith(CurrentToken,'e') ||
CurrentToken.back() == 'E') && endsWith(CurrentToken,'E')) &&
!MathLib::isIntHex(CurrentToken)) { !MathLib::isIntHex(CurrentToken)) {
// Don't separate doubles "4.2e+10" // Don't separate doubles "4.2e+10"
} else if (CurrentToken.empty() && ch == '.' && std::isdigit((unsigned char)code.peek())) { } else if (CurrentToken.empty() && ch == '.' && std::isdigit((unsigned char)code.peek())) {

View File

@ -55,4 +55,8 @@ private:
Cont data_; Cont data_;
}; };
inline bool endsWith(const std::string &str, char c) {
return str.back() == c;
}
#endif #endif