added helper function that joins vectors of strings, refactored suggestions formattingi function to use it

This commit is contained in:
Evgeniy Filatov committed 2018-08-03 14:07:03 +03:00
1 parent 009a55c82d
commit 3705bcc9bc
3 files changed
+61 -10

No files matched your search

+4 -10
View File
@@ -85,17 +85,11 @@ size_t dev::stringDistance(string const& _str1, string const& _str2)
string dev::quotedAlternativesList(vector<string> const& suggestions)
{
if (suggestions.empty())
return "";
if (suggestions.size() == 1)
return "\"" + suggestions.front() + "\"";
vector<string> quotedSuggestions;
string choices = "\"" + suggestions.front() + "\"";
for (size_t i = 1; i + 1 < suggestions.size(); ++i)
choices += ", \"" + suggestions[i] + "\"";
for (auto& suggestion: suggestions)
quotedSuggestions.push_back("\"" + suggestion + "\"");
choices += " or \"" + suggestions.back() + "\"";
return choices;
return joinHumanReadable(quotedSuggestions, ", ", " or ");
}