21 #include "gtest/gtest.h" 68 EXPECT_EQ(s,
"xxxbxxxbxxx");
71 EXPECT_EQ(s,
"axxxaxxxa");
74 EXPECT_EQ(s,
"xbxbx");
77 EXPECT_EQ(s,
"axaxa");
111 "Abc!", {{
"a",
"x"}, {
"ab",
"xy"}, {
"b",
"y"}, {
"bc",
"yz"}, {
"c",
"z"}});
112 EXPECT_EQ(s,
"Ayz!");
117 {{
"a",
"x"}, {
"ab",
"xy"}, {
"b",
"y"}, {
"bc!",
"yz?"}, {
"c!",
"z;"}});
118 EXPECT_EQ(s,
"Ayz?");
122 EXPECT_EQ(s,
"xxxXXXXxxxXXXXxxx");
140 {
"the lazy",
"liquor"},
142 EXPECT_EQ(s,
"pack my box with five dozen liquor jugs");
146 std::map<const char *, const char *> replacements;
147 replacements[
"$who"] =
"Bob";
148 replacements[
"$count"] =
"5";
149 replacements[
"#Noun"] =
"Apples";
152 EXPECT_EQ(
"Bob bought 5 Apples. Thanks Bob!", s);
156 std::string s = std::string(
"$who bought $count #Noun. Thanks $who!");
160 {
"#Noun",
"Apples"}}, &s);
162 EXPECT_EQ(
"Bob bought 5 Apples. Thanks Bob!", s);
166 std::string s = std::string(
"$who bought $count #Noun. Thanks $who!");
167 std::map<absl::string_view, absl::string_view> replacements;
168 replacements[
"$who"] =
"Bob";
169 replacements[
"$count"] =
"5";
170 replacements[
"#Noun"] =
"Apples";
174 EXPECT_EQ(
"Bob bought 5 Apples. Thanks Bob!", s);
187 auto it = splitter.begin();
188 for (
int i = 0;
i < index; ++
i) ++it;
196 std::vector<std::pair<std::string, std::string>> replacements;
203 replacements.push_back({
"a",
"A"});
208 replacements.push_back({
"b",
"B"});
213 replacements.push_back({
"d",
"D"});
221 std::map<const char*, const char*> replacements;
222 replacements[
"aa"] =
"x";
223 replacements[
"a"] =
"X";
232 std::list<std::pair<absl::string_view, absl::string_view>> replacements = {
233 {
"a",
"x"}, {
"b",
"y"}, {
"c",
"z"}};
240 using X = std::tuple<absl::string_view, std::string, int>;
241 std::vector<X> replacements(3);
242 replacements[0] =
X{
"a",
"x", 1};
243 replacements[1] =
X{
"b",
"y", 0};
244 replacements[2] =
X{
"c",
"z", -1};
251 std::vector<Cont> replacements(3);
252 replacements[0] =
Cont{
"a:x"};
253 replacements[1] =
Cont{
"b:y"};
254 replacements[2] =
Cont{
"c:z"};
298 {{
"a",
"x"}, {
"ab",
"xy"}, {
"b",
"y"}, {
"bc",
"yz"}, {
"c",
"z"}}, &s);
300 EXPECT_EQ(s,
"Ayz!");
305 {{
"a",
"x"}, {
"ab",
"xy"}, {
"b",
"y"}, {
"bc!",
"yz?"}, {
"c!",
"z;"}}, &s);
307 EXPECT_EQ(s,
"Ayz?");
313 EXPECT_EQ(s,
"xxxXXXXxxxXXXXxxx");
326 s =
"the quick brown fox jumped over the lazy dogs";
336 {
"the lazy",
"liquor"},
340 EXPECT_EQ(s,
"pack my box with five dozen liquor jugs");
Cont(absl::string_view src)
TEST(StrReplaceAll, OneReplacement)
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
strings_internal::Splitter< typename strings_internal::SelectDelimiter< Delimiter >::type, AllowEmpty > StrSplit(strings_internal::ConvertibleToStringView text, Delimiter d)
std::string StrReplaceAll(absl::string_view s, strings_internal::FixedMapping replacements)