Skip to content

Commit

Permalink
fix StringTrimRight range error
Browse files Browse the repository at this point in the history
  • Loading branch information
lqxhub committed Nov 21, 2023
1 parent ab0476f commit 1933ab5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/pstd/pstd_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ std::string StringTrim(const std::string& ori, const std::string& charList) {
}

auto end = ori.find_last_not_of(charList);
return std::move(ori.substr(begin, end - begin + 1));
return ori.substr(begin, end - begin + 1);
}

// Trim charList from left
Expand All @@ -599,7 +599,7 @@ std::string StringTrimLeft(const std::string& ori, const std::string& charList)
if (begin == std::string::npos) {
return "";
}
return std::move(ori.substr(begin, ori.size() - begin));
return ori.substr(begin, ori.size() - begin);
}

// Trim charList from right
Expand All @@ -609,7 +609,10 @@ std::string StringTrimRight(const std::string& ori, const std::string& charList)
}

auto end = ori.find_last_not_of(charList);
return std::move(ori.substr(0, end + 1));
if (end == std::string::npos) {
return "";
}
return ori.substr(0, end + 1);
}

bool StringHasSpaces(const std::string& str) {
Expand Down

0 comments on commit 1933ab5

Please sign in to comment.