Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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