]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/atom-space-pen-views/node_modules/fuzzaldrin/lib/matcher.js
57edff4c1539829ada26dee0caba313fcbedc553
4 PathSeparator
= require('path').sep
;
6 exports
.basenameMatch = function(string
, query
) {
7 var base
, index
, lastCharacter
, slashCount
;
8 index
= string
.length
- 1;
9 while (string
[index
] === PathSeparator
) {
13 lastCharacter
= index
;
16 if (string
[index
] === PathSeparator
) {
19 base
= string
.substring(index
+ 1, lastCharacter
+ 1);
21 } else if (index
=== 0) {
22 if (lastCharacter
< string
.length
- 1) {
24 base
= string
.substring(0, lastCharacter
+ 1);
34 return exports
.match(base
, query
, string
.length
- base
.length
);
37 exports
.match = function(string
, query
, stringOffset
) {
38 var character
, indexInQuery
, indexInString
, lowerCaseIndex
, matches
, minIndex
, queryLength
, stringLength
, upperCaseIndex
, _i
, _ref
, _results
;
39 if (stringOffset
== null) {
42 if (string
=== query
) {
45 for (var _i
= stringOffset
, _ref
= stringOffset
+ string
.length
; stringOffset
<= _ref
? _i
< _ref : _i
> _ref
; stringOffset
<= _ref
? _i
++ : _i
--){ _results
.push(_i
); }
49 queryLength
= query
.length
;
50 stringLength
= string
.length
;
54 while (indexInQuery
< queryLength
) {
55 character
= query
[indexInQuery
++];
56 lowerCaseIndex
= string
.indexOf(character
.toLowerCase());
57 upperCaseIndex
= string
.indexOf(character
.toUpperCase());
58 minIndex
= Math
.min(lowerCaseIndex
, upperCaseIndex
);
59 if (minIndex
=== -1) {
60 minIndex
= Math
.max(lowerCaseIndex
, upperCaseIndex
);
62 indexInString
= minIndex
;
63 if (indexInString
=== -1) {
66 matches
.push(stringOffset
+ indexInString
);
67 stringOffset
+= indexInString
+ 1;
68 string
= string
.substring(indexInString
+ 1, stringLength
);