Use C++11 string.back() instead of string[string.length()-1]

This commit is contained in:
PKEuS 2015-07-25 17:19:53 +02:00
parent 40a6941577
commit 8ed0180279
8 changed files with 17 additions and 17 deletions

View File

@ -80,7 +80,7 @@ static void AddInclPathsToList(const std::string& FileList, std::list<std::strin
PathName = Path::removeQuotationMarks(PathName);
// If path doesn't end with / or \, add it
if (PathName[PathName.length()-1] != '/')
if (PathName.back() != '/')
PathName += '/';
PathNames->push_back(PathName);
@ -450,7 +450,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
path = Path::removeQuotationMarks(path);
// If path doesn't end with / or \, add it
if (path[path.length()-1] != '/')
if (path.back() != '/')
path += '/';
_settings->_includePaths.push_back(path);
@ -504,7 +504,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
if (FileLister::isDirectory(path)) {
// If directory name doesn't end with / or \, add it
if (path[path.length()-1] != '/')
if (path.back() != '/')
path += '/';
}
_ignoredPaths.push_back(path);

View File

@ -201,7 +201,7 @@ void FileLister::addFiles2(std::set<std::string> &seen_paths,
{
std::ostringstream oss;
oss << path;
if (path.length() > 0 && path[path.length()-1] == '/')
if (path.length() > 0 && path.back() == '/')
oss << "*";
glob_t glob_results;
@ -220,7 +220,7 @@ void FileLister::addFiles2(std::set<std::string> &seen_paths,
if (seen_paths.find(absolute_path) != seen_paths.end())
continue;
if (filename[filename.length()-1] != '/') {
if (filename.back() != '/') {
// File
if ((Path::sameFileName(path,filename) || Path::acceptFile(filename, extra)) && !ignored.Match(filename)) {

View File

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

View File

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

View File

@ -355,7 +355,7 @@ std::string Preprocessor::preprocessCleanupDirectives(const std::string &process
// Trim lines..
if (!line.empty() && line[0] == ' ')
line.erase(0, line.find_first_not_of(" "));
if (!line.empty() && line[line.size()-1] == ' ')
if (!line.empty() && line.back() == ' ')
line.erase(line.find_last_not_of(" ") + 1);
// Preprocessor
@ -1460,7 +1460,7 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
while (cfg.length() > 0 && cfg[0] == ';')
cfg.erase(0, 1);
while (cfg.length() > 0 && cfg[cfg.length()-1] == ';')
while (cfg.length() > 0 && cfg.back() == ';')
cfg.erase(cfg.length() - 1);
std::string::size_type pos = 0;
@ -2496,7 +2496,7 @@ static void getparams(const std::string &line,
// spaces are only added if needed
else if (line[pos] == ' ') {
// Add space only if it is needed
if (par.size() && std::isalnum((unsigned char)par[par.length()-1])) {
if (par.size() && std::isalnum((unsigned char)par.back())) {
par += ' ';
}
}
@ -2563,7 +2563,7 @@ private:
for (std::size_t ipar = 0; ipar < params1.size(); ++ipar) {
const std::string s(innerMacroName + "(");
const std::string param(params1[ipar]);
if (param.compare(0,s.length(),s)==0 && param[param.length()-1]==')') {
if (param.compare(0,s.length(),s)==0 && param.back() == ')') {
std::vector<std::string> innerparams;
std::string::size_type pos = s.length() - 1;
unsigned int num = 0;

View File

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

View File

@ -303,8 +303,8 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
} else if (std::strchr("+-", ch) &&
CurrentToken.length() > 0 &&
std::isdigit((unsigned char)CurrentToken[0]) &&
(CurrentToken[CurrentToken.length()-1] == 'e' ||
CurrentToken[CurrentToken.length()-1] == 'E') &&
(CurrentToken.back() == 'e' ||
CurrentToken.back() == 'E') &&
!MathLib::isHex(CurrentToken)) {
// Don't separate doubles "4.2e+10"
} else if (CurrentToken.empty() && ch == '.' && std::isdigit((unsigned char)code.peek())) {

View File

@ -66,8 +66,8 @@ private:
for (std::list<Check *>::const_iterator i = Check::instances().begin(); i != Check::instances().end(); ++i) {
const std::string info = (*i)->classInfo();
if (!info.empty()) {
ASSERT('\n' != info[0]); // No \n in the beginning
ASSERT('\n' == info[info.length()-1]); // \n at end
ASSERT('\n' != info[0]); // No \n in the beginning
ASSERT('\n' == info.back()); // \n at end
if (info.size() > 1)
ASSERT('\n' != info[info.length()-2]); // Only one \n at end
}