11USERVER_NAMESPACE_BEGIN
17std::string SuggestNameErrorMsg(std::optional<std::string_view> suggest_name);
23 std::string_view view2);
27 std::string_view view2);
30template <
typename StringViews,
typename DistanceFunc = std::size_t (*)(
31 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.");
39 std::optional<std::string_view> nearest_str;
40 std::size_t min_distance = 0;
41 for (
const auto& str : strings) {
42 std::string_view obj_view(str);
43 std::size_t cur_distance = distance_func(key, obj_view);
44 if (!nearest_str.has_value() || cur_distance < min_distance) {
45 nearest_str = obj_view;
46 min_distance = cur_distance;
49 if (nearest_str.has_value() && min_distance <= max_distance) {
56template <
typename StringViews>
58 std::string_view key) {
60 std::is_convertible_v<
decltype(*std::begin(strings)), std::string_view>,
61 "Parameter `strings` should be an iterable over strings.");
62 constexpr std::size_t kMaxDistance = 3;
63 return impl::SuggestNameErrorMsg(
64 utils::GetNearestString(strings, key, kMaxDistance));