mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
clang-tidy fixes
This commit is contained in:
parent
31a62ac3f2
commit
a5768acf08
@ -15,17 +15,15 @@
|
|||||||
|
|
||||||
std::size_t prefixMatch(const std::string &s1, const std::string &s2) {
|
std::size_t prefixMatch(const std::string &s1, const std::string &s2) {
|
||||||
if(s1.size() < s2.size()) {
|
if(s1.size() < s2.size()) {
|
||||||
if(s2.compare(0, s1.size(), s1.c_str()) == 0) {
|
if (s2.compare(0, s1.size(), s1) == 0) {
|
||||||
return s2.size() - s1.size();
|
return s2.size() - s1.size();
|
||||||
} else {
|
|
||||||
return std::string::npos;
|
|
||||||
}
|
}
|
||||||
|
return std::string::npos;
|
||||||
} else {
|
} else {
|
||||||
if(s1.compare(0, s2.size(), s2.c_str()) == 0) {
|
if(s1.compare(0, s2.size(), s2) == 0) {
|
||||||
return s1.size() - s2.size();
|
return s1.size() - s2.size();
|
||||||
} else {
|
|
||||||
return std::string::npos;
|
|
||||||
}
|
}
|
||||||
|
return std::string::npos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,14 +57,9 @@ enum class MatchType : std::uint8_t { proximity, prefix };
|
|||||||
std::pair<std::string, std::size_t>
|
std::pair<std::string, std::size_t>
|
||||||
findClosestMatch(const std::string &input, const std::vector<std::string> &candidates, MatchType match) {
|
findClosestMatch(const std::string &input, const std::vector<std::string> &candidates, MatchType match) {
|
||||||
std::string closest;
|
std::string closest;
|
||||||
int minDistance = (std::numeric_limits<std::size_t>::max)();
|
std::size_t minDistance = (std::numeric_limits<std::size_t>::max)();
|
||||||
std::size_t distance = minDistance;
|
|
||||||
for(const auto &candidate : candidates) {
|
for(const auto &candidate : candidates) {
|
||||||
if(match == MatchType::proximity) {
|
std::size_t distance=(match == MatchType::proximity)?levenshteinDistance(input, candidate):prefixMatch(input, candidate);
|
||||||
distance = levenshteinDistance(input, candidate);
|
|
||||||
} else {
|
|
||||||
distance = prefixMatch(input, candidate);
|
|
||||||
}
|
|
||||||
if(distance < minDistance) {
|
if(distance < minDistance) {
|
||||||
minDistance = distance;
|
minDistance = distance;
|
||||||
closest = candidate;
|
closest = candidate;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user