Some refactorizations

This commit is contained in:
PKEuS 2012-02-18 11:55:05 +01:00
parent bfb4dd6425
commit 2ba2a4e6ae
5 changed files with 20 additions and 44 deletions

View File

@ -68,7 +68,7 @@ public:
/**
* Return the path names user gave to command line.
*/
std::vector<std::string> GetPathNames() const {
const std::vector<std::string>& GetPathNames() const {
return _pathnames;
}
@ -89,7 +89,7 @@ public:
/**
* Return a list of paths user wants to ignore.
*/
std::vector<std::string> GetIgnoredPaths() const {
const std::vector<std::string>& GetIgnoredPaths() const {
return _ignoredPaths;
}

View File

@ -54,7 +54,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
const char * extraVersion = cppcheck->extraVersion();
if (strlen(extraVersion) > 0)
std::cout << "Cppcheck " << cppcheck->version() << " ("
<< extraVersion << ")" << std::endl;
<< extraVersion << ')' << std::endl;
else
std::cout << "Cppcheck " << cppcheck->version() << std::endl;
}
@ -84,7 +84,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
else {
// If the include path is not found, warn user and remove the
// non-existing path from the list.
std::cout << "cppcheck: warning: Couldn't find path given by -I '" + path + "'" << std::endl;
std::cout << "cppcheck: warning: Couldn't find path given by -I '" << path << '\'' << std::endl;
iter = _settings._includePaths.erase(iter);
}
}
@ -262,7 +262,7 @@ void CppCheckExecutor::reportProgress(const std::string &filename, const char st
std::ostringstream ostr;
ostr << "progress: "
<< stage
<< " " << int(value) << "%";
<< ' ' << int(value) << '%';
if (_settings._verbose)
ostr << " time=" << str.substr(11, 8);
@ -275,7 +275,7 @@ void CppCheckExecutor::reportStatus(size_t fileindex, size_t filecount, long siz
{
if (filecount > 1) {
std::ostringstream oss;
oss << fileindex << "/" << filecount
oss << fileindex << '/' << filecount
<< " files checked " <<
(sizetotal > 0 ? static_cast<long>(static_cast<long double>(sizedone) / sizetotal*100) : 0)
<< "% done";

View File

@ -277,7 +277,7 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
if (!_callStack.empty())
text << callStackToString(_callStack) << ": ";
if (_severity != Severity::none)
text << "(" << Severity::toString(_severity) << ") ";
text << '(' << Severity::toString(_severity) << ") ";
text << (verbose ? _verboseMessage : _shortMessage);
return text.str();
}
@ -316,10 +316,10 @@ std::string ErrorLogger::callStackToString(const std::list<ErrorLogger::ErrorMes
{
std::ostringstream ostr;
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator tok = callStack.begin(); tok != callStack.end(); ++tok) {
ostr << (tok == callStack.begin() ? "" : " -> ") << "[" << (*tok).getfile();
ostr << (tok == callStack.begin() ? "" : " -> ") << '[' << (*tok).getfile();
if ((*tok).line != 0)
ostr << ":" << (*tok).line;
ostr << "]";
ostr << ':' << (*tok).line;
ostr << ']';
}
return ostr.str();
}

View File

@ -80,7 +80,7 @@ std::string Path::simplifyPath(const char *originalPath)
if (subPath.length() > 0)
pathParts.push_back(subPath);
for (unsigned int i = 0; i < pathParts.size(); ++i) {
for (unsigned int i = 1; i < pathParts.size(); ++i) {
if (i > 1 && pathParts[i-2] != ".." && pathParts[i] == ".." && pathParts.size() > i + 1) {
pathParts.erase(pathParts.begin() + static_cast<int>(i) + 1);
pathParts.erase(pathParts.begin() + static_cast<int>(i));
@ -90,7 +90,7 @@ std::string Path::simplifyPath(const char *originalPath)
} else if (i > 0 && pathParts[i] == ".") {
pathParts.erase(pathParts.begin() + static_cast<int>(i));
i = 0;
} else if (pathParts[i] == "/" && i > 0 && pathParts[i-1] == "/") {
} else if (i > 0 && pathParts[i] == "/" && pathParts[i-1] == "/") {
pathParts.erase(pathParts.begin() + static_cast<int>(i) - 1);
i = 0;
}
@ -158,11 +158,7 @@ bool Path::isC(const std::string &path)
{
// In unix, ".C" is concidered C++ file
const std::string extension = getFilenameExtension(path);
if (extension == ".c") {
return true;
}
return false;
return(extension == ".c");
}
bool Path::isCPP(const std::string &path)
@ -178,40 +174,23 @@ bool Path::isCPP(const std::string &path)
}
// In unix, ".C" is concidered C++ file
if (getFilenameExtension(path) == ".C") {
return true;
}
return false;
return(getFilenameExtension(path) == ".C");
}
bool Path::isJava(const std::string &path)
{
const std::string extension = getFilenameExtensionInLowerCase(path);
if (extension == ".java") {
return true;
}
return false;
return(extension == ".java");
}
bool Path::isCSharp(const std::string &path)
{
const std::string extension = getFilenameExtensionInLowerCase(path);
if (extension == ".cs") {
return true;
}
return false;
return(extension == ".cs");
}
bool Path::acceptFile(const std::string &filename)
{
if (Path::isCPP(filename) ||
Path::isC(filename)) {
return true;
}
return false;
return(Path::isCPP(filename) || Path::isC(filename));
}

View File

@ -27,21 +27,18 @@ class Token;
class givenACodeSampleToTokenize {
private:
std::istringstream _sample;
const Token* _tokens;
Settings _settings;
Tokenizer _tokenizer;
public:
givenACodeSampleToTokenize(const std::string& sample)
: _sample(sample)
,_tokens(NULL) {
_tokenizer.setSettings(&_settings);
, _tokenizer(&_settings, 0) {
_tokenizer.tokenize(_sample, "test.cpp");
_tokens = _tokenizer.tokens();
}
const Token* tokens() const {
return _tokens;
return _tokenizer.tokens();
}
};