]> git.wh0rd.org - tt-rss.git/blob - lib/dojo/data/util/filter.js.uncompressed.js
upgrade dojo to 1.8.3 (refs #570)
[tt-rss.git] / lib / dojo / data / util / filter.js.uncompressed.js
1 define("dojo/data/util/filter", ["../../_base/lang"], function(lang){
2 // module:
3 // dojo/data/util/filter
4 // summary:
5 // TODOC
6
7 var filter = {};
8 lang.setObject("dojo.data.util.filter", filter);
9
10 filter.patternToRegExp = function(/*String*/pattern, /*boolean?*/ ignoreCase){
11 // summary:
12 // Helper function to convert a simple pattern to a regular expression for matching.
13 // description:
14 // Returns a regular expression object that conforms to the defined conversion rules.
15 // For example:
16 //
17 // - ca* -> /^ca.*$/
18 // - *ca* -> /^.*ca.*$/
19 // - *c\*a* -> /^.*c\*a.*$/
20 // - *c\*a?* -> /^.*c\*a..*$/
21 //
22 // and so on.
23 // pattern: string
24 // A simple matching pattern to convert that follows basic rules:
25 //
26 // - * Means match anything, so ca* means match anything starting with ca
27 // - ? Means match single character. So, b?b will match to bob and bab, and so on.
28 // - \ is an escape character. So for example, \* means do not treat * as a match, but literal character *.
29 //
30 // To use a \ as a character in the string, it must be escaped. So in the pattern it should be
31 // represented by \\ to be treated as an ordinary \ character instead of an escape.
32 // ignoreCase:
33 // An optional flag to indicate if the pattern matching should be treated as case-sensitive or not when comparing
34 // By default, it is assumed case sensitive.
35
36 var rxp = "^";
37 var c = null;
38 for(var i = 0; i < pattern.length; i++){
39 c = pattern.charAt(i);
40 switch(c){
41 case '\\':
42 rxp += c;
43 i++;
44 rxp += pattern.charAt(i);
45 break;
46 case '*':
47 rxp += ".*"; break;
48 case '?':
49 rxp += "."; break;
50 case '$':
51 case '^':
52 case '/':
53 case '+':
54 case '.':
55 case '|':
56 case '(':
57 case ')':
58 case '{':
59 case '}':
60 case '[':
61 case ']':
62 rxp += "\\"; //fallthrough
63 default:
64 rxp += c;
65 }
66 }
67 rxp += "$";
68 if(ignoreCase){
69 return new RegExp(rxp,"mi"); //RegExp
70 }else{
71 return new RegExp(rxp,"m"); //RegExp
72 }
73
74 };
75
76 return filter;
77 });