re2js 2.3.0 → 2.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/README.md +21 -18
- package/build/index.cjs.cjs +106 -36
- package/build/index.cjs.cjs.map +1 -1
- package/build/index.esm.d.ts +27 -14
- package/build/index.esm.d.ts.map +1 -1
- package/build/index.esm.js +106 -36
- package/build/index.esm.js.map +1 -1
- package/build/index.umd.js +106 -36
- package/build/index.umd.js.map +1 -1
- package/package.json +5 -4
package/build/index.esm.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type RE2JS_Pattern = any;
|
|
2
1
|
/**
|
|
3
2
|
* A stateful iterator that interprets a regex {@code RE2JS} on a specific input.
|
|
4
3
|
*
|
|
@@ -21,9 +20,6 @@ export type RE2JS_Pattern = any;
|
|
|
21
20
|
*
|
|
22
21
|
* @author rsc@google.com (Russ Cox)
|
|
23
22
|
*/
|
|
24
|
-
/**
|
|
25
|
-
* @typedef {import('./index').RE2JS} RE2JS_Pattern
|
|
26
|
-
*/
|
|
27
23
|
export class Matcher {
|
|
28
24
|
/**
|
|
29
25
|
* Quotes '\' and '$' in {@code s}, so that the returned string could be used in
|
|
@@ -36,15 +32,15 @@ export class Matcher {
|
|
|
36
32
|
static quoteReplacement(str: string, javaMode?: boolean): string;
|
|
37
33
|
/**
|
|
38
34
|
*
|
|
39
|
-
* @param {
|
|
40
|
-
* @param {
|
|
35
|
+
* @param {RE2JS} pattern
|
|
36
|
+
* @param {string|number[]|Uint8Array} input
|
|
41
37
|
*/
|
|
42
|
-
constructor(pattern:
|
|
38
|
+
constructor(pattern: RE2JS, input: string | number[] | Uint8Array);
|
|
43
39
|
/**
|
|
44
40
|
* The pattern being matched.
|
|
45
|
-
* @type {
|
|
41
|
+
* @type {RE2JS}
|
|
46
42
|
*/
|
|
47
|
-
patternInput:
|
|
43
|
+
patternInput: RE2JS;
|
|
48
44
|
/** @type {number} */
|
|
49
45
|
patternGroupCount: number;
|
|
50
46
|
/** @type {number[]} */
|
|
@@ -55,9 +51,9 @@ export class Matcher {
|
|
|
55
51
|
numberOfInstructions: number;
|
|
56
52
|
/**
|
|
57
53
|
* Returns the {@code RE2JS} associated with this {@code Matcher}.
|
|
58
|
-
* @returns {
|
|
54
|
+
* @returns {RE2JS}
|
|
59
55
|
*/
|
|
60
|
-
pattern():
|
|
56
|
+
pattern(): RE2JS;
|
|
61
57
|
/**
|
|
62
58
|
* Resets the {@code Matcher}, rewinding input and discarding any match information.
|
|
63
59
|
*
|
|
@@ -73,11 +69,11 @@ export class Matcher {
|
|
|
73
69
|
anchorFlag: number | undefined;
|
|
74
70
|
/**
|
|
75
71
|
* Resets the {@code Matcher} and changes the input.
|
|
76
|
-
* @param {
|
|
72
|
+
* @param {MatcherInputBase} input
|
|
77
73
|
* @returns {Matcher} the {@code Matcher} itself, for chained method calls
|
|
78
74
|
*/
|
|
79
|
-
resetMatcherInput(input:
|
|
80
|
-
matcherInput:
|
|
75
|
+
resetMatcherInput(input: MatcherInputBase): Matcher;
|
|
76
|
+
matcherInput: MatcherInputBase | undefined;
|
|
81
77
|
/**
|
|
82
78
|
* Returns the start of the named group of the most recent match, or -1 if the group was not
|
|
83
79
|
* matched.
|
|
@@ -535,6 +531,23 @@ export class RE2Set {
|
|
|
535
531
|
*/
|
|
536
532
|
match(input: string | number[] | Uint8Array): number[];
|
|
537
533
|
}
|
|
534
|
+
/**
|
|
535
|
+
* Abstract the representations of input text supplied to Matcher.
|
|
536
|
+
*/
|
|
537
|
+
declare class MatcherInputBase {
|
|
538
|
+
static Encoding: any;
|
|
539
|
+
getEncoding(): void;
|
|
540
|
+
/**
|
|
541
|
+
*
|
|
542
|
+
* @returns {boolean}
|
|
543
|
+
*/
|
|
544
|
+
isUTF8Encoding(): boolean;
|
|
545
|
+
/**
|
|
546
|
+
*
|
|
547
|
+
* @returns {boolean}
|
|
548
|
+
*/
|
|
549
|
+
isUTF16Encoding(): boolean;
|
|
550
|
+
}
|
|
538
551
|
/**
|
|
539
552
|
* A Prog is a compiled regular expression program.
|
|
540
553
|
*/
|
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":"AAu2CA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;IACE;;;;;;;OAOG;IACH,6BAJW,MAAM,aACN,OAAO,GACL,MAAM,CA2BlB;IACD;;;;OAIG;IACH,qBAHW,KAAK,SACL,MAAM,GAAC,MAAM,EAAE,GAAC,UAAU,EA6BpC;IAvBC;;;OAGG;IACH,cAFU,KAAK,CAEY;IAG3B,qBAAqB;IACrB,mBADW,MAAM,CACqC;IAEtD,uBAAuB;IACvB,QADW,MAAM,EAAE,CACH;IAChB,qCAAqC;IACrC,aADW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CACC;IAClC,qBAAqB;IACrB,sBADW,MAAM,CACqC;IAUxD;;;OAGG;IACH,WAFa,KAAK,CAIjB;IAED;;;;OAIG;IACH,SAFa,OAAO,CAiBnB;IAbC,qBAAqB;IACrB,uCAAoD;IAEpD,qBAAqB;IACrB,8BAAkB;IAElB,8BAAqB;IAGrB,+BAAsB;IAEtB,+BAAmB;IAIrB;;;;OAIG;IACH,yBAHW,gBAAgB,GACd,OAAO,CASnB;IAHC,2CAAyB;IAK3B;;;;;OAKG;IACH,cAHW,MAAM,GAAC,MAAM,GACX,MAAM,CAYlB;IAED;;;;;OAKG;IACH,YAHW,MAAM,GAAC,MAAM,GACX,MAAM,CAYlB;IAED;;;;;;;;;OASG;IACH,eAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,cAHW,MAAM,GAAC,MAAM,GACX,MAAM,GAAC,IAAI,CAgBvB;IAED;;;;OAIG;IACH,kBAFa,MAAM,CAAC,MAAM,EA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OAGG;IACH,cAFa,MAAM,GAAC,IAAI,CAIvB;CACF;AAqhND;IACE,qBAAqB;IACrB,mBADW,MAAM,CACuB;IACxC,qBAAqB;IACrB,qBADW,MAAM,CAC2B;IAC5C,qBAAqB;IACrB,oBADW,MAAM,CACyB;IAE1C;;;;OAIG;IACH,qBAHW,MAAM,UACN,MAAM,EAiBhB;IAdC,eAAoB;IACpB,gBAAoB;IAQpB,iBAAwB;IACxB,eAAiB;IACjB,kBAAgB;IAChB,gBAAe;IACf;;;;;;aAAoB;IAGtB;;;;;;OAMG;IACH,aAJW,MAAM,GACJ,MAAM,CAoBlB;IAED;;;;OAIG;IACH,WAFa,IAAI,CAahB;IAED;;;;OAIG;IACH,aAHW,MAAM,GAAC,MAAM,EAAE,GAAC,UAAU,GACxB,MAAM,EAAE,CAoBpB;CACF;AAphOD;;GAEG;AACH;IACE,qBAAkD;IAClD,oBAEC;IAED;;;OAGG;IACH,kBAFa,OAAO,CAInB;IAED;;;OAGG;IACH,mBAFa,OAAO,CAInB;CACF;AAm0GD;;GAEG;AACH;IAEI,YAAc;IACd,cAAc;IAGd,eAAe;IACf,gBAAkB;IAClB,cAAc;IAKhB,sBAEC;IAGD,kBAEC;IAID,uBAEC;IAID,sBAOC;IAKD,+BAWC;IAID,oBAoBC;IAeD,8BAYC;IACD,8BAYC;IACD;;;OAGG;IACH,YAFa,MAAM,CAelB;CACF;AArxDD;IACE,gCAA4B;IAC5B,uBASC;IARC,UAAgB;IAChB,0BAA2B;IAC3B,mBAAmB;IACnB,gBAAsB;IACtB,mBAAuB;IACvB,oBAAoB;IACpB,gBAAmB;IACnB,cAAc;IAIhB;;;;aAuCC;IAGD,wBAyDC;IACD,mBAyCC;IAGD,kDA+CC;IAGD,yDA+CC;IAGD,0DAwCC;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 v2.3.
|
|
5
|
+
* @version v2.3.2
|
|
6
6
|
* @author Oleksii Vasyliev
|
|
7
7
|
* @homepage https://github.com/le0pard/re2js#readme
|
|
8
8
|
* @repository github:le0pard/re2js
|
|
@@ -627,6 +627,31 @@ class Unicode {
|
|
|
627
627
|
}
|
|
628
628
|
}
|
|
629
629
|
|
|
630
|
+
/**
|
|
631
|
+
* Size of the precomputed single-byte lookup table.
|
|
632
|
+
* Covers standard ASCII and Latin-1 characters for fast-path execution.
|
|
633
|
+
*/
|
|
634
|
+
const FAST_PATH_TABLE_SIZE = 256;
|
|
635
|
+
/**
|
|
636
|
+
* Precomputed lookup table for Word Boundary (\b, \B) assertions.
|
|
637
|
+
* * By precomputing the boolean results for standard ASCII word ranges
|
|
638
|
+
* ('a'-'z', 'A'-'Z', '0'-'9', '_'), we completely eliminate 4 logical
|
|
639
|
+
* branches from the NFA's hot execution loop. This prevents costly
|
|
640
|
+
* CPU branch mispredictions when scanning large strings.
|
|
641
|
+
*/
|
|
642
|
+
const WORD_RUNE_TABLE = new Uint8Array(FAST_PATH_TABLE_SIZE);
|
|
643
|
+
for (let i = 0; i < FAST_PATH_TABLE_SIZE; i++) {
|
|
644
|
+
WORD_RUNE_TABLE[i] = 97 <= i && i <= 122 ||
|
|
645
|
+
// 'a' - 'z'
|
|
646
|
+
65 <= i && i <= 90 ||
|
|
647
|
+
// 'A' - 'Z'
|
|
648
|
+
48 <= i && i <= 57 ||
|
|
649
|
+
// '0' - '9'
|
|
650
|
+
i === 95 // '_'
|
|
651
|
+
? 1 : 0;
|
|
652
|
+
}
|
|
653
|
+
let cachedNativeEncoder = null;
|
|
654
|
+
let cachedNativeDecoder = null;
|
|
630
655
|
/**
|
|
631
656
|
* Various constants and helper utilities.
|
|
632
657
|
*/
|
|
@@ -725,12 +750,21 @@ class Utils {
|
|
|
725
750
|
return out;
|
|
726
751
|
}
|
|
727
752
|
|
|
728
|
-
// Returns the array of runes in the specified
|
|
753
|
+
// Returns the array of runes in the specified JS UTF-16 string.
|
|
729
754
|
static stringToRunes(str) {
|
|
730
|
-
|
|
755
|
+
const string = String(str);
|
|
756
|
+
const runes = [];
|
|
757
|
+
let i = 0;
|
|
758
|
+
while (i < string.length) {
|
|
759
|
+
const cp = string.codePointAt(i);
|
|
760
|
+
runes.push(cp);
|
|
761
|
+
// Surrogate pairs (Emojis, etc.) are > 0xFFFF
|
|
762
|
+
i += cp > Unicode.MAX_BMP ? 2 : 1;
|
|
763
|
+
}
|
|
764
|
+
return runes;
|
|
731
765
|
}
|
|
732
766
|
|
|
733
|
-
// Returns the
|
|
767
|
+
// Returns the JS UTF-16 string containing the single rune |r|.
|
|
734
768
|
static runeToString(r) {
|
|
735
769
|
return String.fromCodePoint(r);
|
|
736
770
|
}
|
|
@@ -739,7 +773,7 @@ class Utils {
|
|
|
739
773
|
// during the evaluation of the \b and \B zero-width assertions.
|
|
740
774
|
// These assertions are ASCII-only: the word characters are [A-Za-z0-9_].
|
|
741
775
|
static isWordRune(r) {
|
|
742
|
-
return
|
|
776
|
+
return r < FAST_PATH_TABLE_SIZE ? WORD_RUNE_TABLE[r] === 1 : false;
|
|
743
777
|
}
|
|
744
778
|
|
|
745
779
|
// emptyOpContext returns the zero-width assertions satisfied at the position
|
|
@@ -752,21 +786,24 @@ class Utils {
|
|
|
752
786
|
static emptyOpContext(r1, r2) {
|
|
753
787
|
let op = 0;
|
|
754
788
|
if (r1 < 0) {
|
|
755
|
-
op |=
|
|
789
|
+
op |= Utils.EMPTY_BEGIN_TEXT | Utils.EMPTY_BEGIN_LINE;
|
|
756
790
|
}
|
|
757
|
-
|
|
758
|
-
|
|
791
|
+
// Hardcode 10 for '\n'
|
|
792
|
+
if (r1 === 10) {
|
|
793
|
+
op |= Utils.EMPTY_BEGIN_LINE;
|
|
759
794
|
}
|
|
760
795
|
if (r2 < 0) {
|
|
761
|
-
op |=
|
|
796
|
+
op |= Utils.EMPTY_END_TEXT | Utils.EMPTY_END_LINE;
|
|
762
797
|
}
|
|
763
|
-
|
|
764
|
-
|
|
798
|
+
|
|
799
|
+
// Hardcode 10 for '\n'
|
|
800
|
+
if (r2 === 10) {
|
|
801
|
+
op |= Utils.EMPTY_END_LINE;
|
|
765
802
|
}
|
|
766
|
-
if (
|
|
767
|
-
op |=
|
|
803
|
+
if (Utils.isWordRune(r1) !== Utils.isWordRune(r2)) {
|
|
804
|
+
op |= Utils.EMPTY_WORD_BOUNDARY;
|
|
768
805
|
} else {
|
|
769
|
-
op |=
|
|
806
|
+
op |= Utils.EMPTY_NO_WORD_BOUNDARY;
|
|
770
807
|
}
|
|
771
808
|
return op;
|
|
772
809
|
}
|
|
@@ -790,9 +827,23 @@ class Utils {
|
|
|
790
827
|
static charCount(codePoint) {
|
|
791
828
|
return codePoint > Unicode.MAX_BMP ? 2 : 1;
|
|
792
829
|
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* High-speed conversion from TypedArrays to standard JS Arrays.
|
|
833
|
+
* Bypasses the expensive Symbol.iterator overhead of Array.from()
|
|
834
|
+
*/
|
|
835
|
+
static toArray(typedArray) {
|
|
836
|
+
const len = typedArray.length;
|
|
837
|
+
const res = new Array(len);
|
|
838
|
+
for (let i = 0; i < len; i++) {
|
|
839
|
+
res[i] = typedArray[i];
|
|
840
|
+
}
|
|
841
|
+
return res;
|
|
842
|
+
}
|
|
793
843
|
static stringToUtf8ByteArray(str) {
|
|
794
844
|
if (globalThis.TextEncoder) {
|
|
795
|
-
|
|
845
|
+
if (!cachedNativeEncoder) cachedNativeEncoder = new TextEncoder();
|
|
846
|
+
return Utils.toArray(cachedNativeEncoder.encode(str));
|
|
796
847
|
} else {
|
|
797
848
|
// fallback, if no TextEncoder
|
|
798
849
|
let out = [],
|
|
@@ -822,7 +873,9 @@ class Utils {
|
|
|
822
873
|
}
|
|
823
874
|
static utf8ByteArrayToString(bytes) {
|
|
824
875
|
if (globalThis.TextDecoder) {
|
|
825
|
-
|
|
876
|
+
if (!cachedNativeDecoder) cachedNativeDecoder = new TextDecoder('utf-8');
|
|
877
|
+
const view = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
878
|
+
return cachedNativeDecoder.decode(view);
|
|
826
879
|
} else {
|
|
827
880
|
// fallback, if no TextDecoder
|
|
828
881
|
let out = [],
|
|
@@ -1119,15 +1172,34 @@ class MachineUTF8Input extends MachineInputBase {
|
|
|
1119
1172
|
if (targetLength === 0) {
|
|
1120
1173
|
return fromIndex <= this.end ? fromIndex : -1;
|
|
1121
1174
|
}
|
|
1175
|
+
const firstByte = target[0];
|
|
1122
1176
|
let limit = this.end - targetLength;
|
|
1123
|
-
|
|
1124
|
-
|
|
1177
|
+
// Feature detection: Native TypedArray indexOf (ES2015)
|
|
1178
|
+
const hasNativeIndexOf = typeof source.indexOf === 'function';
|
|
1179
|
+
let i = fromIndex;
|
|
1180
|
+
while (i <= limit) {
|
|
1181
|
+
// Fast-forward to the first matching byte using C++ bindings if available
|
|
1182
|
+
if (hasNativeIndexOf) {
|
|
1183
|
+
i = source.indexOf(firstByte, i);
|
|
1184
|
+
if (i === -1 || i > limit) return -1;
|
|
1185
|
+
} else {
|
|
1186
|
+
// Fallback: Manual loop
|
|
1187
|
+
while (i <= limit && source[i] !== firstByte) i++;
|
|
1188
|
+
if (i > limit) return -1;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// First byte matches, verify the rest of the target sequence
|
|
1192
|
+
let match = true;
|
|
1193
|
+
for (let j = 1; j < targetLength; j++) {
|
|
1125
1194
|
if (source[i + j] !== target[j]) {
|
|
1195
|
+
match = false;
|
|
1126
1196
|
break;
|
|
1127
|
-
} else if (j === targetLength - 1) {
|
|
1128
|
-
return i;
|
|
1129
1197
|
}
|
|
1130
1198
|
}
|
|
1199
|
+
if (match) {
|
|
1200
|
+
return i;
|
|
1201
|
+
}
|
|
1202
|
+
i++;
|
|
1131
1203
|
}
|
|
1132
1204
|
return -1;
|
|
1133
1205
|
}
|
|
@@ -1199,8 +1271,10 @@ class MachineUTF16Input extends MachineInputBase {
|
|
|
1199
1271
|
// Returns a bitmask of EMPTY_* flags.
|
|
1200
1272
|
context(pos) {
|
|
1201
1273
|
pos += this.start;
|
|
1202
|
-
|
|
1203
|
-
|
|
1274
|
+
|
|
1275
|
+
// We only care about ASCII word runes and newlines for context boundaries
|
|
1276
|
+
const r1 = pos > this.start && pos <= this.end ? this.charSequence.charCodeAt(pos - 1) : -1;
|
|
1277
|
+
const r2 = pos < this.end ? this.charSequence.charCodeAt(pos) : -1;
|
|
1204
1278
|
return Utils.emptyOpContext(r1, r2);
|
|
1205
1279
|
}
|
|
1206
1280
|
prefixLength(re2) {
|
|
@@ -1330,10 +1404,6 @@ class RE2JSInternalException extends RE2JSException {
|
|
|
1330
1404
|
* @author rsc@google.com (Russ Cox)
|
|
1331
1405
|
*/
|
|
1332
1406
|
|
|
1333
|
-
/**
|
|
1334
|
-
* @typedef {import('./index').RE2JS} RE2JS_Pattern
|
|
1335
|
-
*/
|
|
1336
|
-
|
|
1337
1407
|
class Matcher {
|
|
1338
1408
|
/**
|
|
1339
1409
|
* Quotes '\' and '$' in {@code s}, so that the returned string could be used in
|
|
@@ -1371,8 +1441,8 @@ class Matcher {
|
|
|
1371
1441
|
}
|
|
1372
1442
|
/**
|
|
1373
1443
|
*
|
|
1374
|
-
* @param {
|
|
1375
|
-
* @param {
|
|
1444
|
+
* @param {RE2JS} pattern
|
|
1445
|
+
* @param {string|number[]|Uint8Array} input
|
|
1376
1446
|
*/
|
|
1377
1447
|
constructor(pattern, input) {
|
|
1378
1448
|
if (pattern === null) {
|
|
@@ -1380,7 +1450,7 @@ class Matcher {
|
|
|
1380
1450
|
}
|
|
1381
1451
|
/**
|
|
1382
1452
|
* The pattern being matched.
|
|
1383
|
-
* @type {
|
|
1453
|
+
* @type {RE2JS}
|
|
1384
1454
|
*/
|
|
1385
1455
|
this.patternInput = pattern;
|
|
1386
1456
|
const re2 = this.patternInput.re2();
|
|
@@ -1405,7 +1475,7 @@ class Matcher {
|
|
|
1405
1475
|
|
|
1406
1476
|
/**
|
|
1407
1477
|
* Returns the {@code RE2JS} associated with this {@code Matcher}.
|
|
1408
|
-
* @returns {
|
|
1478
|
+
* @returns {RE2JS}
|
|
1409
1479
|
*/
|
|
1410
1480
|
pattern() {
|
|
1411
1481
|
return this.patternInput;
|
|
@@ -1435,7 +1505,7 @@ class Matcher {
|
|
|
1435
1505
|
|
|
1436
1506
|
/**
|
|
1437
1507
|
* Resets the {@code Matcher} and changes the input.
|
|
1438
|
-
* @param {
|
|
1508
|
+
* @param {MatcherInputBase} input
|
|
1439
1509
|
* @returns {Matcher} the {@code Matcher} itself, for chained method calls
|
|
1440
1510
|
*/
|
|
1441
1511
|
resetMatcherInput(input) {
|
|
@@ -2211,7 +2281,7 @@ class Machine {
|
|
|
2211
2281
|
return Utils.emptyInts();
|
|
2212
2282
|
}
|
|
2213
2283
|
// Use subarray() to create a zero-allocation view before converting
|
|
2214
|
-
return
|
|
2284
|
+
return Utils.toArray(this.matchcap.subarray(0, this.ncap));
|
|
2215
2285
|
}
|
|
2216
2286
|
|
|
2217
2287
|
// alloc() allocates a new thread with the given instruction.
|
|
@@ -3173,7 +3243,7 @@ class Backtracker {
|
|
|
3173
3243
|
}
|
|
3174
3244
|
|
|
3175
3245
|
// Must slice so we don't accidentally leak trailing arrays from previously recycled typed arrays
|
|
3176
|
-
const result = ncap === 0 ? [] :
|
|
3246
|
+
const result = ncap === 0 ? [] : Utils.toArray(b.matchcap.subarray(0, ncap));
|
|
3177
3247
|
bitStatePool.push(b);
|
|
3178
3248
|
return result;
|
|
3179
3249
|
}
|
|
@@ -3549,7 +3619,7 @@ class OnePass {
|
|
|
3549
3619
|
matchcap[0] = 0;
|
|
3550
3620
|
matchcap[1] = pos;
|
|
3551
3621
|
}
|
|
3552
|
-
return ncap === 0 ? [] :
|
|
3622
|
+
return ncap === 0 ? [] : Utils.toArray(matchcap);
|
|
3553
3623
|
}
|
|
3554
3624
|
case Inst.RUNE:
|
|
3555
3625
|
if (!inst.matchRune(rune)) return null;
|
|
@@ -3598,7 +3668,7 @@ class OnePass {
|
|
|
3598
3668
|
}
|
|
3599
3669
|
}
|
|
3600
3670
|
if (!matched) return null;
|
|
3601
|
-
return ncap === 0 ? [] :
|
|
3671
|
+
return ncap === 0 ? [] : Utils.toArray(matchcap);
|
|
3602
3672
|
}
|
|
3603
3673
|
}
|
|
3604
3674
|
|
|
@@ -5352,7 +5422,7 @@ class StringIterator {
|
|
|
5352
5422
|
return r;
|
|
5353
5423
|
}
|
|
5354
5424
|
lookingAt(s) {
|
|
5355
|
-
return this.
|
|
5425
|
+
return this.str.startsWith(s, this.position);
|
|
5356
5426
|
}
|
|
5357
5427
|
|
|
5358
5428
|
// Returns the rest of the pattern as a Java UTF-16 string.
|