2022-03-03 11:50:35 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "comparator.hh"
|
|
|
|
#include "types.hh"
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2022-03-03 14:12:27 +02:00
|
|
|
int levenshteinDistance(std::string_view first, std::string_view second);
|
|
|
|
|
2022-03-03 11:50:35 +02:00
|
|
|
/**
|
|
|
|
* A potential suggestion for the cli interface.
|
|
|
|
*/
|
|
|
|
class Suggestion {
|
|
|
|
public:
|
|
|
|
int distance; // The smaller the better
|
|
|
|
std::string suggestion;
|
|
|
|
|
2022-03-07 11:04:57 +02:00
|
|
|
std::string to_string() const;
|
2022-03-03 11:50:35 +02:00
|
|
|
|
|
|
|
GENERATE_CMP(Suggestion, me->distance, me->suggestion)
|
|
|
|
};
|
|
|
|
|
|
|
|
class Suggestions {
|
|
|
|
public:
|
|
|
|
std::set<Suggestion> suggestions;
|
|
|
|
|
2022-03-07 11:04:57 +02:00
|
|
|
std::string to_string() const;
|
2022-03-03 11:50:35 +02:00
|
|
|
|
|
|
|
Suggestions trim(
|
|
|
|
int limit = 5,
|
|
|
|
int maxDistance = 2
|
|
|
|
) const;
|
|
|
|
|
|
|
|
static Suggestions bestMatches (
|
|
|
|
std::set<std::string> allMatches,
|
|
|
|
std::string query
|
|
|
|
);
|
|
|
|
|
|
|
|
Suggestions& operator+=(const Suggestions & other);
|
|
|
|
};
|
2022-03-07 11:04:57 +02:00
|
|
|
|
|
|
|
std::ostream & operator<<(std::ostream & str, const Suggestion &);
|
|
|
|
std::ostream & operator<<(std::ostream & str, const Suggestions &);
|
2022-03-03 11:50:35 +02:00
|
|
|
}
|