Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long cmpFuzzy(string haystack, string needle){
- long scoreMul = 100;
- long score = scoreMul*10;
- size_t curIdx;
- long largestScore;
- foreach(i, c; haystack){
- if(curIdx<needle.length && c.toLower == needle[curIdx].toLower){
- score += scoreMul;
- scoreMul *= scoreMul;//(c == needle[curIdx] ? 4 : 3);
- curIdx++;
- }else{
- scoreMul = 100;
- }
- if(curIdx==needle.length){
- scoreMul = 100;
- curIdx = 0;
- score = scoreMul*10;
- if(largestScore < score-i+needle.length)
- largestScore = score-i+needle.length;
- }
- }
- if(!largestScore)
- return 0;
- if(!needle.startsWith(".") && (haystack.canFind("/.") || haystack.startsWith(".")))
- largestScore -= 5;
- if(needle == haystack)
- largestScore += 10000000;
- return largestScore;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement