re2js 0.3.0 → 0.3.2
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 → index.cjs.cjs} +95 -18
- package/build/index.cjs.cjs.map +1 -0
- package/build/index.esm.d.ts +125 -36
- package/build/index.esm.d.ts.map +1 -1
- package/build/index.esm.js +94 -17
- package/build/index.esm.js.map +1 -1
- package/build/index.umd.js +94 -17
- package/build/index.umd.js.map +1 -1
- package/package.json +3 -3
- package/build/index.cjs.js.map +0 -1
package/build/index.esm.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export class RE2JS {
|
|
|
47
47
|
/**
|
|
48
48
|
* Helper: create new RE2JS with given regex and flags. Flregex is the regex with flags applied.
|
|
49
49
|
* @param {string} regex
|
|
50
|
-
* @param {number} flags
|
|
50
|
+
* @param {number} [flags=0]
|
|
51
51
|
* @returns {RE2JS}
|
|
52
52
|
*/
|
|
53
53
|
static compile(regex: string, ...args: any[]): RE2JS;
|
|
@@ -55,15 +55,24 @@ export class RE2JS {
|
|
|
55
55
|
* Matches a string against a regular expression.
|
|
56
56
|
*
|
|
57
57
|
* @param {string} regex the regular expression
|
|
58
|
-
* @param {
|
|
58
|
+
* @param {string|number[]} input the input
|
|
59
59
|
* @returns {boolean} true if the regular expression matches the entire input
|
|
60
60
|
* @throws RE2JSSyntaxException if the regular expression is malformed
|
|
61
61
|
*/
|
|
62
|
-
static matches(regex: string, input:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
static matches(regex: string, input: string | number[]): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* This is visible for testing.
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
private static initTest;
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* @param {string} pattern
|
|
71
|
+
* @param {number} flags
|
|
72
|
+
*/
|
|
73
|
+
constructor(pattern: string, flags: number);
|
|
74
|
+
patternInput: string;
|
|
75
|
+
flagsInput: number;
|
|
67
76
|
/**
|
|
68
77
|
* Releases memory used by internal caches associated with this pattern. Does not change the
|
|
69
78
|
* observable behaviour. Useful for tests that detect memory leaks via allocation tracking.
|
|
@@ -83,17 +92,17 @@ export class RE2JS {
|
|
|
83
92
|
/**
|
|
84
93
|
* Matches a string against a regular expression.
|
|
85
94
|
*
|
|
86
|
-
* @param {
|
|
95
|
+
* @param {string|number[]} input the input
|
|
87
96
|
* @returns {boolean} true if the regular expression matches the entire input
|
|
88
97
|
*/
|
|
89
|
-
matches(input:
|
|
98
|
+
matches(input: string | number[]): boolean;
|
|
90
99
|
/**
|
|
91
100
|
* Creates a new {@code Matcher} matching the pattern against the input.
|
|
92
101
|
*
|
|
93
|
-
* @param {
|
|
102
|
+
* @param {string|number[]} input the input string
|
|
94
103
|
* @returns {Matcher}
|
|
95
104
|
*/
|
|
96
|
-
matcher(input:
|
|
105
|
+
matcher(input: string | number[]): Matcher;
|
|
97
106
|
/**
|
|
98
107
|
* Splits input around instances of the regular expression. It returns an array giving the strings
|
|
99
108
|
* that occur before, between, and after instances of the regular expression.
|
|
@@ -105,11 +114,15 @@ export class RE2JS {
|
|
|
105
114
|
* of the input, possibly including additional matches of the pattern.
|
|
106
115
|
*
|
|
107
116
|
* @param {string} input the input string to be split
|
|
108
|
-
* @param {number} limit the limit
|
|
109
|
-
* @returns {
|
|
117
|
+
* @param {number} [limit=0] the limit
|
|
118
|
+
* @returns {string[]} the split strings
|
|
110
119
|
*/
|
|
111
|
-
split(input: string, ...args: any[]):
|
|
112
|
-
|
|
120
|
+
split(input: string, ...args: any[]): string[];
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
* @returns {string}
|
|
124
|
+
*/
|
|
125
|
+
toString(): string;
|
|
113
126
|
/**
|
|
114
127
|
* Returns the number of capturing groups in this matcher's pattern. Group zero denotes the entire
|
|
115
128
|
* pattern and is excluded from this count.
|
|
@@ -123,6 +136,11 @@ export class RE2JS {
|
|
|
123
136
|
* @returns {*}
|
|
124
137
|
*/
|
|
125
138
|
namedGroups(): any;
|
|
139
|
+
/**
|
|
140
|
+
*
|
|
141
|
+
* @param {*} other
|
|
142
|
+
* @returns {boolean}
|
|
143
|
+
*/
|
|
126
144
|
equals(other: any): boolean;
|
|
127
145
|
}
|
|
128
146
|
/**
|
|
@@ -187,49 +205,60 @@ declare class Matcher {
|
|
|
187
205
|
* Quotes '\' and '$' in {@code s}, so that the returned string could be used in
|
|
188
206
|
* {@link #appendReplacement} as a literal replacement of {@code s}.
|
|
189
207
|
*
|
|
190
|
-
* @param {string}
|
|
208
|
+
* @param {string} str the string to be quoted
|
|
191
209
|
* @returns {string} the quoted string
|
|
192
210
|
*/
|
|
193
|
-
static quoteReplacement(str:
|
|
194
|
-
|
|
195
|
-
|
|
211
|
+
static quoteReplacement(str: string): string;
|
|
212
|
+
/**
|
|
213
|
+
*
|
|
214
|
+
* @param {RE2JS} pattern
|
|
215
|
+
* @param {Utf8MatcherInput|Utf16MatcherInput|number[]|string} input
|
|
216
|
+
*/
|
|
217
|
+
constructor(pattern: RE2JS, input: Utf8MatcherInput | Utf16MatcherInput | number[] | string);
|
|
218
|
+
patternInput: RE2JS;
|
|
196
219
|
patternGroupCount: any;
|
|
197
220
|
groups: any[];
|
|
198
221
|
namedGroups: any;
|
|
199
|
-
/**
|
|
200
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Returns the {@code RE2JS} associated with this {@code Matcher}.
|
|
224
|
+
* @returns {RE2JS}
|
|
225
|
+
*/
|
|
226
|
+
pattern(): RE2JS;
|
|
201
227
|
/**
|
|
202
228
|
* Resets the {@code Matcher}, rewinding input and discarding any match information.
|
|
203
229
|
*
|
|
204
|
-
* @returns the {@code Matcher} itself, for chained method calls
|
|
230
|
+
* @returns {Matcher} the {@code Matcher} itself, for chained method calls
|
|
205
231
|
*/
|
|
206
|
-
reset():
|
|
232
|
+
reset(): Matcher;
|
|
207
233
|
matcherInputLength: any;
|
|
208
|
-
appendPos:
|
|
234
|
+
appendPos: string | number;
|
|
209
235
|
hasMatch: boolean;
|
|
210
236
|
hasGroups: boolean;
|
|
211
237
|
anchorFlag: number;
|
|
212
238
|
/**
|
|
213
239
|
* Resets the {@code Matcher} and changes the input.
|
|
214
|
-
* @returns the {@code Matcher} itself, for chained method calls
|
|
240
|
+
* @returns {Matcher} the {@code Matcher} itself, for chained method calls
|
|
215
241
|
*/
|
|
216
|
-
resetMatcherInput(input: any):
|
|
242
|
+
resetMatcherInput(input: any): Matcher;
|
|
217
243
|
matcherInput: any;
|
|
218
244
|
/**
|
|
219
245
|
* Returns the start of the named group of the most recent match, or -1 if the group was not
|
|
220
246
|
* matched.
|
|
221
|
-
*
|
|
247
|
+
* @param {string|number} [group=0]
|
|
248
|
+
* @returns {string}
|
|
222
249
|
*/
|
|
223
|
-
start(...args: any[]):
|
|
250
|
+
start(...args: any[]): string;
|
|
224
251
|
/**
|
|
225
252
|
* Returns the end of the named group of the most recent match, or -1 if the group was not
|
|
226
253
|
* matched.
|
|
227
|
-
*
|
|
254
|
+
* @param {string|number} [group=0]
|
|
255
|
+
* @returns {string}
|
|
228
256
|
*/
|
|
229
|
-
end(...args: any[]):
|
|
257
|
+
end(...args: any[]): string;
|
|
230
258
|
/**
|
|
231
259
|
* Returns the named group of the most recent match, or {@code null} if the group was not matched.
|
|
232
|
-
*
|
|
260
|
+
* @param {string|number} [group=0]
|
|
261
|
+
* @returns {string}
|
|
233
262
|
*/
|
|
234
263
|
group(...args: any[]): string;
|
|
235
264
|
/**
|
|
@@ -262,7 +291,7 @@ declare class Matcher {
|
|
|
262
291
|
* Matches the input against the pattern (unanchored), starting at a specified position. If there
|
|
263
292
|
* is a match, {@code find} sets the match state to describe it.
|
|
264
293
|
*
|
|
265
|
-
* @param start the input position where the search begins
|
|
294
|
+
* @param {string|number} [start=null] the input position where the search begins
|
|
266
295
|
* @returns {boolean} if it finds a match
|
|
267
296
|
* @throws IndexOutOfBoundsException if start is not a valid input position
|
|
268
297
|
*/
|
|
@@ -305,21 +334,24 @@ declare class Matcher {
|
|
|
305
334
|
*
|
|
306
335
|
* @param {string} replacement the replacement string
|
|
307
336
|
* @param {boolean} [perlMode=false] activate perl/js mode (different behaviour for capture groups and special characters)
|
|
308
|
-
* @returns
|
|
337
|
+
* @returns {string}
|
|
309
338
|
* @throws IllegalStateException if there was no most recent match
|
|
310
339
|
* @throws IndexOutOfBoundsException if replacement refers to an invalid group
|
|
340
|
+
* @private
|
|
311
341
|
*/
|
|
312
|
-
appendReplacement
|
|
342
|
+
private appendReplacement;
|
|
313
343
|
/**
|
|
314
344
|
* @param {string} replacement - the replacement string
|
|
315
345
|
* @returns {string}
|
|
346
|
+
* @private
|
|
316
347
|
*/
|
|
317
|
-
appendReplacementInternal
|
|
348
|
+
private appendReplacementInternal;
|
|
318
349
|
/**
|
|
319
350
|
* @param {string} replacement - the replacement string
|
|
320
351
|
* @returns {string}
|
|
352
|
+
* @private
|
|
321
353
|
*/
|
|
322
|
-
appendReplacementInternalPerl
|
|
354
|
+
private appendReplacementInternalPerl;
|
|
323
355
|
/**
|
|
324
356
|
* Return the substring of the input from the append position to the end of the
|
|
325
357
|
* input.
|
|
@@ -356,5 +388,62 @@ declare class Matcher {
|
|
|
356
388
|
*/
|
|
357
389
|
private replace;
|
|
358
390
|
}
|
|
391
|
+
declare class Utf8MatcherInput extends MatcherInputBase {
|
|
392
|
+
constructor(...args: any[]);
|
|
393
|
+
bytes: any;
|
|
394
|
+
getEncoding(): any;
|
|
395
|
+
/**
|
|
396
|
+
*
|
|
397
|
+
* @returns {string}
|
|
398
|
+
*/
|
|
399
|
+
asCharSequence(): string;
|
|
400
|
+
/**
|
|
401
|
+
*
|
|
402
|
+
* @returns {number[]}
|
|
403
|
+
*/
|
|
404
|
+
asBytes(): number[];
|
|
405
|
+
/**
|
|
406
|
+
*
|
|
407
|
+
* @returns {number}
|
|
408
|
+
*/
|
|
409
|
+
length(): number;
|
|
410
|
+
}
|
|
411
|
+
declare class Utf16MatcherInput extends MatcherInputBase {
|
|
412
|
+
constructor(...args: any[]);
|
|
413
|
+
charSequence: any;
|
|
414
|
+
getEncoding(): any;
|
|
415
|
+
/**
|
|
416
|
+
*
|
|
417
|
+
* @returns {string}
|
|
418
|
+
*/
|
|
419
|
+
asCharSequence(): string;
|
|
420
|
+
/**
|
|
421
|
+
*
|
|
422
|
+
* @returns {number[]}
|
|
423
|
+
*/
|
|
424
|
+
asBytes(): number[];
|
|
425
|
+
/**
|
|
426
|
+
*
|
|
427
|
+
* @returns {number}
|
|
428
|
+
*/
|
|
429
|
+
length(): number;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Abstract the representations of input text supplied to Matcher.
|
|
433
|
+
*/
|
|
434
|
+
declare class MatcherInputBase {
|
|
435
|
+
static Encoding: Readonly<{}>;
|
|
436
|
+
getEncoding(): void;
|
|
437
|
+
/**
|
|
438
|
+
*
|
|
439
|
+
* @returns {boolean}
|
|
440
|
+
*/
|
|
441
|
+
isUTF8Encoding(): boolean;
|
|
442
|
+
/**
|
|
443
|
+
*
|
|
444
|
+
* @returns {boolean}
|
|
445
|
+
*/
|
|
446
|
+
isUTF16Encoding(): boolean;
|
|
447
|
+
}
|
|
359
448
|
export {};
|
|
360
449
|
//# sourceMappingURL=index.esm.d.ts.map
|
package/build/index.esm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.d.ts","sourceRoot":"","sources":["index.esm.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.esm.d.ts","sourceRoot":"","sources":["index.esm.js"],"names":[],"mappings":"AA27KA;;;;;;;;;;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;IA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;GAEG;AACH;IACE,8BAAkD;IAClD,oBAEC;IAED;;;OAGG;IACH,kBAFa,OAAO,CAInB;IAED;;;OAGG;IACH,mBAFa,OAAO,CAInB;CACF"}
|
package/build/index.esm.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* re2js
|
|
3
3
|
* RE2JS is the JavaScript port of RE2, a regular expression engine that provides linear time matching
|
|
4
4
|
*
|
|
5
|
-
* @version v0.3.
|
|
5
|
+
* @version v0.3.2
|
|
6
6
|
* @author Alexey Vasiliev
|
|
7
7
|
* @homepage https://github.com/le0pard/re2js#readme
|
|
8
8
|
* @repository github:le0pard/re2js
|
|
@@ -696,9 +696,19 @@ class MatcherInputBase {
|
|
|
696
696
|
getEncoding() {
|
|
697
697
|
throw Error('not implemented');
|
|
698
698
|
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
*
|
|
702
|
+
* @returns {boolean}
|
|
703
|
+
*/
|
|
699
704
|
isUTF8Encoding() {
|
|
700
705
|
return this.getEncoding() === MatcherInputBase.Encoding.UTF_8;
|
|
701
706
|
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
*
|
|
710
|
+
* @returns {boolean}
|
|
711
|
+
*/
|
|
702
712
|
isUTF16Encoding() {
|
|
703
713
|
return this.getEncoding() === MatcherInputBase.Encoding.UTF_16;
|
|
704
714
|
}
|
|
@@ -712,12 +722,26 @@ class Utf8MatcherInput extends MatcherInputBase {
|
|
|
712
722
|
getEncoding() {
|
|
713
723
|
return MatcherInputBase.Encoding.UTF_8;
|
|
714
724
|
}
|
|
725
|
+
/**
|
|
726
|
+
*
|
|
727
|
+
* @returns {string}
|
|
728
|
+
*/
|
|
715
729
|
asCharSequence() {
|
|
716
730
|
return Utils.utf8ByteArrayToString(this.bytes);
|
|
717
731
|
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
*
|
|
735
|
+
* @returns {number[]}
|
|
736
|
+
*/
|
|
718
737
|
asBytes() {
|
|
719
738
|
return this.bytes;
|
|
720
739
|
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
*
|
|
743
|
+
* @returns {number}
|
|
744
|
+
*/
|
|
721
745
|
length() {
|
|
722
746
|
return this.bytes.length;
|
|
723
747
|
}
|
|
@@ -731,12 +755,27 @@ class Utf16MatcherInput extends MatcherInputBase {
|
|
|
731
755
|
getEncoding() {
|
|
732
756
|
return MatcherInputBase.Encoding.UTF_16;
|
|
733
757
|
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
*
|
|
761
|
+
* @returns {string}
|
|
762
|
+
*/
|
|
734
763
|
asCharSequence() {
|
|
735
764
|
return this.charSequence;
|
|
736
765
|
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
*
|
|
769
|
+
* @returns {number[]}
|
|
770
|
+
*/
|
|
737
771
|
asBytes() {
|
|
738
772
|
return this.charSequence.toString().split('').map(s => s.codePointAt(0));
|
|
739
773
|
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
*
|
|
777
|
+
* @returns {number}
|
|
778
|
+
*/
|
|
740
779
|
length() {
|
|
741
780
|
return this.charSequence.length;
|
|
742
781
|
}
|
|
@@ -744,6 +783,7 @@ class Utf16MatcherInput extends MatcherInputBase {
|
|
|
744
783
|
class MatcherInput {
|
|
745
784
|
/**
|
|
746
785
|
* Return the MatcherInput for UTF_16 encoding.
|
|
786
|
+
* @returns {Utf16MatcherInput}
|
|
747
787
|
*/
|
|
748
788
|
static utf16(charSequence) {
|
|
749
789
|
return new Utf16MatcherInput(charSequence);
|
|
@@ -751,6 +791,7 @@ class MatcherInput {
|
|
|
751
791
|
|
|
752
792
|
/**
|
|
753
793
|
* Return the MatcherInput for UTF_8 encoding.
|
|
794
|
+
* @returns {Utf8MatcherInput}
|
|
754
795
|
*/
|
|
755
796
|
static utf8(input) {
|
|
756
797
|
if (Array.isArray(input)) {
|
|
@@ -857,7 +898,7 @@ class Matcher {
|
|
|
857
898
|
* Quotes '\' and '$' in {@code s}, so that the returned string could be used in
|
|
858
899
|
* {@link #appendReplacement} as a literal replacement of {@code s}.
|
|
859
900
|
*
|
|
860
|
-
* @param {string}
|
|
901
|
+
* @param {string} str the string to be quoted
|
|
861
902
|
* @returns {string} the quoted string
|
|
862
903
|
*/
|
|
863
904
|
static quoteReplacement(str) {
|
|
@@ -872,6 +913,11 @@ class Matcher {
|
|
|
872
913
|
return s;
|
|
873
914
|
}).join('');
|
|
874
915
|
}
|
|
916
|
+
/**
|
|
917
|
+
*
|
|
918
|
+
* @param {RE2JS} pattern
|
|
919
|
+
* @param {Utf8MatcherInput|Utf16MatcherInput|number[]|string} input
|
|
920
|
+
*/
|
|
875
921
|
constructor(pattern, input) {
|
|
876
922
|
if (pattern === null) {
|
|
877
923
|
throw new Error('pattern is null');
|
|
@@ -893,7 +939,10 @@ class Matcher {
|
|
|
893
939
|
}
|
|
894
940
|
}
|
|
895
941
|
|
|
896
|
-
/**
|
|
942
|
+
/**
|
|
943
|
+
* Returns the {@code RE2JS} associated with this {@code Matcher}.
|
|
944
|
+
* @returns {RE2JS}
|
|
945
|
+
*/
|
|
897
946
|
pattern() {
|
|
898
947
|
return this.patternInput;
|
|
899
948
|
}
|
|
@@ -901,7 +950,7 @@ class Matcher {
|
|
|
901
950
|
/**
|
|
902
951
|
* Resets the {@code Matcher}, rewinding input and discarding any match information.
|
|
903
952
|
*
|
|
904
|
-
* @returns the {@code Matcher} itself, for chained method calls
|
|
953
|
+
* @returns {Matcher} the {@code Matcher} itself, for chained method calls
|
|
905
954
|
*/
|
|
906
955
|
reset() {
|
|
907
956
|
// The input length in UTF16 codes.
|
|
@@ -920,7 +969,7 @@ class Matcher {
|
|
|
920
969
|
|
|
921
970
|
/**
|
|
922
971
|
* Resets the {@code Matcher} and changes the input.
|
|
923
|
-
* @returns the {@code Matcher} itself, for chained method calls
|
|
972
|
+
* @returns {Matcher} the {@code Matcher} itself, for chained method calls
|
|
924
973
|
*/
|
|
925
974
|
resetMatcherInput(input) {
|
|
926
975
|
if (input === null) {
|
|
@@ -934,7 +983,8 @@ class Matcher {
|
|
|
934
983
|
/**
|
|
935
984
|
* Returns the start of the named group of the most recent match, or -1 if the group was not
|
|
936
985
|
* matched.
|
|
937
|
-
*
|
|
986
|
+
* @param {string|number} [group=0]
|
|
987
|
+
* @returns {string}
|
|
938
988
|
*/
|
|
939
989
|
start() {
|
|
940
990
|
let group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
@@ -952,7 +1002,8 @@ class Matcher {
|
|
|
952
1002
|
/**
|
|
953
1003
|
* Returns the end of the named group of the most recent match, or -1 if the group was not
|
|
954
1004
|
* matched.
|
|
955
|
-
*
|
|
1005
|
+
* @param {string|number} [group=0]
|
|
1006
|
+
* @returns {string}
|
|
956
1007
|
*/
|
|
957
1008
|
end() {
|
|
958
1009
|
let group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
@@ -969,7 +1020,8 @@ class Matcher {
|
|
|
969
1020
|
|
|
970
1021
|
/**
|
|
971
1022
|
* Returns the named group of the most recent match, or {@code null} if the group was not matched.
|
|
972
|
-
*
|
|
1023
|
+
* @param {string|number} [group=0]
|
|
1024
|
+
* @returns {string}
|
|
973
1025
|
*/
|
|
974
1026
|
group() {
|
|
975
1027
|
let group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
@@ -1048,7 +1100,7 @@ class Matcher {
|
|
|
1048
1100
|
* Matches the input against the pattern (unanchored), starting at a specified position. If there
|
|
1049
1101
|
* is a match, {@code find} sets the match state to describe it.
|
|
1050
1102
|
*
|
|
1051
|
-
* @param start the input position where the search begins
|
|
1103
|
+
* @param {string|number} [start=null] the input position where the search begins
|
|
1052
1104
|
* @returns {boolean} if it finds a match
|
|
1053
1105
|
* @throws IndexOutOfBoundsException if start is not a valid input position
|
|
1054
1106
|
*/
|
|
@@ -1131,9 +1183,10 @@ class Matcher {
|
|
|
1131
1183
|
*
|
|
1132
1184
|
* @param {string} replacement the replacement string
|
|
1133
1185
|
* @param {boolean} [perlMode=false] activate perl/js mode (different behaviour for capture groups and special characters)
|
|
1134
|
-
* @returns
|
|
1186
|
+
* @returns {string}
|
|
1135
1187
|
* @throws IllegalStateException if there was no most recent match
|
|
1136
1188
|
* @throws IndexOutOfBoundsException if replacement refers to an invalid group
|
|
1189
|
+
* @private
|
|
1137
1190
|
*/
|
|
1138
1191
|
appendReplacement(replacement) {
|
|
1139
1192
|
let perlMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
@@ -1151,6 +1204,7 @@ class Matcher {
|
|
|
1151
1204
|
/**
|
|
1152
1205
|
* @param {string} replacement - the replacement string
|
|
1153
1206
|
* @returns {string}
|
|
1207
|
+
* @private
|
|
1154
1208
|
*/
|
|
1155
1209
|
appendReplacementInternal(replacement) {
|
|
1156
1210
|
let res = '';
|
|
@@ -1216,6 +1270,7 @@ class Matcher {
|
|
|
1216
1270
|
/**
|
|
1217
1271
|
* @param {string} replacement - the replacement string
|
|
1218
1272
|
* @returns {string}
|
|
1273
|
+
* @private
|
|
1219
1274
|
*/
|
|
1220
1275
|
appendReplacementInternalPerl(replacement) {
|
|
1221
1276
|
let res = '';
|
|
@@ -3085,6 +3140,8 @@ class Parser {
|
|
|
3085
3140
|
}
|
|
3086
3141
|
/**
|
|
3087
3142
|
* Parse regular expression pattern {@code pattern} with mode flags {@code flags}.
|
|
3143
|
+
* @param {string} pattern
|
|
3144
|
+
* @param {number} flags
|
|
3088
3145
|
*/
|
|
3089
3146
|
static parse(pattern, flags) {
|
|
3090
3147
|
return new Parser(pattern, flags).parseInternal();
|
|
@@ -5557,7 +5614,7 @@ class RE2JS {
|
|
|
5557
5614
|
/**
|
|
5558
5615
|
* Helper: create new RE2JS with given regex and flags. Flregex is the regex with flags applied.
|
|
5559
5616
|
* @param {string} regex
|
|
5560
|
-
* @param {number} flags
|
|
5617
|
+
* @param {number} [flags=0]
|
|
5561
5618
|
* @returns {RE2JS}
|
|
5562
5619
|
*/
|
|
5563
5620
|
static compile(regex) {
|
|
@@ -5589,7 +5646,7 @@ class RE2JS {
|
|
|
5589
5646
|
* Matches a string against a regular expression.
|
|
5590
5647
|
*
|
|
5591
5648
|
* @param {string} regex the regular expression
|
|
5592
|
-
* @param {
|
|
5649
|
+
* @param {string|number[]} input the input
|
|
5593
5650
|
* @returns {boolean} true if the regular expression matches the entire input
|
|
5594
5651
|
* @throws RE2JSSyntaxException if the regular expression is malformed
|
|
5595
5652
|
*/
|
|
@@ -5597,7 +5654,10 @@ class RE2JS {
|
|
|
5597
5654
|
return RE2JS.compile(regex).matcher(input).matches();
|
|
5598
5655
|
}
|
|
5599
5656
|
|
|
5600
|
-
|
|
5657
|
+
/**
|
|
5658
|
+
* This is visible for testing.
|
|
5659
|
+
* @private
|
|
5660
|
+
*/
|
|
5601
5661
|
static initTest(pattern, flags, re2) {
|
|
5602
5662
|
if (pattern == null) {
|
|
5603
5663
|
throw new Error('pattern is null');
|
|
@@ -5610,6 +5670,12 @@ class RE2JS {
|
|
|
5610
5670
|
p.re2Input = re2;
|
|
5611
5671
|
return p;
|
|
5612
5672
|
}
|
|
5673
|
+
|
|
5674
|
+
/**
|
|
5675
|
+
*
|
|
5676
|
+
* @param {string} pattern
|
|
5677
|
+
* @param {number} flags
|
|
5678
|
+
*/
|
|
5613
5679
|
constructor(pattern, flags) {
|
|
5614
5680
|
// The pattern string at construction time.
|
|
5615
5681
|
this.patternInput = pattern;
|
|
@@ -5647,7 +5713,7 @@ class RE2JS {
|
|
|
5647
5713
|
/**
|
|
5648
5714
|
* Matches a string against a regular expression.
|
|
5649
5715
|
*
|
|
5650
|
-
* @param {
|
|
5716
|
+
* @param {string|number[]} input the input
|
|
5651
5717
|
* @returns {boolean} true if the regular expression matches the entire input
|
|
5652
5718
|
*/
|
|
5653
5719
|
matches(input) {
|
|
@@ -5657,7 +5723,7 @@ class RE2JS {
|
|
|
5657
5723
|
/**
|
|
5658
5724
|
* Creates a new {@code Matcher} matching the pattern against the input.
|
|
5659
5725
|
*
|
|
5660
|
-
* @param {
|
|
5726
|
+
* @param {string|number[]} input the input string
|
|
5661
5727
|
* @returns {Matcher}
|
|
5662
5728
|
*/
|
|
5663
5729
|
matcher(input) {
|
|
@@ -5678,8 +5744,8 @@ class RE2JS {
|
|
|
5678
5744
|
* of the input, possibly including additional matches of the pattern.
|
|
5679
5745
|
*
|
|
5680
5746
|
* @param {string} input the input string to be split
|
|
5681
|
-
* @param {number} limit the limit
|
|
5682
|
-
* @returns {
|
|
5747
|
+
* @param {number} [limit=0] the limit
|
|
5748
|
+
* @returns {string[]} the split strings
|
|
5683
5749
|
*/
|
|
5684
5750
|
split(input) {
|
|
5685
5751
|
let limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
@@ -5729,6 +5795,11 @@ class RE2JS {
|
|
|
5729
5795
|
}
|
|
5730
5796
|
return result;
|
|
5731
5797
|
}
|
|
5798
|
+
|
|
5799
|
+
/**
|
|
5800
|
+
*
|
|
5801
|
+
* @returns {string}
|
|
5802
|
+
*/
|
|
5732
5803
|
toString() {
|
|
5733
5804
|
return this.patternInput;
|
|
5734
5805
|
}
|
|
@@ -5751,6 +5822,12 @@ class RE2JS {
|
|
|
5751
5822
|
namedGroups() {
|
|
5752
5823
|
return this.re2Input.namedGroups;
|
|
5753
5824
|
}
|
|
5825
|
+
|
|
5826
|
+
/**
|
|
5827
|
+
*
|
|
5828
|
+
* @param {*} other
|
|
5829
|
+
* @returns {boolean}
|
|
5830
|
+
*/
|
|
5754
5831
|
equals(other) {
|
|
5755
5832
|
if (this === other) {
|
|
5756
5833
|
return true;
|