1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 12:13:52 +00:00

style: pre-commit.ci fixes

This commit is contained in:
pre-commit-ci[bot] 2025-04-23 01:28:38 +00:00
parent ae0735c88c
commit 31a62ac3f2

View File

@ -13,24 +13,17 @@
#include <utility>
#include <vector>
std::size_t prefixMatch(const std::string& s1, const std::string& s2)
{
if (s1.size() < s2.size())
{
if (s2.compare(0, s1.size(), s1.c_str()) == 0)
{
std::size_t prefixMatch(const std::string &s1, const std::string &s2) {
if(s1.size() < s2.size()) {
if(s2.compare(0, s1.size(), s1.c_str()) == 0) {
return s2.size() - s1.size();
}
else {
} else {
return std::string::npos;
}
}
else {
if (s1.compare(0, s2.size(), s2.c_str()) == 0)
{
} else {
if(s1.compare(0, s2.size(), s2.c_str()) == 0) {
return s1.size() - s2.size();
}
else {
} else {
return std::string::npos;
}
}
@ -63,17 +56,15 @@ std::size_t levenshteinDistance(const std::string &s1, const std::string &s2) {
enum class MatchType : std::uint8_t { proximity, prefix };
// Finds the closest string from a list (modified from chat gpt code)
std::pair<std::string, std::size_t> findClosestMatch(const std::string &input, const std::vector<std::string> &candidates,MatchType match) {
std::pair<std::string, std::size_t>
findClosestMatch(const std::string &input, const std::vector<std::string> &candidates, MatchType match) {
std::string closest;
int minDistance = (std::numeric_limits<std::size_t>::max)();
std::size_t distance = minDistance;
for(const auto &candidate : candidates) {
if (match == MatchType::proximity)
{
if(match == MatchType::proximity) {
distance = levenshteinDistance(input, candidate);
}
else
{
} else {
distance = prefixMatch(input, candidate);
}
if(distance < minDistance) {
@ -85,8 +76,7 @@ std::pair<std::string, std::size_t> findClosestMatch(const std::string &input, c
return {closest, minDistance};
}
void addCloseMatchDetection(CLI::App* app, MatchType match)
{
void addCloseMatchDetection(CLI::App *app, MatchType match) {
app->allow_extras(true);
app->parse_complete_callback([&app, match]() {
@ -116,7 +106,8 @@ void addCloseMatchDetection(CLI::App* app, MatchType match)
});
}
/** This example demonstrates the use of close match detection to detect invalid commands that are close matches to existing ones
/** This example demonstrates the use of close match detection to detect invalid commands that are close matches to
* existing ones
*/
int main(int argc, const char *argv[]) {