| 185 | } |
| 186 | |
| 187 | std::vector<std::string> sortByDistance(const std::string& source, |
| 188 | const std::vector<std::string>& words, std::size_t limit) |
| 189 | { |
| 190 | std::vector<std::string> sortedByDistance = words; |
| 191 | std::sort(sortedByDistance.begin(), sortedByDistance.end(), |
| 192 | [source](const std::string& s1, const std::string& s2) { |
| 193 | return Utils::String::distance(s1, source) |
| 194 | < Utils::String::distance(s2, source); |
| 195 | }); |
| 196 | if (limit && !sortedByDistance.empty()) |
| 197 | { |
| 198 | return std::vector<std::string>(sortedByDistance.begin(), |
| 199 | sortedByDistance.begin() + std::min(sortedByDistance.size() - 1, limit)); |
| 200 | } |
| 201 | else |
| 202 | return sortedByDistance; |
| 203 | } |
| 204 | |
| 205 | std::string quote(const std::string& source) |
| 206 | { |
no test coverage detected