scratch – Diff between revs 75 and 125

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 75 Rev 125
1 // Generated by CoffeeScript 1.10.0 1 // Generated by CoffeeScript 1.12.4
2 var Pattern; 2 var Pattern;
3   3  
4 Pattern = (function() { 4 Pattern = (function() {
5 Pattern.prototype.regex = null; 5 Pattern.prototype.regex = null;
6   6  
7 Pattern.prototype.rawRegex = null; 7 Pattern.prototype.rawRegex = null;
8   8  
9 Pattern.prototype.cleanedRegex = null; 9 Pattern.prototype.cleanedRegex = null;
10   10  
11 Pattern.prototype.mapping = null; 11 Pattern.prototype.mapping = null;
12   12  
13 function Pattern(rawRegex, modifiers) { 13 function Pattern(rawRegex, modifiers) {
14 var _char, capturingBracketNumber, cleanedRegex, i, len, mapping, name, part, subChar; 14 var _char, capturingBracketNumber, cleanedRegex, i, len, mapping, name, part, subChar;
15 if (modifiers == null) { 15 if (modifiers == null) {
16 modifiers = ''; 16 modifiers = '';
17 } 17 }
18 cleanedRegex = ''; 18 cleanedRegex = '';
19 len = rawRegex.length; 19 len = rawRegex.length;
20 mapping = null; 20 mapping = null;
21 capturingBracketNumber = 0; 21 capturingBracketNumber = 0;
22 i = 0; 22 i = 0;
23 while (i < len) { 23 while (i < len) {
24 _char = rawRegex.charAt(i); 24 _char = rawRegex.charAt(i);
25 if (_char === '\\') { 25 if (_char === '\\') {
26 cleanedRegex += rawRegex.slice(i, +(i + 1) + 1 || 9e9); 26 cleanedRegex += rawRegex.slice(i, +(i + 1) + 1 || 9e9);
27 i++; 27 i++;
28 } else if (_char === '(') { 28 } else if (_char === '(') {
29 if (i < len - 2) { 29 if (i < len - 2) {
30 part = rawRegex.slice(i, +(i + 2) + 1 || 9e9); 30 part = rawRegex.slice(i, +(i + 2) + 1 || 9e9);
31 if (part === '(?:') { 31 if (part === '(?:') {
32 i += 2; 32 i += 2;
33 cleanedRegex += part; 33 cleanedRegex += part;
34 } else if (part === '(?<') { 34 } else if (part === '(?<') {
35 capturingBracketNumber++; 35 capturingBracketNumber++;
36 i += 2; 36 i += 2;
37 name = ''; 37 name = '';
38 while (i + 1 < len) { 38 while (i + 1 < len) {
39 subChar = rawRegex.charAt(i + 1); 39 subChar = rawRegex.charAt(i + 1);
40 if (subChar === '>') { 40 if (subChar === '>') {
41 cleanedRegex += '('; 41 cleanedRegex += '(';
42 i++; 42 i++;
43 if (name.length > 0) { 43 if (name.length > 0) {
44 if (mapping == null) { 44 if (mapping == null) {
45 mapping = {}; 45 mapping = {};
46 } 46 }
47 mapping[name] = capturingBracketNumber; 47 mapping[name] = capturingBracketNumber;
48 } 48 }
49 break; 49 break;
50 } else { 50 } else {
51 name += subChar; 51 name += subChar;
52 } 52 }
53 i++; 53 i++;
54 } 54 }
55 } else { 55 } else {
56 cleanedRegex += _char; 56 cleanedRegex += _char;
57 capturingBracketNumber++; 57 capturingBracketNumber++;
58 } 58 }
59 } else { 59 } else {
60 cleanedRegex += _char; 60 cleanedRegex += _char;
61 } 61 }
62 } else { 62 } else {
63 cleanedRegex += _char; 63 cleanedRegex += _char;
64 } 64 }
65 i++; 65 i++;
66 } 66 }
67 this.rawRegex = rawRegex; 67 this.rawRegex = rawRegex;
68 this.cleanedRegex = cleanedRegex; 68 this.cleanedRegex = cleanedRegex;
69 this.regex = new RegExp(this.cleanedRegex, 'g' + modifiers.replace('g', '')); 69 this.regex = new RegExp(this.cleanedRegex, 'g' + modifiers.replace('g', ''));
70 this.mapping = mapping; 70 this.mapping = mapping;
71 } 71 }
72   72  
73 Pattern.prototype.exec = function(str) { 73 Pattern.prototype.exec = function(str) {
74 var index, matches, name, ref; 74 var index, matches, name, ref;
75 this.regex.lastIndex = 0; 75 this.regex.lastIndex = 0;
76 matches = this.regex.exec(str); 76 matches = this.regex.exec(str);
77 if (matches == null) { 77 if (matches == null) {
78 return null; 78 return null;
79 } 79 }
80 if (this.mapping != null) { 80 if (this.mapping != null) {
81 ref = this.mapping; 81 ref = this.mapping;
82 for (name in ref) { 82 for (name in ref) {
83 index = ref[name]; 83 index = ref[name];
84 matches[name] = matches[index]; 84 matches[name] = matches[index];
85 } 85 }
86 } 86 }
87 return matches; 87 return matches;
88 }; 88 };
89   89  
90 Pattern.prototype.test = function(str) { 90 Pattern.prototype.test = function(str) {
91 this.regex.lastIndex = 0; 91 this.regex.lastIndex = 0;
92 return this.regex.test(str); 92 return this.regex.test(str);
93 }; 93 };
94   94  
95 Pattern.prototype.replace = function(str, replacement) { 95 Pattern.prototype.replace = function(str, replacement) {
96 this.regex.lastIndex = 0; 96 this.regex.lastIndex = 0;
97 return str.replace(this.regex, replacement); 97 return str.replace(this.regex, replacement);
98 }; 98 };
99   99  
100 Pattern.prototype.replaceAll = function(str, replacement, limit) { 100 Pattern.prototype.replaceAll = function(str, replacement, limit) {
101 var count; 101 var count;
102 if (limit == null) { 102 if (limit == null) {
103 limit = 0; 103 limit = 0;
104 } 104 }
105 this.regex.lastIndex = 0; 105 this.regex.lastIndex = 0;
106 count = 0; 106 count = 0;
107 while (this.regex.test(str) && (limit === 0 || count < limit)) { 107 while (this.regex.test(str) && (limit === 0 || count < limit)) {
108 this.regex.lastIndex = 0; 108 this.regex.lastIndex = 0;
109 str = str.replace(this.regex, ''); 109 str = str.replace(this.regex, replacement);
110 count++; 110 count++;
111 } 111 }
112 return [str, count]; 112 return [str, count];
113 }; 113 };
114   114  
115 return Pattern; 115 return Pattern;
116   116  
117 })(); 117 })();
118   118  
119 module.exports = Pattern; 119 module.exports = Pattern;
120   120