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.umd.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
|
|
@@ -702,9 +702,19 @@
|
|
|
702
702
|
getEncoding() {
|
|
703
703
|
throw Error('not implemented');
|
|
704
704
|
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
*
|
|
708
|
+
* @returns {boolean}
|
|
709
|
+
*/
|
|
705
710
|
isUTF8Encoding() {
|
|
706
711
|
return this.getEncoding() === MatcherInputBase.Encoding.UTF_8;
|
|
707
712
|
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
*
|
|
716
|
+
* @returns {boolean}
|
|
717
|
+
*/
|
|
708
718
|
isUTF16Encoding() {
|
|
709
719
|
return this.getEncoding() === MatcherInputBase.Encoding.UTF_16;
|
|
710
720
|
}
|
|
@@ -718,12 +728,26 @@
|
|
|
718
728
|
getEncoding() {
|
|
719
729
|
return MatcherInputBase.Encoding.UTF_8;
|
|
720
730
|
}
|
|
731
|
+
/**
|
|
732
|
+
*
|
|
733
|
+
* @returns {string}
|
|
734
|
+
*/
|
|
721
735
|
asCharSequence() {
|
|
722
736
|
return Utils.utf8ByteArrayToString(this.bytes);
|
|
723
737
|
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
*
|
|
741
|
+
* @returns {number[]}
|
|
742
|
+
*/
|
|
724
743
|
asBytes() {
|
|
725
744
|
return this.bytes;
|
|
726
745
|
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
*
|
|
749
|
+
* @returns {number}
|
|
750
|
+
*/
|
|
727
751
|
length() {
|
|
728
752
|
return this.bytes.length;
|
|
729
753
|
}
|
|
@@ -737,12 +761,27 @@
|
|
|
737
761
|
getEncoding() {
|
|
738
762
|
return MatcherInputBase.Encoding.UTF_16;
|
|
739
763
|
}
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
*
|
|
767
|
+
* @returns {string}
|
|
768
|
+
*/
|
|
740
769
|
asCharSequence() {
|
|
741
770
|
return this.charSequence;
|
|
742
771
|
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
*
|
|
775
|
+
* @returns {number[]}
|
|
776
|
+
*/
|
|
743
777
|
asBytes() {
|
|
744
778
|
return this.charSequence.toString().split('').map(s => s.codePointAt(0));
|
|
745
779
|
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
*
|
|
783
|
+
* @returns {number}
|
|
784
|
+
*/
|
|
746
785
|
length() {
|
|
747
786
|
return this.charSequence.length;
|
|
748
787
|
}
|
|
@@ -750,6 +789,7 @@
|
|
|
750
789
|
class MatcherInput {
|
|
751
790
|
/**
|
|
752
791
|
* Return the MatcherInput for UTF_16 encoding.
|
|
792
|
+
* @returns {Utf16MatcherInput}
|
|
753
793
|
*/
|
|
754
794
|
static utf16(charSequence) {
|
|
755
795
|
return new Utf16MatcherInput(charSequence);
|
|
@@ -757,6 +797,7 @@
|
|
|
757
797
|
|
|
758
798
|
/**
|
|
759
799
|
* Return the MatcherInput for UTF_8 encoding.
|
|
800
|
+
* @returns {Utf8MatcherInput}
|
|
760
801
|
*/
|
|
761
802
|
static utf8(input) {
|
|
762
803
|
if (Array.isArray(input)) {
|
|
@@ -863,7 +904,7 @@
|
|
|
863
904
|
* Quotes '\' and '$' in {@code s}, so that the returned string could be used in
|
|
864
905
|
* {@link #appendReplacement} as a literal replacement of {@code s}.
|
|
865
906
|
*
|
|
866
|
-
* @param {string}
|
|
907
|
+
* @param {string} str the string to be quoted
|
|
867
908
|
* @returns {string} the quoted string
|
|
868
909
|
*/
|
|
869
910
|
static quoteReplacement(str) {
|
|
@@ -878,6 +919,11 @@
|
|
|
878
919
|
return s;
|
|
879
920
|
}).join('');
|
|
880
921
|
}
|
|
922
|
+
/**
|
|
923
|
+
*
|
|
924
|
+
* @param {RE2JS} pattern
|
|
925
|
+
* @param {Utf8MatcherInput|Utf16MatcherInput|number[]|string} input
|
|
926
|
+
*/
|
|
881
927
|
constructor(pattern, input) {
|
|
882
928
|
if (pattern === null) {
|
|
883
929
|
throw new Error('pattern is null');
|
|
@@ -899,7 +945,10 @@
|
|
|
899
945
|
}
|
|
900
946
|
}
|
|
901
947
|
|
|
902
|
-
/**
|
|
948
|
+
/**
|
|
949
|
+
* Returns the {@code RE2JS} associated with this {@code Matcher}.
|
|
950
|
+
* @returns {RE2JS}
|
|
951
|
+
*/
|
|
903
952
|
pattern() {
|
|
904
953
|
return this.patternInput;
|
|
905
954
|
}
|
|
@@ -907,7 +956,7 @@
|
|
|
907
956
|
/**
|
|
908
957
|
* Resets the {@code Matcher}, rewinding input and discarding any match information.
|
|
909
958
|
*
|
|
910
|
-
* @returns the {@code Matcher} itself, for chained method calls
|
|
959
|
+
* @returns {Matcher} the {@code Matcher} itself, for chained method calls
|
|
911
960
|
*/
|
|
912
961
|
reset() {
|
|
913
962
|
// The input length in UTF16 codes.
|
|
@@ -926,7 +975,7 @@
|
|
|
926
975
|
|
|
927
976
|
/**
|
|
928
977
|
* Resets the {@code Matcher} and changes the input.
|
|
929
|
-
* @returns the {@code Matcher} itself, for chained method calls
|
|
978
|
+
* @returns {Matcher} the {@code Matcher} itself, for chained method calls
|
|
930
979
|
*/
|
|
931
980
|
resetMatcherInput(input) {
|
|
932
981
|
if (input === null) {
|
|
@@ -940,7 +989,8 @@
|
|
|
940
989
|
/**
|
|
941
990
|
* Returns the start of the named group of the most recent match, or -1 if the group was not
|
|
942
991
|
* matched.
|
|
943
|
-
*
|
|
992
|
+
* @param {string|number} [group=0]
|
|
993
|
+
* @returns {string}
|
|
944
994
|
*/
|
|
945
995
|
start() {
|
|
946
996
|
let group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
@@ -958,7 +1008,8 @@
|
|
|
958
1008
|
/**
|
|
959
1009
|
* Returns the end of the named group of the most recent match, or -1 if the group was not
|
|
960
1010
|
* matched.
|
|
961
|
-
*
|
|
1011
|
+
* @param {string|number} [group=0]
|
|
1012
|
+
* @returns {string}
|
|
962
1013
|
*/
|
|
963
1014
|
end() {
|
|
964
1015
|
let group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
@@ -975,7 +1026,8 @@
|
|
|
975
1026
|
|
|
976
1027
|
/**
|
|
977
1028
|
* Returns the named group of the most recent match, or {@code null} if the group was not matched.
|
|
978
|
-
*
|
|
1029
|
+
* @param {string|number} [group=0]
|
|
1030
|
+
* @returns {string}
|
|
979
1031
|
*/
|
|
980
1032
|
group() {
|
|
981
1033
|
let group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
@@ -1054,7 +1106,7 @@
|
|
|
1054
1106
|
* Matches the input against the pattern (unanchored), starting at a specified position. If there
|
|
1055
1107
|
* is a match, {@code find} sets the match state to describe it.
|
|
1056
1108
|
*
|
|
1057
|
-
* @param start the input position where the search begins
|
|
1109
|
+
* @param {string|number} [start=null] the input position where the search begins
|
|
1058
1110
|
* @returns {boolean} if it finds a match
|
|
1059
1111
|
* @throws IndexOutOfBoundsException if start is not a valid input position
|
|
1060
1112
|
*/
|
|
@@ -1137,9 +1189,10 @@
|
|
|
1137
1189
|
*
|
|
1138
1190
|
* @param {string} replacement the replacement string
|
|
1139
1191
|
* @param {boolean} [perlMode=false] activate perl/js mode (different behaviour for capture groups and special characters)
|
|
1140
|
-
* @returns
|
|
1192
|
+
* @returns {string}
|
|
1141
1193
|
* @throws IllegalStateException if there was no most recent match
|
|
1142
1194
|
* @throws IndexOutOfBoundsException if replacement refers to an invalid group
|
|
1195
|
+
* @private
|
|
1143
1196
|
*/
|
|
1144
1197
|
appendReplacement(replacement) {
|
|
1145
1198
|
let perlMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
@@ -1157,6 +1210,7 @@
|
|
|
1157
1210
|
/**
|
|
1158
1211
|
* @param {string} replacement - the replacement string
|
|
1159
1212
|
* @returns {string}
|
|
1213
|
+
* @private
|
|
1160
1214
|
*/
|
|
1161
1215
|
appendReplacementInternal(replacement) {
|
|
1162
1216
|
let res = '';
|
|
@@ -1222,6 +1276,7 @@
|
|
|
1222
1276
|
/**
|
|
1223
1277
|
* @param {string} replacement - the replacement string
|
|
1224
1278
|
* @returns {string}
|
|
1279
|
+
* @private
|
|
1225
1280
|
*/
|
|
1226
1281
|
appendReplacementInternalPerl(replacement) {
|
|
1227
1282
|
let res = '';
|
|
@@ -3091,6 +3146,8 @@
|
|
|
3091
3146
|
}
|
|
3092
3147
|
/**
|
|
3093
3148
|
* Parse regular expression pattern {@code pattern} with mode flags {@code flags}.
|
|
3149
|
+
* @param {string} pattern
|
|
3150
|
+
* @param {number} flags
|
|
3094
3151
|
*/
|
|
3095
3152
|
static parse(pattern, flags) {
|
|
3096
3153
|
return new Parser(pattern, flags).parseInternal();
|
|
@@ -5563,7 +5620,7 @@
|
|
|
5563
5620
|
/**
|
|
5564
5621
|
* Helper: create new RE2JS with given regex and flags. Flregex is the regex with flags applied.
|
|
5565
5622
|
* @param {string} regex
|
|
5566
|
-
* @param {number} flags
|
|
5623
|
+
* @param {number} [flags=0]
|
|
5567
5624
|
* @returns {RE2JS}
|
|
5568
5625
|
*/
|
|
5569
5626
|
static compile(regex) {
|
|
@@ -5595,7 +5652,7 @@
|
|
|
5595
5652
|
* Matches a string against a regular expression.
|
|
5596
5653
|
*
|
|
5597
5654
|
* @param {string} regex the regular expression
|
|
5598
|
-
* @param {
|
|
5655
|
+
* @param {string|number[]} input the input
|
|
5599
5656
|
* @returns {boolean} true if the regular expression matches the entire input
|
|
5600
5657
|
* @throws RE2JSSyntaxException if the regular expression is malformed
|
|
5601
5658
|
*/
|
|
@@ -5603,7 +5660,10 @@
|
|
|
5603
5660
|
return RE2JS.compile(regex).matcher(input).matches();
|
|
5604
5661
|
}
|
|
5605
5662
|
|
|
5606
|
-
|
|
5663
|
+
/**
|
|
5664
|
+
* This is visible for testing.
|
|
5665
|
+
* @private
|
|
5666
|
+
*/
|
|
5607
5667
|
static initTest(pattern, flags, re2) {
|
|
5608
5668
|
if (pattern == null) {
|
|
5609
5669
|
throw new Error('pattern is null');
|
|
@@ -5616,6 +5676,12 @@
|
|
|
5616
5676
|
p.re2Input = re2;
|
|
5617
5677
|
return p;
|
|
5618
5678
|
}
|
|
5679
|
+
|
|
5680
|
+
/**
|
|
5681
|
+
*
|
|
5682
|
+
* @param {string} pattern
|
|
5683
|
+
* @param {number} flags
|
|
5684
|
+
*/
|
|
5619
5685
|
constructor(pattern, flags) {
|
|
5620
5686
|
// The pattern string at construction time.
|
|
5621
5687
|
this.patternInput = pattern;
|
|
@@ -5653,7 +5719,7 @@
|
|
|
5653
5719
|
/**
|
|
5654
5720
|
* Matches a string against a regular expression.
|
|
5655
5721
|
*
|
|
5656
|
-
* @param {
|
|
5722
|
+
* @param {string|number[]} input the input
|
|
5657
5723
|
* @returns {boolean} true if the regular expression matches the entire input
|
|
5658
5724
|
*/
|
|
5659
5725
|
matches(input) {
|
|
@@ -5663,7 +5729,7 @@
|
|
|
5663
5729
|
/**
|
|
5664
5730
|
* Creates a new {@code Matcher} matching the pattern against the input.
|
|
5665
5731
|
*
|
|
5666
|
-
* @param {
|
|
5732
|
+
* @param {string|number[]} input the input string
|
|
5667
5733
|
* @returns {Matcher}
|
|
5668
5734
|
*/
|
|
5669
5735
|
matcher(input) {
|
|
@@ -5684,8 +5750,8 @@
|
|
|
5684
5750
|
* of the input, possibly including additional matches of the pattern.
|
|
5685
5751
|
*
|
|
5686
5752
|
* @param {string} input the input string to be split
|
|
5687
|
-
* @param {number} limit the limit
|
|
5688
|
-
* @returns {
|
|
5753
|
+
* @param {number} [limit=0] the limit
|
|
5754
|
+
* @returns {string[]} the split strings
|
|
5689
5755
|
*/
|
|
5690
5756
|
split(input) {
|
|
5691
5757
|
let limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
@@ -5735,6 +5801,11 @@
|
|
|
5735
5801
|
}
|
|
5736
5802
|
return result;
|
|
5737
5803
|
}
|
|
5804
|
+
|
|
5805
|
+
/**
|
|
5806
|
+
*
|
|
5807
|
+
* @returns {string}
|
|
5808
|
+
*/
|
|
5738
5809
|
toString() {
|
|
5739
5810
|
return this.patternInput;
|
|
5740
5811
|
}
|
|
@@ -5757,6 +5828,12 @@
|
|
|
5757
5828
|
namedGroups() {
|
|
5758
5829
|
return this.re2Input.namedGroups;
|
|
5759
5830
|
}
|
|
5831
|
+
|
|
5832
|
+
/**
|
|
5833
|
+
*
|
|
5834
|
+
* @param {*} other
|
|
5835
|
+
* @returns {boolean}
|
|
5836
|
+
*/
|
|
5760
5837
|
equals(other) {
|
|
5761
5838
|
if (this === other) {
|
|
5762
5839
|
return true;
|