]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/regexp.js.uncompressed.js
1 define("dojo/regexp", ["./_base/kernel", "./_base/lang"], function(dojo
, lang
) {
7 lang
.getObject("regexp", true, dojo
);
11 // summary: Regular expressions and Builder resources
15 dojo
.regexp
.escapeString = function(/*String*/str
, /*String?*/except
){
17 // Adds escape sequences for special characters in regular expressions
19 // a String with special characters to be left unescaped
21 return str
.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, function(ch
){
22 if(except
&& except
.indexOf(ch
) != -1){
29 dojo
.regexp
.buildGroupRE = function(/*Object|Array*/arr
, /*Function*/re
, /*Boolean?*/nonCapture
){
31 // Builds a regular expression that groups subexpressions
33 // A utility function used by some of the RE generators. The
34 // subexpressions are constructed by the function, re, in the second
35 // parameter. re builds one subexpression for each elem in the array
36 // a, in the first parameter. Returns a string for a regular
37 // expression that groups all the subexpressions.
39 // A single value or an array of values.
41 // A function. Takes one parameter and converts it to a regular
44 // If true, uses non-capturing match, otherwise matches are retained
45 // by regular expression. Defaults to false
47 // case 1: a is a single value.
48 if(!(arr
instanceof Array
)){
49 return re(arr
); // String
52 // case 2: a is an array
54 for(var i
= 0; i
< arr
.length
; i
++){
55 // convert each elem to a RE
59 // join the REs as alternatives in a RE group.
60 return dojo
.regexp
.group(b
.join("|"), nonCapture
); // String
63 dojo
.regexp
.group = function(/*String*/expression
, /*Boolean?*/nonCapture
){
65 // adds group match to expression
67 // If true, uses non-capturing match, otherwise matches are retained
68 // by regular expression.
69 return "(" + (nonCapture
? "?:":"") + expression
+ ")"; // String