[base] Trim impl was replaced to faster.

This commit is contained in:
Maksim Andrianov 2020-12-07 22:22:00 +03:00 committed by mpimenov
parent 5ed308ed0e
commit f4d915c0f2
3 changed files with 26 additions and 28 deletions

View file

@ -203,8 +203,27 @@ char ascii_to_lower(char in)
} // namespace
void AsciiToLower(std::string & s) { transform(s.begin(), s.end(), s.begin(), &ascii_to_lower); }
void Trim(std::string & s) { boost::trim(s); }
void Trim(std::string & s, char const * anyOf) { boost::trim_if(s, boost::is_any_of(anyOf)); }
std::string & Ltrim(std::string & s)
{
s.erase(s.begin(), std::find_if(s.cbegin(), s.cend(), [](auto c) { return !std::isspace(c); }));
return s;
}
std::string & Rtrim(std::string & s)
{
s.erase(std::find_if(s.crbegin(), s.crend(), [](auto c) { return !std::isspace(c); }).base(),
s.end());
return s;
}
std::string & Trim(std::string & s) { return Ltrim(Rtrim(s)); }
std::string & Trim(std::string & s, char const * anyOf)
{
boost::trim_if(s, boost::is_any_of(anyOf));
return s;
}
bool ReplaceFirst(std::string & str, std::string const & from, std::string const & to)
{

View file

@ -101,11 +101,11 @@ void NormalizeDigits(UniString & us);
size_t CountNormLowerSymbols(UniString const & s, UniString const & lowStr);
void AsciiToLower(std::string & s);
// TODO(AlexZ): current boost impl uses default std::locale() to trim.
// TODO(AlexZ): current impl works as boost trim, that uses default std::locale() to trim.
// In general, it does not work for any unicode whitespace except ASCII U+0020 one.
void Trim(std::string & s);
std::string & Trim(std::string & s);
/// Remove any characters that contain in "anyOf" on left and right side of string s
void Trim(std::string & s, char const * anyOf);
std::string & Trim(std::string & s, char const * anyOf);
// Replace the first match of the search substring in the input with the format string.
// str - An input string

View file

@ -9,27 +9,6 @@
#include <cstring>
#include <sstream>
namespace
{
std::string & Ltrim(std::string & s)
{
s.erase(s.begin(), std::find_if(s.cbegin(), s.cend(), [](auto c) {return !std::isspace(c); }));
return s;
}
std::string & Rtrim(std::string & s)
{
s.erase(std::find_if(s.crbegin(), s.crend(), [](auto c) {return !std::isspace(c); }).base(),
s.end());
return s;
}
std::string & Trim(std::string & s)
{
return Ltrim(Rtrim(s));
}
} // namespace
std::string DebugPrint(OsmElement::EntityType type)
{
switch (type)
@ -89,8 +68,8 @@ void OsmElement::AddTag(char const * key, char const * value)
SKIP_KEY_BY_PREFIX("official_name");
#undef SKIP_KEY_BY_PREFIX
std::string val{value};
m_tags.emplace_back(key, std::move(Trim(val)));
std::string val(value);
m_tags.emplace_back(key, std::move(strings::Trim(val)));
}
void OsmElement::AddTag(std::string const & key, std::string const & value)