summaryrefslogtreecommitdiff
path: root/lib/dojo/regexp.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2011-03-04 19:02:28 +0300
committerAndrew Dolgov <[email protected]>2011-03-04 19:02:59 +0300
commita089699c8915636ba4f158d77dba9b012bc93208 (patch)
treeb2d7d051f1f55d44a6be07d3ee137e5a7ccfcefb /lib/dojo/regexp.js
parentcfad9259a6feacfa8194b1312770ae6db1ecce50 (diff)
build custom layer of Dojo to speed up loading of tt-rss (refs #293)
Diffstat (limited to 'lib/dojo/regexp.js')
-rw-r--r--lib/dojo/regexp.js83
1 files changed, 63 insertions, 20 deletions
diff --git a/lib/dojo/regexp.js b/lib/dojo/regexp.js
index 2c63514f3..1da68f452 100644
--- a/lib/dojo/regexp.js
+++ b/lib/dojo/regexp.js
@@ -5,28 +5,71 @@
*/
-if(!dojo._hasResource["dojo.regexp"]){
-dojo._hasResource["dojo.regexp"]=true;
+if(!dojo._hasResource["dojo.regexp"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojo.regexp"] = true;
dojo.provide("dojo.regexp");
-dojo.regexp.escapeString=function(_1,_2){
-return _1.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,function(ch){
-if(_2&&_2.indexOf(ch)!=-1){
-return ch;
-}
-return "\\"+ch;
-});
+
+/*=====
+dojo.regexp = {
+ // summary: Regular expressions and Builder resources
};
-dojo.regexp.buildGroupRE=function(_3,re,_4){
-if(!(_3 instanceof Array)){
-return re(_3);
+=====*/
+
+dojo.regexp.escapeString = function(/*String*/str, /*String?*/except){
+ // summary:
+ // Adds escape sequences for special characters in regular expressions
+ // except:
+ // a String with special characters to be left unescaped
+
+ return str.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, function(ch){
+ if(except && except.indexOf(ch) != -1){
+ return ch;
+ }
+ return "\\" + ch;
+ }); // String
}
-var b=[];
-for(var i=0;i<_3.length;i++){
-b.push(re(_3[i]));
+
+dojo.regexp.buildGroupRE = function(/*Object|Array*/arr, /*Function*/re, /*Boolean?*/nonCapture){
+ // summary:
+ // Builds a regular expression that groups subexpressions
+ // description:
+ // A utility function used by some of the RE generators. The
+ // subexpressions are constructed by the function, re, in the second
+ // parameter. re builds one subexpression for each elem in the array
+ // a, in the first parameter. Returns a string for a regular
+ // expression that groups all the subexpressions.
+ // arr:
+ // A single value or an array of values.
+ // re:
+ // A function. Takes one parameter and converts it to a regular
+ // expression.
+ // nonCapture:
+ // If true, uses non-capturing match, otherwise matches are retained
+ // by regular expression. Defaults to false
+
+ // case 1: a is a single value.
+ if(!(arr instanceof Array)){
+ return re(arr); // String
+ }
+
+ // case 2: a is an array
+ var b = [];
+ for(var i = 0; i < arr.length; i++){
+ // convert each elem to a RE
+ b.push(re(arr[i]));
+ }
+
+ // join the REs as alternatives in a RE group.
+ return dojo.regexp.group(b.join("|"), nonCapture); // String
}
-return dojo.regexp.group(b.join("|"),_4);
-};
-dojo.regexp.group=function(_5,_6){
-return "("+(_6?"?:":"")+_5+")";
-};
+
+dojo.regexp.group = function(/*String*/expression, /*Boolean?*/nonCapture){
+ // summary:
+ // adds group match to expression
+ // nonCapture:
+ // If true, uses non-capturing match, otherwise matches are retained
+ // by regular expression.
+ return "(" + (nonCapture ? "?:":"") + expression + ")"; // String
+}
+
}