diff options
author | Steven Laver <lavers@google.com> | 2019-12-12 15:29:36 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-12-12 15:29:36 +0000 |
commit | a239544c7b06814b70fd970de7eaac234682fa52 (patch) | |
tree | a4298d61f9b73642f350799b1157e49b65f4e1e8 /base/strings.cpp | |
parent | 63de1e1c8d7824c241f22de67edf54f4f1eaeea5 (diff) | |
parent | 5319412e5305a3b4bcecf251a2955c09a6e9837e (diff) |
Merge "Merge RP1A.191203.001" into r-keystone-qcom-dev
Diffstat (limited to 'base/strings.cpp')
-rw-r--r-- | base/strings.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/base/strings.cpp b/base/strings.cpp index bb3167ef0..40b2bf270 100644 --- a/base/strings.cpp +++ b/base/strings.cpp @@ -116,5 +116,24 @@ bool EqualsIgnoreCase(std::string_view lhs, std::string_view rhs) { return lhs.size() == rhs.size() && strncasecmp(lhs.data(), rhs.data(), lhs.size()) == 0; } +std::string StringReplace(std::string_view s, std::string_view from, std::string_view to, + bool all) { + if (from.empty()) return std::string(s); + + std::string result; + std::string_view::size_type start_pos = 0; + do { + std::string_view::size_type pos = s.find(from, start_pos); + if (pos == std::string_view::npos) break; + + result.append(s.data() + start_pos, pos - start_pos); + result.append(to.data(), to.size()); + + start_pos = pos + from.size(); + } while (all); + result.append(s.data() + start_pos, s.size() - start_pos); + return result; +} + } // namespace base } // namespace android |