mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-30 11:27:07 +00:00
Don't use std::mismatch. Unit tests crash on Windows.
This commit is contained in:
parent
b272fc427c
commit
0dbe8a9171
@ -504,15 +504,37 @@ std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
|
|||||||
// Computes a score based on how well |a| and |b| match. This is used for
|
// Computes a score based on how well |a| and |b| match. This is used for
|
||||||
// argument guessing.
|
// argument guessing.
|
||||||
int ComputeGuessScore(const std::string& a, const std::string& b) {
|
int ComputeGuessScore(const std::string& a, const std::string& b) {
|
||||||
// Increase score based on common prefix and suffix. Prefixes are prioritized.
|
const int kMatchPrefixWeight = 100;
|
||||||
size_t i = std::mismatch(a.begin(), a.end(), b.begin()).first - a.begin();
|
const int kMismatchDirectoryWeight = 100;
|
||||||
size_t j = std::mismatch(a.rbegin(), a.rend(), b.rbegin()).first - a.rbegin();
|
const int kMatchPostfixWeight = 1;
|
||||||
int score = 10 * i + j;
|
|
||||||
|
int score = 0;
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
// Increase score based on matching prefix.
|
||||||
|
for (i = 0; i < a.size() && i < b.size(); ++i) {
|
||||||
|
if (a[i] != b[i])
|
||||||
|
break;
|
||||||
|
score += kMatchPrefixWeight;
|
||||||
|
}
|
||||||
|
|
||||||
// Reduce score based on mismatched directory distance.
|
// Reduce score based on mismatched directory distance.
|
||||||
if (i + j < std::min(a.size(), b.size()))
|
for (size_t j = i; j < a.size(); ++j) {
|
||||||
score -= 100 * (std::count(a.begin() + i, a.end() - j, '/') +
|
if (a[j] == '/')
|
||||||
std::count(b.begin() + i, b.end() - j, '/'));
|
score -= kMismatchDirectoryWeight;
|
||||||
|
}
|
||||||
|
for (size_t j = i; j < b.size(); ++j) {
|
||||||
|
if (b[j] == '/')
|
||||||
|
score -= kMismatchDirectoryWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increase score based on common ending. Don't increase as much as matching
|
||||||
|
// prefix or directory distance.
|
||||||
|
for (size_t offset = 1; offset <= a.size() && offset <= b.size(); ++offset) {
|
||||||
|
if (a[a.size() - offset] != b[b.size() - offset])
|
||||||
|
break;
|
||||||
|
score += kMatchPostfixWeight;
|
||||||
|
}
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user