38 #ifndef ABSL_STRINGS_STR_REPLACE_H_ 39 #define ABSL_STRINGS_STR_REPLACE_H_ 69 std::initializer_list<std::pair<absl::string_view, absl::string_view>>
95 template <
typename StrToStrMapping>
97 const StrToStrMapping& replacements);
113 std::initializer_list<std::pair<absl::string_view, absl::string_view>>
115 std::string* target);
129 template <
typename StrToStrMapping>
130 int StrReplaceAll(
const StrToStrMapping& replacements, std::string* target);
133 namespace strings_internal {
142 : old(old_str), replacement(replacement_str), offset(offset_val) {}
156 template <
typename StrToStrMapping>
159 std::vector<ViableSubstitution> subs;
160 subs.reserve(replacements.size());
162 for (
const auto& rep : replacements) {
166 size_t pos = s.
find(old);
167 if (pos == s.
npos)
continue;
172 if (old.
empty())
continue;
174 subs.emplace_back(old, get<1>(rep), pos);
178 size_t index = subs.size();
179 while (--index && subs[index - 1].
OccursBefore(subs[index])) {
187 std::vector<ViableSubstitution>* subs_ptr,
188 std::string* result_ptr);
192 template <
typename StrToStrMapping>
194 const StrToStrMapping& replacements) {
197 result.reserve(s.
size());
202 template <
typename StrToStrMapping>
203 int StrReplaceAll(
const StrToStrMapping& replacements, std::string* target) {
205 if (subs.empty())
return 0;
208 result.reserve(target->size());
211 target->swap(result);
212 return substitutions;
217 #endif // ABSL_STRINGS_STR_REPLACE_H_
size_type find(string_view s, size_type pos=0) const noexcept
static constexpr size_type npos
std::vector< ViableSubstitution > FindSubstitutions(absl::string_view s, const StrToStrMapping &replacements)
constexpr size_type size() const noexcept
bool OccursBefore(const ViableSubstitution &y) const
ViableSubstitution(absl::string_view old_str, absl::string_view replacement_str, size_t offset_val)
absl::string_view replacement
#define ABSL_MUST_USE_RESULT
void swap(absl::InlinedVector< T, N, A > &a, absl::InlinedVector< T, N, A > &b) noexcept(noexcept(a.swap(b)))
constexpr bool empty() const noexcept
absl::string_view get(const Cont &c)
int ApplySubstitutions(absl::string_view s, std::vector< strings_internal::ViableSubstitution > *subs_ptr, std::string *result_ptr)
std::string StrReplaceAll(absl::string_view s, strings_internal::FixedMapping replacements)