Skip to content

Commit 1faca91

Browse files
committed
Added 'endsWith' utility function. This will make compiling the democlient easier.
1 parent 4bf4399 commit 1faca91

13 files changed

Lines changed: 38 additions & 27 deletions

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ endif
300300

301301
###### Build
302302

303-
$(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
303+
$(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
304304
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/analyzerinfo.o $(SRCDIR)/analyzerinfo.cpp
305305

306306
$(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.
390390
$(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
391391
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/errorlogger.o $(SRCDIR)/errorlogger.cpp
392392

393-
$(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
393+
$(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
394394
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/importproject.o $(SRCDIR)/importproject.cpp
395395

396-
$(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
396+
$(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
397397
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/library.o $(SRCDIR)/library.cpp
398398

399-
$(SRCDIR)/mathlib.o: lib/mathlib.cpp lib/cxx11emu.h lib/mathlib.h lib/config.h lib/errorlogger.h lib/suppressions.h
399+
$(SRCDIR)/mathlib.o: lib/mathlib.cpp lib/cxx11emu.h lib/mathlib.h lib/config.h lib/errorlogger.h lib/suppressions.h lib/utils.h
400400
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/mathlib.o $(SRCDIR)/mathlib.cpp
401401

402-
$(SRCDIR)/path.o: lib/path.cpp lib/cxx11emu.h lib/path.h lib/config.h
402+
$(SRCDIR)/path.o: lib/path.cpp lib/cxx11emu.h lib/path.h lib/config.h lib/utils.h
403403
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/path.o $(SRCDIR)/path.cpp
404404

405-
$(SRCDIR)/pathmatch.o: lib/pathmatch.cpp lib/cxx11emu.h lib/pathmatch.h lib/config.h lib/path.h
405+
$(SRCDIR)/pathmatch.o: lib/pathmatch.cpp lib/cxx11emu.h lib/pathmatch.h lib/config.h lib/path.h lib/utils.h
406406
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/pathmatch.o $(SRCDIR)/pathmatch.cpp
407407

408408
$(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
432432
$(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
433433
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/tokenize.o $(SRCDIR)/tokenize.cpp
434434

435-
$(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
435+
$(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
436436
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/tokenlist.o $(SRCDIR)/tokenlist.cpp
437437

438438
$(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

lib/analyzerinfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "analyzerinfo.h"
2020
#include "path.h"
21+
#include "utils.h"
2122
#include <tinyxml2.h>
2223
#include <sstream>
2324

@@ -110,7 +111,7 @@ std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir
110111
}
111112

112113
std::string filename = Path::fromNativeSeparators(buildDir);
113-
if (filename.back() != '/')
114+
if (!endsWith(filename, '/'))
114115
filename += '/';
115116
const std::string::size_type pos = sourcefile.rfind('/');
116117
if (pos == std::string::npos)

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,7 @@ void CheckClass::checkConst()
17341734
continue;
17351735
} else if (func->isOperator() && Token::Match(previous, ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator
17361736
const std::string& opName = func->tokenDef->str();
1737-
if (opName.compare(8, 5, "const") != 0 && (opName.back() == '&' || opName.back() == '*'))
1737+
if (opName.compare(8, 5, "const") != 0 && (endsWith(opName,'&') || endsWith(opName,'*')))
17381738
continue;
17391739
} else {
17401740
// don't warn for unknown types..

lib/errorlogger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void ErrorLogger::ErrorMessage::setmsg(const std::string &msg)
137137
// as an empty message to the user if --verbose is used.
138138
// Even this doesn't cause problems with messages that have multiple
139139
// lines, none of the the error messages should end into it.
140-
assert(!(msg.back() =='\n'));
140+
assert(!endsWith(msg,'\n'));
141141

142142
// The summary and verbose message are separated by a newline
143143
// If there is no newline then both the summary and verbose messages

lib/importproject.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "tokenize.h"
2323
#include "token.h"
2424
#include "tinyxml2.h"
25+
#include "utils.h"
2526
#include <fstream>
2627

2728
void ImportProject::ignorePaths(const std::vector<std::string> &ipaths)
@@ -70,7 +71,7 @@ void ImportProject::FileSettings::setDefines(std::string defs)
7071
}
7172
while (defs.find(";;") != std::string::npos)
7273
defs.erase(defs.find(";;"),1);
73-
if (!defs.empty() && defs.back() == ';')
74+
if (!defs.empty() && endsWith(defs,';'))
7475
defs.erase(defs.size() - 1U); // TODO: Use std::string::pop_back() as soon as travis supports it
7576
bool eq = false;
7677
for (std::size_t pos = 0; pos < defs.size(); ++pos) {
@@ -123,13 +124,13 @@ void ImportProject::FileSettings::setIncludePaths(const std::string &basepath, c
123124
continue;
124125
std::string s(Path::fromNativeSeparators(*it));
125126
if (s[0] == '/' || (s.size() > 1U && s.compare(1,2,":/") == 0)) {
126-
if (s.back() != '/')
127+
if (!endsWith(s,'/'))
127128
s += '/';
128129
I.push_back(s);
129130
continue;
130131
}
131132

132-
if (s.back() == '/') // this is a temporary hack, simplifyPath can crash if path ends with '/'
133+
if (endsWith(s,'/')) // this is a temporary hack, simplifyPath can crash if path ends with '/'
133134
s.erase(s.size() - 1U); // TODO: Use std::string::pop_back() as soon as travis supports it
134135

135136
if (s.find("$(")==std::string::npos) {
@@ -154,7 +155,7 @@ void ImportProject::import(const std::string &filename)
154155
importCompileCommands(fin);
155156
} else if (filename.find(".sln") != std::string::npos) {
156157
std::string path(Path::getPathFromFilename(Path::fromNativeSeparators(filename)));
157-
if (!path.empty() && path.back() != '/')
158+
if (!path.empty() && !endsWith(path,'/'))
158159
path += '/';
159160
importSln(fin,path);
160161
} else if (filename.find(".vcxproj") != std::string::npos) {

lib/library.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "token.h"
2525
#include "symboldatabase.h"
2626
#include "astutils.h"
27+
#include "utils.h"
2728

2829
#include <string>
2930

@@ -87,7 +88,7 @@ Library::Error Library::load(const char exename[], const char path[])
8788
while (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND && !cfgfolders.empty()) {
8889
const std::string cfgfolder(cfgfolders.front());
8990
cfgfolders.pop_front();
90-
const char *sep = (!cfgfolder.empty() && cfgfolder.back()=='/' ? "" : "/");
91+
const char *sep = (!cfgfolder.empty() && endsWith(cfgfolder,'/') ? "" : "/");
9192
const std::string filename(cfgfolder + sep + fullfilename);
9293
error = doc.LoadFile(filename.c_str());
9394
if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND)

lib/mathlib.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "mathlib.h"
2222
#include "errorlogger.h"
23+
#include "utils.h"
2324

2425
#include <algorithm> // VS2013: std::min and std::max
2526
#include <cmath>
@@ -524,7 +525,7 @@ MathLib::bigint MathLib::toLongNumber(const std::string & str)
524525
return static_cast<bigint>(doubleval);
525526
}
526527

527-
if (str[0] == '\'' && str.size() >= 3U && str.back() == '\'') {
528+
if (str[0] == '\'' && str.size() >= 3U && endsWith(str,'\'')) {
528529
return characterLiteralToLongNumber(str.substr(1,str.size()-2));
529530
}
530531

@@ -537,7 +538,7 @@ MathLib::bigint MathLib::toLongNumber(const std::string & str)
537538

538539
double MathLib::toDoubleNumber(const std::string &str)
539540
{
540-
if (str[0] == '\'' && str.size() >= 3U && str.back() == '\'')
541+
if (str[0] == '\'' && str.size() >= 3U && endsWith(str,'\''))
541542
return characterLiteralToLongNumber(str.substr(1,str.size()-2));
542543
if (isIntHex(str))
543544
return static_cast<double>(toLongNumber(str));

lib/path.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#undef __STRICT_ANSI__
2121
#endif
2222
#include "path.h"
23+
#include "utils.h"
2324
#include <algorithm>
2425
#include <vector>
2526
#include <sstream>
@@ -227,7 +228,7 @@ std::string Path::getRelativePath(const std::string& absolutePath, const std::ve
227228
if (absolutePath == *i || i->empty()) // Seems to be a file, or path is empty
228229
continue;
229230

230-
bool endsWithSep = i->back() == '/';
231+
bool endsWithSep = endsWith(*i,'/');
231232
if (absolutePath.compare(0, i->length(), *i) == 0 && absolutePath[i->length() - (endsWithSep?1:0)] == '/') {
232233
std::string rest = absolutePath.substr(i->length() + (endsWithSep?0:1));
233234
return rest;

lib/pathmatch.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "pathmatch.h"
2020
#include "path.h"
21+
#include "utils.h"
2122
#include <algorithm>
2223
#include <ctype.h>
2324

@@ -43,8 +44,8 @@ bool PathMatch::Match(const std::string &path) const
4344
std::transform(findpath.begin(), findpath.end(), findpath.begin(), ::tolower);
4445

4546
// Filtering directory name
46-
if (excludedPath.back() == '/') {
47-
if (findpath.back() != '/')
47+
if (endsWith(excludedPath,'/')) {
48+
if (!endsWith(findpath,'/'))
4849
findpath = RemoveFilename(findpath);
4950

5051
if (excludedPath.length() > findpath.length())

lib/token.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ void Token::update_property_info()
7474
_tokType = eName;
7575
} else if (std::isdigit((unsigned char)_str[0]) || (_str.length() > 1 && _str[0] == '-' && std::isdigit((unsigned char)_str[1])))
7676
_tokType = eNumber;
77-
else if (_str.length() > 1 && _str[0] == '"' && _str.back() == '"')
77+
else if (_str.length() > 1 && _str[0] == '"' && endsWith(_str,'"'))
7878
_tokType = eString;
79-
else if (_str.length() > 1 && _str[0] == '\'' && _str.back() == '\'')
79+
else if (_str.length() > 1 && _str[0] == '\'' && endsWith(_str,'\''))
8080
_tokType = eChar;
8181
else if (_str == "=" || _str == "<<=" || _str == ">>=" ||
8282
(_str.size() == 2U && _str[1] == '=' && std::strchr("+-*/%&^|", _str[0])))

0 commit comments

Comments
 (0)