| 139 | using Expression = vector<TElem>; |
| 140 | |
| 141 | std::string NameMap::replaceNames(const std::string &text, bool expand) const |
| 142 | { |
| 143 | |
| 144 | const auto var_names_begin = |
| 145 | std::sregex_iterator(text.begin(), text.end(), var_name_regex); |
| 146 | const auto var_names_end = std::sregex_iterator(); |
| 147 | |
| 148 | size_t pos = 0; |
| 149 | |
| 150 | Expression expr; |
| 151 | |
| 152 | /// this might require some caching |
| 153 | |
| 154 | for (auto it = var_names_begin; it != var_names_end; ++it) |
| 155 | { |
| 156 | auto match = *it; |
| 157 | auto str = text.substr(pos, static_cast<size_t>(match.position()) - pos); |
| 158 | |
| 159 | if (match.position() != 0) |
| 160 | { |
| 161 | const auto non_id = |
| 162 | text.substr(pos, static_cast<size_t>(match.position()) - pos); |
| 163 | expr.push_back({non_id, false}); |
| 164 | } |
| 165 | |
| 166 | const auto id = match.str(); |
| 167 | expr.push_back({id, true}); |
| 168 | |
| 169 | pos = static_cast<size_t>(match.position() + match.length()); |
| 170 | } |
| 171 | |
| 172 | expr.push_back({text.substr(pos), false}); |
| 173 | |
| 174 | std::stringstream ss; |
| 175 | |
| 176 | for (const auto &el : expr) |
| 177 | { |
| 178 | if (el.is_id) |
| 179 | { |
| 180 | ss << getNiceName(el.str); |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | ss << el.str; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | return ss.str(); |
| 189 | } |
| 190 | |
| 191 | // static string replaceAssignments(const string& path, const string& |
| 192 | // epxression) { |
no test coverage detected