diff options
Diffstat (limited to 'libdevcore/StringUtils.cpp')
-rw-r--r-- | libdevcore/StringUtils.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/libdevcore/StringUtils.cpp b/libdevcore/StringUtils.cpp index 2ff86bd5..50bf7cce 100644 --- a/libdevcore/StringUtils.cpp +++ b/libdevcore/StringUtils.cpp @@ -29,13 +29,16 @@ using namespace std; using namespace dev; -bool dev::stringWithinDistance(string const& _str1, string const& _str2, size_t _maxDistance) +bool dev::stringWithinDistance(string const& _str1, string const& _str2, size_t _maxDistance, size_t _lenThreshold) { if (_str1 == _str2) return true; size_t n1 = _str1.size(); size_t n2 = _str2.size(); + if (_lenThreshold > 0 && n1 * n2 > _lenThreshold) + return false; + size_t distance = stringDistance(_str1, _str2); // if distance is not greater than _maxDistance, and distance is strictly less than length of both names, they can be considered similar @@ -85,17 +88,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() + "\""; - - string choices = "\"" + suggestions.front() + "\""; - for (size_t i = 1; i + 1 < suggestions.size(); ++i) - choices += ", \"" + suggestions[i] + "\""; + vector<string> quotedSuggestions; - choices += " or \"" + suggestions.back() + "\""; + for (auto& suggestion: suggestions) + quotedSuggestions.push_back("\"" + suggestion + "\""); - return choices; + return joinHumanReadable(quotedSuggestions, ", ", " or "); } |