Skip to content

Commit 60e83d9

Browse files
authored
only trim leading and trailing whitespace from config file vars (#129)
1 parent e19d92a commit 60e83d9

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

intercept/OS/OS_linux_common.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ bool Services_Common::GetControl(
116116
return found;
117117
}
118118

119+
static std::string trim(const std::string& str)
120+
{
121+
const std::string whitespace(" \t");
122+
const auto start = str.find_first_not_of(whitespace);
123+
const auto end = str.find_last_not_of(whitespace);
124+
125+
if( start == std::string::npos || end == std::string::npos )
126+
{
127+
return "";
128+
}
129+
130+
return str.substr(start, end - start + 1);
131+
}
132+
119133
bool Services_Common::GetControlFromFile(
120134
const std::string& fileName,
121135
const std::string& controlName,
@@ -151,11 +165,9 @@ bool Services_Common::GetControlFromFile(
151165
size_t pos = s.find('=');
152166
if( pos != std::string::npos )
153167
{
154-
std::string var = s.substr( 0, pos );
155-
var.erase(std::remove_if(var.begin(), var.end(), ::isspace), var.end());
156-
157-
std::string value = s.substr( pos + 1 );
158-
value.erase(std::remove_if(value.begin(), value.end(), ::isspace), value.end());
168+
const std::string whitespace(" \t");
169+
std::string var = trim(s.substr( 0, pos ));
170+
std::string value = trim(s.substr( pos + 1 ));
159171

160172
if( var == controlName )
161173
{

0 commit comments

Comments
 (0)