From f31657640f5731c2f86206190fe1d59728225795 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sun, 3 Mar 2024 18:05:37 +0800 Subject: [PATCH] fix Trim failed --- src/strings/utils.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/strings/utils.cc b/src/strings/utils.cc index ef66646..50560bd 100644 --- a/src/strings/utils.cc +++ b/src/strings/utils.cc @@ -44,14 +44,15 @@ StrSplit(const std::string &str, const std::string &delim, bool skip_empty) std::string Trim(const std::string &str, const std::string &chars) { - return TrimLeft(TrimRight(str)); + return TrimLeft(TrimRight(str, chars), chars); } std::string TrimLeft(const std::string &str, const std::string &chars) { 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; } return str.substr(start); @@ -61,7 +62,9 @@ std::string TrimRight(const std::string &str, const std::string &chars) { 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); }