Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transliterate non-latin strings into latin if there's no match #2395

Merged
merged 2 commits into from Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Quicksilver/Code-QuickStepFoundation/QSSense.h
Expand Up @@ -10,4 +10,5 @@


CGFloat QSScoreForAbbreviation(CFStringRef string, CFStringRef abbr, id hitMask);
CGFloat QSScoreForAbbreviationOrTransliteration(CFStringRef str, CFStringRef abbr, id mask);
CGFloat QSScoreForAbbreviationWithRanges(CFStringRef str, CFStringRef abbr, id mask, CFRange strRange, CFRange abbrRange);
20 changes: 19 additions & 1 deletion Quicksilver/Code-QuickStepFoundation/QSSense.m
Expand Up @@ -17,7 +17,25 @@
CGFloat QSScoreForAbbreviationWithRanges(CFStringRef str, CFStringRef abbr, id mask, CFRange strRange, CFRange abbrRange);

CGFloat QSScoreForAbbreviation(CFStringRef str, CFStringRef abbr, id mask) {
return QSScoreForAbbreviationWithRanges(str, abbr, mask, CFRangeMake(0, CFStringGetLength(str)), CFRangeMake(0, CFStringGetLength(abbr)));
return QSScoreForAbbreviationOrTransliteration(str, abbr, mask);
}

CGFloat QSScoreForAbbreviationOrTransliteration(CFStringRef str, CFStringRef abbr, id mask) {
CGFloat score = QSScoreForAbbreviationWithRanges(str, abbr, mask, CFRangeMake(0, CFStringGetLength(str)), CFRangeMake(0, CFStringGetLength(abbr)));
if (score == 0) {
CFMutableStringRef mutableString = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, str);
CFStringTransform(mutableString, nil, kCFStringTransformToLatin, false);

if (CFStringCompare(str, mutableString, 0) != kCFCompareEqualTo) {
// only do this if the two strings are not equal (otherwise it's a wasted compute)
score = QSScoreForAbbreviationWithRanges(mutableString, abbr, nil, CFRangeMake(0, CFStringGetLength(mutableString)), CFRangeMake(0, CFStringGetLength(abbr)));
}
if (mutableString) {
CFRelease(mutableString);
}
return score;
}
return score;
}

CGFloat QSScoreForAbbreviationWithRanges(CFStringRef str, CFStringRef abbr, id mask, CFRange strRange, CFRange abbrRange) {
Expand Down