MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / replaceMap

Method replaceMap

libminifi/src/utils/StringUtils.cpp:156–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156std::string StringUtils::replaceMap(std::string source_string, const std::map<std::string, std::string> &replace_map) {
157 auto result_string = source_string;
158
159 std::vector<std::pair<size_t, std::pair<size_t, std::string>>> replacements;
160 for (const auto &replace_pair : replace_map) {
161 size_t replace_pos = 0;
162 while ((replace_pos = source_string.find(replace_pair.first, replace_pos)) != std::string::npos) {
163 replacements.emplace_back(std::make_pair(replace_pos, std::make_pair(replace_pair.first.length(), replace_pair.second)));
164 replace_pos += replace_pair.first.length();
165 }
166 }
167
168 std::sort(replacements.begin(), replacements.end(), [](const std::pair<size_t, std::pair<size_t, std::string>> a,
169 const std::pair<size_t, std::pair<size_t, std::string>> &b) {
170 return a.first > b.first;
171 });
172
173 for (const auto &replacement : replacements) {
174 result_string = source_string.replace(replacement.first, replacement.second.first, replacement.second.second);
175 }
176
177 return result_string;
178}
179
180bool StringUtils::from_hex(uint8_t ch, uint8_t& output) {
181 if (ch > 127) {

Callers

nothing calls this directly

Calls 5

lengthMethod · 0.80
replaceMethod · 0.80
findMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected