mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-27 15:53:31 +03:00
34 lines
762 B
Swift
34 lines
762 B
Swift
/**
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
* See LICENSE
|
|
*/
|
|
|
|
import Foundation
|
|
|
|
class Scorer {
|
|
|
|
static func score(_ target: String, pattern: String) -> Int {
|
|
let wf = Matcher.wagnerFisherDistance(target, pattern: pattern)
|
|
let fuzzy = Matcher.fuzzyIgnoringCase(target, pattern: pattern)
|
|
let upper = Matcher.numberOfUppercaseMatches(target, pattern: pattern)
|
|
let exactMatch = Matcher.exactMatchIgnoringCase(target, pattern: pattern)
|
|
|
|
let exactScore: Int
|
|
switch exactMatch {
|
|
case .none:
|
|
exactScore = 0
|
|
case .exact:
|
|
return 100
|
|
case .prefix, .contains, .suffix:
|
|
exactScore = 5
|
|
}
|
|
|
|
let wfScore = 0 - (wf / 10)
|
|
|
|
return exactScore
|
|
+ wfScore
|
|
+ fuzzy.matches
|
|
+ 2 * upper
|
|
}
|
|
}
|