Skip to content

Commit 3bb0160

Browse files
committed
utils.h: made characters to trim configurable
1 parent 7c688a5 commit 3bb0160

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

lib/utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ void strTolower(std::string& str)
130130
});
131131
}
132132

133-
std::string trim(const std::string& s)
133+
std::string trim(const std::string& s, const std::string& t)
134134
{
135-
const std::string::size_type beg = s.find_first_not_of(" \t");
135+
const std::string::size_type beg = s.find_first_not_of(t);
136136
if (beg == std::string::npos)
137137
return "";
138-
const std::string::size_type end = s.find_last_not_of(" \t");
138+
const std::string::size_type end = s.find_last_not_of(t);
139139
return s.substr(beg, end - beg + 1);
140140
}

lib/utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,9 @@ static inline const char* bool_to_string(bool b)
351351
* Remove heading and trailing whitespaces from the input parameter.
352352
* If string is all spaces/tabs, return empty string.
353353
* @param s The string to trim.
354+
* @param t The characters to trim.
354355
*/
355-
CPPCHECKLIB std::string trim(const std::string& s);
356+
CPPCHECKLIB std::string trim(const std::string& s, const std::string& t = " \t");
356357

357358
namespace cppcheck
358359
{

0 commit comments

Comments
 (0)