Skip to content

Commit 7c688a5

Browse files
committed
PreProcessor: extracted trim() to utils.{cpp|h}
1 parent ea2e716 commit 7c688a5

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

lib/preprocessor.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ static bool sameline(const simplecpp::Token *tok1, const simplecpp::Token *tok2)
4343
return tok1 && tok2 && tok1->location.sameline(tok2->location);
4444
}
4545

46-
/**
47-
* Remove heading and trailing whitespaces from the input parameter.
48-
* If string is all spaces/tabs, return empty string.
49-
* @param s The string to trim.
50-
*/
51-
static std::string trim(const std::string& s)
52-
{
53-
const std::string::size_type beg = s.find_first_not_of(" \t");
54-
if (beg == std::string::npos)
55-
return "";
56-
const std::string::size_type end = s.find_last_not_of(" \t");
57-
return s.substr(beg, end - beg + 1);
58-
}
59-
6046
Directive::Directive(std::string _file, const int _linenr, const std::string &_str) :
6147
file(std::move(_file)),
6248
linenr(_linenr),

lib/utils.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,12 @@ void strTolower(std::string& str)
129129
return std::tolower(c);
130130
});
131131
}
132+
133+
std::string trim(const std::string& s)
134+
{
135+
const std::string::size_type beg = s.find_first_not_of(" \t");
136+
if (beg == std::string::npos)
137+
return "";
138+
const std::string::size_type end = s.find_last_not_of(" \t");
139+
return s.substr(beg, end - beg + 1);
140+
}

lib/utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ static inline const char* bool_to_string(bool b)
347347
return b ? "true" : "false";
348348
}
349349

350+
/**
351+
* Remove heading and trailing whitespaces from the input parameter.
352+
* If string is all spaces/tabs, return empty string.
353+
* @param s The string to trim.
354+
*/
355+
CPPCHECKLIB std::string trim(const std::string& s);
356+
350357
namespace cppcheck
351358
{
352359
NORETURN inline void unreachable()

0 commit comments

Comments
 (0)