optimize StartsWith,EndsWith
This commit is contained in:
@@ -50,22 +50,15 @@ Trim(const std::string &str, const std::string &chars)
|
||||
std::string
|
||||
TrimLeft(const std::string &str, const std::string &chars)
|
||||
{
|
||||
size_t start = 0;
|
||||
while (start < str.size()
|
||||
&& chars.find_first_of(str[start]) != std::string::npos) {
|
||||
++start;
|
||||
}
|
||||
return str.substr(start);
|
||||
size_t start = str.find_first_not_of(chars);
|
||||
return start == std::string::npos ? "" : str.substr(start);
|
||||
}
|
||||
|
||||
std::string
|
||||
TrimRight(const std::string &str, const std::string &chars)
|
||||
{
|
||||
size_t end = str.size();
|
||||
while (end > 0 && chars.find_first_of(str[end - 1]) != std::string::npos) {
|
||||
--end;
|
||||
}
|
||||
return str.substr(0, end);
|
||||
size_t end = str.find_last_not_of(chars);
|
||||
return end == std::string::npos ? "" : str.substr(0, end + 1);
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
Reference in New Issue
Block a user