]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/regexp.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojo / regexp.js
1 if(!dojo._hasResource["dojo.regexp"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.regexp"] = true;
3 dojo.provide("dojo.regexp");
4
5 /*=====
6 dojo.regexp = {
7         // summary: Regular expressions and Builder resources
8 };
9 =====*/
10
11 dojo.regexp.escapeString = function(/*String*/str, /*String?*/except){
12         //      summary:
13         //              Adds escape sequences for special characters in regular expressions
14         // except:
15         //              a String with special characters to be left unescaped
16
17 //      return str.replace(/([\f\b\n\t\r[\^$|?*+(){}])/gm, "\\$1"); // string
18         return str.replace(/([\.$?*!=:|{}\(\)\[\]\\\/^])/g, function(ch){
19                 if(except && except.indexOf(ch) != -1){
20                         return ch;
21                 }
22                 return "\\" + ch;
23         }); // String
24 }
25
26 dojo.regexp.buildGroupRE = function(/*Object|Array*/arr, /*Function*/re, /*Boolean?*/nonCapture){
27         //      summary:
28         //              Builds a regular expression that groups subexpressions
29         //      description:
30         //              A utility function used by some of the RE generators. The
31         //              subexpressions are constructed by the function, re, in the second
32         //              parameter.  re builds one subexpression for each elem in the array
33         //              a, in the first parameter. Returns a string for a regular
34         //              expression that groups all the subexpressions.
35         // arr:
36         //              A single value or an array of values.
37         // re:
38         //              A function. Takes one parameter and converts it to a regular
39         //              expression. 
40         // nonCapture:
41         //              If true, uses non-capturing match, otherwise matches are retained
42         //              by regular expression. Defaults to false
43
44         // case 1: a is a single value.
45         if(!(arr instanceof Array)){
46                 return re(arr); // String
47         }
48
49         // case 2: a is an array
50         var b = [];
51         for(var i = 0; i < arr.length; i++){
52                 // convert each elem to a RE
53                 b.push(re(arr[i]));
54         }
55
56          // join the REs as alternatives in a RE group.
57         return dojo.regexp.group(b.join("|"), nonCapture); // String
58 }
59
60 dojo.regexp.group = function(/*String*/expression, /*Boolean?*/nonCapture){
61         // summary:
62         //              adds group match to expression
63         // nonCapture:
64         //              If true, uses non-capturing match, otherwise matches are retained
65         //              by regular expression. 
66         return "(" + (nonCapture ? "?:":"") + expression + ")"; // String
67 }
68
69 }