| 137 | |
| 138 | template <class F> |
| 139 | inline std::string |
| 140 | interpolate_string(const std::string& input, F f, std::string start = "${", std::string end = "}") |
| 141 | { |
| 142 | std::string result = ""; |
| 143 | result.reserve(input.size()); |
| 144 | auto it = input.begin(); |
| 145 | while(it != input.end()) |
| 146 | { |
| 147 | auto next_start = std::search(it, input.end(), start.begin(), start.end()); |
| 148 | auto next_end = std::search(next_start, input.end(), end.begin(), end.end()); |
| 149 | result.append(it, next_start); |
| 150 | if(next_start == input.end()) |
| 151 | break; |
| 152 | if(next_end == input.end()) |
| 153 | { |
| 154 | throw std::runtime_error("Unbalanced brackets"); |
| 155 | } |
| 156 | auto r = f(next_start + start.size(), next_end); |
| 157 | result.append(r.begin(), r.end()); |
| 158 | it = next_end + end.size(); |
| 159 | } |
| 160 | return result; |
| 161 | } |
| 162 | inline std::string interpolate_string(const std::string& input, |
| 163 | const std::unordered_map<std::string, std::string>& vars, |
| 164 | std::string start = "${", |
no test coverage detected