11USERVER_NAMESPACE_BEGIN
17std::string SuggestNameErrorMsg(std::optional<std::string_view> suggest_name);
28template <
typename StringViews,
typename DistanceFunc = std::size_t (*)(std::string_view, std::string_view)>
36 std::is_convertible_v<
decltype(*std::begin(strings)), std::string_view>,
37 "Parameter `strings` should be an iterable over strings."
40 std::optional<std::string_view> nearest_str;
41 std::size_t min_distance = 0;
42 for (
const auto& str : strings) {
43 std::string_view obj_view(str);
44 std::size_t cur_distance = distance_func(key, obj_view);
45 if (!nearest_str.has_value() || cur_distance < min_distance) {
46 nearest_str = obj_view;
47 min_distance = cur_distance;
50 if (nearest_str.has_value() && min_distance <= max_distance) {
57template <
typename StringViews>
60 std::is_convertible_v<
decltype(*std::begin(strings)), std::string_view>,
61 "Parameter `strings` should be an iterable over strings."
63 constexpr std::size_t kMaxDistance = 3;
64 return impl::SuggestNameErrorMsg(utils::GetNearestString(strings, key, kMaxDistance));