| 154 | } |
| 155 | |
| 156 | std::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 | |
| 180 | bool StringUtils::from_hex(uint8_t ch, uint8_t& output) { |
| 181 | if (ch > 127) { |