]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/data/util/filter.js.uncompressed.js
1 define("dojo/data/util/filter", ["../../_base/lang"], function(lang
){
3 // dojo/data/util/filter
8 lang
.setObject("dojo.data.util.filter", filter
);
10 filter
.patternToRegExp = function(/*String*/pattern
, /*boolean?*/ ignoreCase
){
12 // Helper function to convert a simple pattern to a regular expression for matching.
14 // Returns a regular expression object that conforms to the defined conversion rules.
18 // - *ca* -> /^.*ca.*$/
19 // - *c\*a* -> /^.*c\*a.*$/
20 // - *c\*a?* -> /^.*c\*a..*$/
24 // A simple matching pattern to convert that follows basic rules:
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 *.
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.
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.
38 for(var i
= 0; i
< pattern
.length
; i
++){
39 c
= pattern
.charAt(i
);
44 rxp
+= pattern
.charAt(i
);
62 rxp
+= "\\"; //fallthrough
69 return new RegExp(rxp
,"mi"); //RegExp
71 return new RegExp(rxp
,"m"); //RegExp