utils: introduce trim()
This commit is contained in:
parent
164b2c19ee
commit
5037a17fba
17
utils.cpp
17
utils.cpp
@ -181,3 +181,20 @@ std::string utils::toISODate(time_t t)
|
|||||||
}
|
}
|
||||||
return std::string{result};
|
return std::string{result};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string utils::trim(const std::string &str)
|
||||||
|
{
|
||||||
|
std::string_view chars = " \t\n\r";
|
||||||
|
std::string_view view = str;
|
||||||
|
auto n = view.find_first_not_of(chars);
|
||||||
|
if(n != std::string_view::npos)
|
||||||
|
{
|
||||||
|
view.remove_prefix(n);
|
||||||
|
}
|
||||||
|
n = view.find_last_not_of(chars);
|
||||||
|
if(n != std::string_view::npos)
|
||||||
|
{
|
||||||
|
view.remove_suffix(view.size() - n - 1);
|
||||||
|
}
|
||||||
|
return std::string{view};
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user