fix Trim failed
This commit is contained in:
parent
5413784c57
commit
f31657640f
@ -44,14 +44,15 @@ StrSplit(const std::string &str, const std::string &delim, bool skip_empty)
|
|||||||
std::string
|
std::string
|
||||||
Trim(const std::string &str, const std::string &chars)
|
Trim(const std::string &str, const std::string &chars)
|
||||||
{
|
{
|
||||||
return TrimLeft(TrimRight(str));
|
return TrimLeft(TrimRight(str, chars), chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
TrimLeft(const std::string &str, const std::string &chars)
|
TrimLeft(const std::string &str, const std::string &chars)
|
||||||
{
|
{
|
||||||
size_t start = 0;
|
size_t start = 0;
|
||||||
while (start < str.size() && chars.find(str[start]) != std::string::npos) {
|
while (start < str.size()
|
||||||
|
&& chars.find_first_of(str[start]) != std::string::npos) {
|
||||||
++start;
|
++start;
|
||||||
}
|
}
|
||||||
return str.substr(start);
|
return str.substr(start);
|
||||||
@ -61,7 +62,9 @@ std::string
|
|||||||
TrimRight(const std::string &str, const std::string &chars)
|
TrimRight(const std::string &str, const std::string &chars)
|
||||||
{
|
{
|
||||||
size_t end = str.size();
|
size_t end = str.size();
|
||||||
while (end > 0 && chars.find(str[end - 1]) != std::string::npos) { --end; }
|
while (end > 0 && chars.find_first_of(str[end - 1]) != std::string::npos) {
|
||||||
|
--end;
|
||||||
|
}
|
||||||
return str.substr(0, end);
|
return str.substr(0, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user