re2js 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs.js +5763 -2
- package/build/index.cjs.js.map +1 -1
- package/build/index.esm.d.ts +360 -0
- package/build/index.esm.d.ts.map +1 -0
- package/build/index.esm.js +5756 -2
- package/build/index.esm.js.map +1 -1
- package/build/index.umd.js +5769 -2
- package/build/index.umd.js.map +1 -1
- package/package.json +6 -5
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A compiled representation of an RE2 regular expression
|
|
3
|
+
*
|
|
4
|
+
* <p>
|
|
5
|
+
* The matching functions take {@code String} arguments instead of the more general Java
|
|
6
|
+
* {@code CharSequence} since the latter doesn't provide UTF-16 decoding.
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* @author rsc@google.com (Russ Cox)
|
|
10
|
+
* @class
|
|
11
|
+
*/
|
|
12
|
+
export class RE2JS {
|
|
13
|
+
/**
|
|
14
|
+
* Flag: case insensitive matching.
|
|
15
|
+
*/
|
|
16
|
+
static CASE_INSENSITIVE: number;
|
|
17
|
+
/**
|
|
18
|
+
* Flag: dot ({@code .}) matches all characters, including newline.
|
|
19
|
+
*/
|
|
20
|
+
static DOTALL: number;
|
|
21
|
+
/**
|
|
22
|
+
* Flag: multiline matching: {@code ^} and {@code $} match at beginning and end of line, not just
|
|
23
|
+
* beginning and end of input.
|
|
24
|
+
*/
|
|
25
|
+
static MULTILINE: number;
|
|
26
|
+
/**
|
|
27
|
+
* Flag: Unicode groups (e.g. {@code \p\ Greek\} ) will be syntax errors.
|
|
28
|
+
*/
|
|
29
|
+
static DISABLE_UNICODE_GROUPS: number;
|
|
30
|
+
/**
|
|
31
|
+
* Flag: matches longest possible string.
|
|
32
|
+
*/
|
|
33
|
+
static LONGEST_MATCH: number;
|
|
34
|
+
/**
|
|
35
|
+
* Returns a literal pattern string for the specified string.
|
|
36
|
+
*
|
|
37
|
+
* <p>
|
|
38
|
+
* This method produces a string that can be used to create a <code>RE2JS</code> that would
|
|
39
|
+
* match the string <code>s</code> as if it were a literal pattern.
|
|
40
|
+
* </p>
|
|
41
|
+
* Metacharacters or escape sequences in the input sequence will be given no special meaning.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} str The string to be literalized
|
|
44
|
+
* @returns {string} A literal string replacement
|
|
45
|
+
*/
|
|
46
|
+
static quote(str: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Helper: create new RE2JS with given regex and flags. Flregex is the regex with flags applied.
|
|
49
|
+
* @param {string} regex
|
|
50
|
+
* @param {number} flags
|
|
51
|
+
* @returns {RE2JS}
|
|
52
|
+
*/
|
|
53
|
+
static compile(regex: string, ...args: any[]): RE2JS;
|
|
54
|
+
/**
|
|
55
|
+
* Matches a string against a regular expression.
|
|
56
|
+
*
|
|
57
|
+
* @param {string} regex the regular expression
|
|
58
|
+
* @param {*} input the input
|
|
59
|
+
* @returns {boolean} true if the regular expression matches the entire input
|
|
60
|
+
* @throws RE2JSSyntaxException if the regular expression is malformed
|
|
61
|
+
*/
|
|
62
|
+
static matches(regex: string, input: any): boolean;
|
|
63
|
+
static initTest(pattern: any, flags: any, re2: any): RE2JS;
|
|
64
|
+
constructor(pattern: any, flags: any);
|
|
65
|
+
patternInput: any;
|
|
66
|
+
flagsInput: any;
|
|
67
|
+
/**
|
|
68
|
+
* Releases memory used by internal caches associated with this pattern. Does not change the
|
|
69
|
+
* observable behaviour. Useful for tests that detect memory leaks via allocation tracking.
|
|
70
|
+
*/
|
|
71
|
+
reset(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the flags used in the constructor.
|
|
74
|
+
* @returns {number}
|
|
75
|
+
*/
|
|
76
|
+
flags(): number;
|
|
77
|
+
/**
|
|
78
|
+
* Returns the pattern used in the constructor.
|
|
79
|
+
* @returns {string}
|
|
80
|
+
*/
|
|
81
|
+
pattern(): string;
|
|
82
|
+
re2(): any;
|
|
83
|
+
/**
|
|
84
|
+
* Matches a string against a regular expression.
|
|
85
|
+
*
|
|
86
|
+
* @param {*} input the input
|
|
87
|
+
* @returns {boolean} true if the regular expression matches the entire input
|
|
88
|
+
*/
|
|
89
|
+
matches(input: any): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a new {@code Matcher} matching the pattern against the input.
|
|
92
|
+
*
|
|
93
|
+
* @param {*} input the input string
|
|
94
|
+
* @returns {Matcher}
|
|
95
|
+
*/
|
|
96
|
+
matcher(input: any): Matcher;
|
|
97
|
+
/**
|
|
98
|
+
* Splits input around instances of the regular expression. It returns an array giving the strings
|
|
99
|
+
* that occur before, between, and after instances of the regular expression.
|
|
100
|
+
*
|
|
101
|
+
* <p>
|
|
102
|
+
* If {@code limit <= 0}, there is no limit on the size of the returned array. If
|
|
103
|
+
* {@code limit == 0}, empty strings that would occur at the end of the array are omitted. If
|
|
104
|
+
* {@code limit > 0}, at most limit strings are returned. The final string contains the remainder
|
|
105
|
+
* of the input, possibly including additional matches of the pattern.
|
|
106
|
+
*
|
|
107
|
+
* @param {string} input the input string to be split
|
|
108
|
+
* @param {number} limit the limit
|
|
109
|
+
* @returns {java.lang.String[]} the split strings
|
|
110
|
+
*/
|
|
111
|
+
split(input: string, ...args: any[]): java.lang.String[];
|
|
112
|
+
toString(): any;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the number of capturing groups in this matcher's pattern. Group zero denotes the entire
|
|
115
|
+
* pattern and is excluded from this count.
|
|
116
|
+
*
|
|
117
|
+
* @returns {number} the number of capturing groups in this pattern
|
|
118
|
+
*/
|
|
119
|
+
groupCount(): number;
|
|
120
|
+
/**
|
|
121
|
+
* Return a map of the capturing groups in this matcher's pattern, where key is the name and value
|
|
122
|
+
* is the index of the group in the pattern.
|
|
123
|
+
* @returns {*}
|
|
124
|
+
*/
|
|
125
|
+
namedGroups(): any;
|
|
126
|
+
equals(other: any): boolean;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* An exception thrown by the compiler
|
|
130
|
+
*/
|
|
131
|
+
export class RE2JSCompileException extends RE2JSException {
|
|
132
|
+
}
|
|
133
|
+
export class RE2JSException extends Error {
|
|
134
|
+
constructor(message: any);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* An exception thrown by flags
|
|
138
|
+
*/
|
|
139
|
+
export class RE2JSFlagsException extends RE2JSException {
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* An exception thrown by using groups
|
|
143
|
+
*/
|
|
144
|
+
export class RE2JSGroupException extends RE2JSException {
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* An exception thrown by the parser if the pattern was invalid.
|
|
148
|
+
*/
|
|
149
|
+
export class RE2JSSyntaxException extends RE2JSException {
|
|
150
|
+
constructor(error: any, ...args: any[]);
|
|
151
|
+
error: any;
|
|
152
|
+
input: any;
|
|
153
|
+
/**
|
|
154
|
+
* Retrieves the description of the error.
|
|
155
|
+
*/
|
|
156
|
+
getDescription(): any;
|
|
157
|
+
/**
|
|
158
|
+
* Retrieves the erroneous regular-expression pattern.
|
|
159
|
+
*/
|
|
160
|
+
getPattern(): any;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* A stateful iterator that interprets a regex {@code RE2JS} on a specific input.
|
|
164
|
+
*
|
|
165
|
+
* <p>
|
|
166
|
+
* Conceptually, a Matcher consists of four parts:
|
|
167
|
+
* <ol>
|
|
168
|
+
* <li>A compiled regular expression {@code RE2JS}, set at construction and fixed for the lifetime
|
|
169
|
+
* of the matcher.</li>
|
|
170
|
+
*
|
|
171
|
+
* <li>The remainder of the input string, set at construction or {@link #reset()} and advanced by
|
|
172
|
+
* each match operation such as {@link #find}, {@link #matches} or {@link #lookingAt}.</li>
|
|
173
|
+
*
|
|
174
|
+
* <li>The current match information, accessible via {@link #start}, {@link #end}, and
|
|
175
|
+
* {@link #group}, and updated by each match operation.</li>
|
|
176
|
+
*
|
|
177
|
+
* <li>The append position, used and advanced by {@link #appendReplacement} and {@link #appendTail}
|
|
178
|
+
* if performing a search and replace from the input to an external {@code StringBuffer}.
|
|
179
|
+
*
|
|
180
|
+
* </ol>
|
|
181
|
+
*
|
|
182
|
+
*
|
|
183
|
+
* @author rsc@google.com (Russ Cox)
|
|
184
|
+
*/
|
|
185
|
+
declare class Matcher {
|
|
186
|
+
/**
|
|
187
|
+
* Quotes '\' and '$' in {@code s}, so that the returned string could be used in
|
|
188
|
+
* {@link #appendReplacement} as a literal replacement of {@code s}.
|
|
189
|
+
*
|
|
190
|
+
* @param {string} s the string to be quoted
|
|
191
|
+
* @returns {string} the quoted string
|
|
192
|
+
*/
|
|
193
|
+
static quoteReplacement(str: any): string;
|
|
194
|
+
constructor(pattern: any, input: any);
|
|
195
|
+
patternInput: any;
|
|
196
|
+
patternGroupCount: any;
|
|
197
|
+
groups: any[];
|
|
198
|
+
namedGroups: any;
|
|
199
|
+
/** Returns the {@code RE2JS} associated with this {@code Matcher}. */
|
|
200
|
+
pattern(): any;
|
|
201
|
+
/**
|
|
202
|
+
* Resets the {@code Matcher}, rewinding input and discarding any match information.
|
|
203
|
+
*
|
|
204
|
+
* @returns the {@code Matcher} itself, for chained method calls
|
|
205
|
+
*/
|
|
206
|
+
reset(): this;
|
|
207
|
+
matcherInputLength: any;
|
|
208
|
+
appendPos: any;
|
|
209
|
+
hasMatch: boolean;
|
|
210
|
+
hasGroups: boolean;
|
|
211
|
+
anchorFlag: number;
|
|
212
|
+
/**
|
|
213
|
+
* Resets the {@code Matcher} and changes the input.
|
|
214
|
+
* @returns the {@code Matcher} itself, for chained method calls
|
|
215
|
+
*/
|
|
216
|
+
resetMatcherInput(input: any): this;
|
|
217
|
+
matcherInput: any;
|
|
218
|
+
/**
|
|
219
|
+
* Returns the start of the named group of the most recent match, or -1 if the group was not
|
|
220
|
+
* matched.
|
|
221
|
+
*
|
|
222
|
+
*/
|
|
223
|
+
start(...args: any[]): any;
|
|
224
|
+
/**
|
|
225
|
+
* Returns the end of the named group of the most recent match, or -1 if the group was not
|
|
226
|
+
* matched.
|
|
227
|
+
*
|
|
228
|
+
*/
|
|
229
|
+
end(...args: any[]): any;
|
|
230
|
+
/**
|
|
231
|
+
* Returns the named group of the most recent match, or {@code null} if the group was not matched.
|
|
232
|
+
*
|
|
233
|
+
*/
|
|
234
|
+
group(...args: any[]): string;
|
|
235
|
+
/**
|
|
236
|
+
* Returns the number of subgroups in this pattern.
|
|
237
|
+
*
|
|
238
|
+
* @returns {number} the number of subgroups; the overall match (group 0) does not count
|
|
239
|
+
*/
|
|
240
|
+
groupCount(): number;
|
|
241
|
+
/**
|
|
242
|
+
* Helper: finds subgroup information if needed for group.
|
|
243
|
+
* @param {number} group
|
|
244
|
+
* @private
|
|
245
|
+
*/
|
|
246
|
+
private loadGroup;
|
|
247
|
+
/**
|
|
248
|
+
* Matches the entire input against the pattern (anchored start and end). If there is a match,
|
|
249
|
+
* {@code matches} sets the match state to describe it.
|
|
250
|
+
*
|
|
251
|
+
* @returns {boolean} true if the entire input matches the pattern
|
|
252
|
+
*/
|
|
253
|
+
matches(): boolean;
|
|
254
|
+
/**
|
|
255
|
+
* Matches the beginning of input against the pattern (anchored start). If there is a match,
|
|
256
|
+
* {@code lookingAt} sets the match state to describe it.
|
|
257
|
+
*
|
|
258
|
+
* @returns {boolean} true if the beginning of the input matches the pattern
|
|
259
|
+
*/
|
|
260
|
+
lookingAt(): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Matches the input against the pattern (unanchored), starting at a specified position. If there
|
|
263
|
+
* is a match, {@code find} sets the match state to describe it.
|
|
264
|
+
*
|
|
265
|
+
* @param start the input position where the search begins
|
|
266
|
+
* @returns {boolean} if it finds a match
|
|
267
|
+
* @throws IndexOutOfBoundsException if start is not a valid input position
|
|
268
|
+
*/
|
|
269
|
+
find(...args: any[]): boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Helper: does match starting at start, with RE2 anchor flag.
|
|
272
|
+
* @param {number} startByte
|
|
273
|
+
* @param {number} anchor
|
|
274
|
+
* @returns {boolean}
|
|
275
|
+
* @private
|
|
276
|
+
*/
|
|
277
|
+
private genMatch;
|
|
278
|
+
/**
|
|
279
|
+
* Helper: return substring for [start, end).
|
|
280
|
+
* @param {number} start
|
|
281
|
+
* @param {number} end
|
|
282
|
+
* @returns {string}
|
|
283
|
+
*/
|
|
284
|
+
substring(start: number, end: number): string;
|
|
285
|
+
/**
|
|
286
|
+
* Helper for Pattern: return input length.
|
|
287
|
+
* @returns {number}
|
|
288
|
+
*/
|
|
289
|
+
inputLength(): number;
|
|
290
|
+
/**
|
|
291
|
+
* Appends to result two strings: the text from the append position up to the beginning of the
|
|
292
|
+
* most recent match, and then the replacement with submatch groups substituted for references of
|
|
293
|
+
* the form {@code $n}, where {@code n} is the group number in decimal. It advances the append
|
|
294
|
+
* position to where the most recent match ended.
|
|
295
|
+
*
|
|
296
|
+
* <p>
|
|
297
|
+
* To embed a literal {@code $}, use \$ (actually {@code "\\$"} with string escapes). The escape
|
|
298
|
+
* is only necessary when {@code $} is followed by a digit, but it is always allowed. Only
|
|
299
|
+
* {@code $} and {@code \} need escaping, but any character can be escaped.
|
|
300
|
+
*
|
|
301
|
+
* <p>
|
|
302
|
+
* The group number {@code n} in {@code $n} is always at least one digit and expands to use more
|
|
303
|
+
* digits as long as the resulting number is a valid group number for this pattern. To cut it off
|
|
304
|
+
* earlier, escape the first digit that should not be used.
|
|
305
|
+
*
|
|
306
|
+
* @param {string} replacement the replacement string
|
|
307
|
+
* @param {boolean} [perlMode=false] activate perl/js mode (different behaviour for capture groups and special characters)
|
|
308
|
+
* @returns the {@code Matcher} itself, for chained method calls
|
|
309
|
+
* @throws IllegalStateException if there was no most recent match
|
|
310
|
+
* @throws IndexOutOfBoundsException if replacement refers to an invalid group
|
|
311
|
+
*/
|
|
312
|
+
appendReplacement(replacement: string, ...args: any[]): string;
|
|
313
|
+
/**
|
|
314
|
+
* @param {string} replacement - the replacement string
|
|
315
|
+
* @returns {string}
|
|
316
|
+
*/
|
|
317
|
+
appendReplacementInternal(replacement: string): string;
|
|
318
|
+
/**
|
|
319
|
+
* @param {string} replacement - the replacement string
|
|
320
|
+
* @returns {string}
|
|
321
|
+
*/
|
|
322
|
+
appendReplacementInternalPerl(replacement: string): string;
|
|
323
|
+
/**
|
|
324
|
+
* Return the substring of the input from the append position to the end of the
|
|
325
|
+
* input.
|
|
326
|
+
* @returns {string}
|
|
327
|
+
*/
|
|
328
|
+
appendTail(): string;
|
|
329
|
+
/**
|
|
330
|
+
* Returns the input with all matches replaced by {@code replacement}, interpreted as for
|
|
331
|
+
* {@code appendReplacement}.
|
|
332
|
+
*
|
|
333
|
+
* @param {string} replacement - the replacement string
|
|
334
|
+
* @param {boolean} [perlMode=false] - activate perl/js mode (different behaviour for capture groups and special characters)
|
|
335
|
+
* @returns {string} the input string with the matches replaced
|
|
336
|
+
* @throws IndexOutOfBoundsException if replacement refers to an invalid group and perlMode is false
|
|
337
|
+
*/
|
|
338
|
+
replaceAll(replacement: string, ...args: any[]): string;
|
|
339
|
+
/**
|
|
340
|
+
* Returns the input with the first match replaced by {@code replacement}, interpreted as for
|
|
341
|
+
* {@code appendReplacement}.
|
|
342
|
+
*
|
|
343
|
+
* @param {string} replacement - the replacement string
|
|
344
|
+
* @param {boolean} [perlMode=false] - activate perl/js mode (different behaviour for capture groups and special characters)
|
|
345
|
+
* @returns {string} the input string with the first match replaced
|
|
346
|
+
* @throws IndexOutOfBoundsException if replacement refers to an invalid group and perlMode is false
|
|
347
|
+
*/
|
|
348
|
+
replaceFirst(replacement: string, ...args: any[]): string;
|
|
349
|
+
/**
|
|
350
|
+
* Helper: replaceAll/replaceFirst hybrid.
|
|
351
|
+
* @param {string} replacement - the replacement string
|
|
352
|
+
* @param {boolean} [all=true] - replace all matches
|
|
353
|
+
* @param {boolean} [perlMode=false] - activate perl/js mode (different behaviour for capture groups and special characters)
|
|
354
|
+
* @returns {string}
|
|
355
|
+
* @private
|
|
356
|
+
*/
|
|
357
|
+
private replace;
|
|
358
|
+
}
|
|
359
|
+
export {};
|
|
360
|
+
//# sourceMappingURL=index.esm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.d.ts","sourceRoot":"","sources":["index.esm.js"],"names":[],"mappings":"AAk4KA;;;;;;;;;;GAUG;AACH;IACE;;OAEG;IACH,gCAA4B;IAC5B;;OAEG;IACH,sBAAkB;IAClB;;;OAGG;IACH,yBAAqB;IACrB;;OAEG;IACH,sCAAkC;IAClC;;OAEG;IACH,6BAA0B;IAE1B;;;;;;;;;;;OAWG;IACH,kBAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;OAKG;IACH,sBAJW,MAAM,mBAEJ,KAAK,CAyBjB;IAED;;;;;;;OAOG;IACH,sBALW,MAAM,eAEJ,OAAO,CAKnB;IAGD,2DAWC;IACD,sCAKC;IAHC,kBAA2B;IAE3B,gBAAuB;IAGzB;;;OAGG;IACH,cAEC;IAED;;;OAGG;IACH,SAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,WAFa,MAAM,CAIlB;IACD,WAEC;IAED;;;;;OAKG;IACH,qBAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,qBAFa,OAAO,CAOnB;IAED;;;;;;;;;;;;;OAaG;IACH,aAJW,MAAM,mBAEJ,kBAAkB,CAiD9B;IACD,gBAEC;IAED;;;;;OAKG;IACH,cAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,mBAEC;IACD,4BAQC;CACF;AAj2JD;;GAEG;AACH;CAKC;AA/CD;IACE,0BAGC;CACF;AAsDD;;GAEG;AACH;CAKC;AAlBD;;GAEG;AACH;CAKC;AAlDD;;GAEG;AACH;IACE,wCAWC;IAFC,WAAkB;IAClB,WAAkB;IAGpB;;OAEG;IACH,sBAEC;IAED;;OAEG;IACH,kBAEC;CACF;AAgCD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;IACE;;;;;;OAMG;IACH,mCAFa,MAAM,CAalB;IACD,sCAmBC;IAdC,kBAA2B;IAG3B,uBAAsD;IAEtD,cAAgB;IAChB,iBAAkC;IAUpC,sEAAsE;IACtE,eAEC;IAED;;;;OAIG;IACH,cAaC;IAXC,wBAAoD;IAEpD,eAAkB;IAElB,kBAAqB;IAGrB,mBAAsB;IAEtB,mBAAmB;IAIrB;;;OAGG;IACH,oCAOC;IAHC,kBAAyB;IAK3B;;;;OAIG;IACH,2BAWC;IAED;;;;OAIG;IACH,yBAWC;IAED;;;OAGG;IACH,8BAeC;IACD;;;;OAIG;IACH,cAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,kBAqBC;IAED;;;;;OAKG;IACH,WAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,aAFa,OAAO,CAInB;IAED;;;;;;;OAOG;IACH,sBAHa,OAAO,CAqBnB;IAED;;;;;;OAMG;IACH,iBAWC;IAED;;;;;OAKG;IACH,iBAJW,MAAM,OACN,MAAM,GACJ,MAAM,CAOlB;IAED;;;OAGG;IACH,eAFa,MAAM,CAIlB;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,+BANW,MAAM,0BAiBhB;IAED;;;OAGG;IACH,uCAHW,MAAM,GACJ,MAAM,CA6DlB;IAED;;;OAGG;IACH,2CAHW,MAAM,GACJ,MAAM,CAmFlB;IAED;;;;OAIG;IACH,cAFa,MAAM,CAIlB;IAED;;;;;;;;OAQG;IACH,wBALW,MAAM,mBAEJ,MAAM,CAMlB;IAED;;;;;;;;OAQG;IACH,0BALW,MAAM,mBAEJ,MAAM,CAMlB;IAED;;;;;;;OAOG;IACH,gBAaC;CACF"}
|