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.
@@ -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.0
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
@@ -698,9 +698,19 @@ class MatcherInputBase {
698
698
  getEncoding() {
699
699
  throw Error('not implemented');
700
700
  }
701
+
702
+ /**
703
+ *
704
+ * @returns {boolean}
705
+ */
701
706
  isUTF8Encoding() {
702
707
  return this.getEncoding() === MatcherInputBase.Encoding.UTF_8;
703
708
  }
709
+
710
+ /**
711
+ *
712
+ * @returns {boolean}
713
+ */
704
714
  isUTF16Encoding() {
705
715
  return this.getEncoding() === MatcherInputBase.Encoding.UTF_16;
706
716
  }
@@ -714,12 +724,26 @@ class Utf8MatcherInput extends MatcherInputBase {
714
724
  getEncoding() {
715
725
  return MatcherInputBase.Encoding.UTF_8;
716
726
  }
727
+ /**
728
+ *
729
+ * @returns {string}
730
+ */
717
731
  asCharSequence() {
718
732
  return Utils.utf8ByteArrayToString(this.bytes);
719
733
  }
734
+
735
+ /**
736
+ *
737
+ * @returns {number[]}
738
+ */
720
739
  asBytes() {
721
740
  return this.bytes;
722
741
  }
742
+
743
+ /**
744
+ *
745
+ * @returns {number}
746
+ */
723
747
  length() {
724
748
  return this.bytes.length;
725
749
  }
@@ -733,12 +757,27 @@ class Utf16MatcherInput extends MatcherInputBase {
733
757
  getEncoding() {
734
758
  return MatcherInputBase.Encoding.UTF_16;
735
759
  }
760
+
761
+ /**
762
+ *
763
+ * @returns {string}
764
+ */
736
765
  asCharSequence() {
737
766
  return this.charSequence;
738
767
  }
768
+
769
+ /**
770
+ *
771
+ * @returns {number[]}
772
+ */
739
773
  asBytes() {
740
774
  return this.charSequence.toString().split('').map(s => s.codePointAt(0));
741
775
  }
776
+
777
+ /**
778
+ *
779
+ * @returns {number}
780
+ */
742
781
  length() {
743
782
  return this.charSequence.length;
744
783
  }
@@ -746,6 +785,7 @@ class Utf16MatcherInput extends MatcherInputBase {
746
785
  class MatcherInput {
747
786
  /**
748
787
  * Return the MatcherInput for UTF_16 encoding.
788
+ * @returns {Utf16MatcherInput}
749
789
  */
750
790
  static utf16(charSequence) {
751
791
  return new Utf16MatcherInput(charSequence);
@@ -753,6 +793,7 @@ class MatcherInput {
753
793
 
754
794
  /**
755
795
  * Return the MatcherInput for UTF_8 encoding.
796
+ * @returns {Utf8MatcherInput}
756
797
  */
757
798
  static utf8(input) {
758
799
  if (Array.isArray(input)) {
@@ -859,7 +900,7 @@ class Matcher {
859
900
  * Quotes '\' and '$' in {@code s}, so that the returned string could be used in
860
901
  * {@link #appendReplacement} as a literal replacement of {@code s}.
861
902
  *
862
- * @param {string} s the string to be quoted
903
+ * @param {string} str the string to be quoted
863
904
  * @returns {string} the quoted string
864
905
  */
865
906
  static quoteReplacement(str) {
@@ -874,6 +915,11 @@ class Matcher {
874
915
  return s;
875
916
  }).join('');
876
917
  }
918
+ /**
919
+ *
920
+ * @param {RE2JS} pattern
921
+ * @param {Utf8MatcherInput|Utf16MatcherInput|number[]|string} input
922
+ */
877
923
  constructor(pattern, input) {
878
924
  if (pattern === null) {
879
925
  throw new Error('pattern is null');
@@ -895,7 +941,10 @@ class Matcher {
895
941
  }
896
942
  }
897
943
 
898
- /** Returns the {@code RE2JS} associated with this {@code Matcher}. */
944
+ /**
945
+ * Returns the {@code RE2JS} associated with this {@code Matcher}.
946
+ * @returns {RE2JS}
947
+ */
899
948
  pattern() {
900
949
  return this.patternInput;
901
950
  }
@@ -903,7 +952,7 @@ class Matcher {
903
952
  /**
904
953
  * Resets the {@code Matcher}, rewinding input and discarding any match information.
905
954
  *
906
- * @returns the {@code Matcher} itself, for chained method calls
955
+ * @returns {Matcher} the {@code Matcher} itself, for chained method calls
907
956
  */
908
957
  reset() {
909
958
  // The input length in UTF16 codes.
@@ -922,7 +971,7 @@ class Matcher {
922
971
 
923
972
  /**
924
973
  * Resets the {@code Matcher} and changes the input.
925
- * @returns the {@code Matcher} itself, for chained method calls
974
+ * @returns {Matcher} the {@code Matcher} itself, for chained method calls
926
975
  */
927
976
  resetMatcherInput(input) {
928
977
  if (input === null) {
@@ -936,7 +985,8 @@ class Matcher {
936
985
  /**
937
986
  * Returns the start of the named group of the most recent match, or -1 if the group was not
938
987
  * matched.
939
- *
988
+ * @param {string|number} [group=0]
989
+ * @returns {string}
940
990
  */
941
991
  start() {
942
992
  let group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
@@ -954,7 +1004,8 @@ class Matcher {
954
1004
  /**
955
1005
  * Returns the end of the named group of the most recent match, or -1 if the group was not
956
1006
  * matched.
957
- *
1007
+ * @param {string|number} [group=0]
1008
+ * @returns {string}
958
1009
  */
959
1010
  end() {
960
1011
  let group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
@@ -971,7 +1022,8 @@ class Matcher {
971
1022
 
972
1023
  /**
973
1024
  * Returns the named group of the most recent match, or {@code null} if the group was not matched.
974
- *
1025
+ * @param {string|number} [group=0]
1026
+ * @returns {string}
975
1027
  */
976
1028
  group() {
977
1029
  let group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
@@ -1050,7 +1102,7 @@ class Matcher {
1050
1102
  * Matches the input against the pattern (unanchored), starting at a specified position. If there
1051
1103
  * is a match, {@code find} sets the match state to describe it.
1052
1104
  *
1053
- * @param start the input position where the search begins
1105
+ * @param {string|number} [start=null] the input position where the search begins
1054
1106
  * @returns {boolean} if it finds a match
1055
1107
  * @throws IndexOutOfBoundsException if start is not a valid input position
1056
1108
  */
@@ -1133,9 +1185,10 @@ class Matcher {
1133
1185
  *
1134
1186
  * @param {string} replacement the replacement string
1135
1187
  * @param {boolean} [perlMode=false] activate perl/js mode (different behaviour for capture groups and special characters)
1136
- * @returns the {@code Matcher} itself, for chained method calls
1188
+ * @returns {string}
1137
1189
  * @throws IllegalStateException if there was no most recent match
1138
1190
  * @throws IndexOutOfBoundsException if replacement refers to an invalid group
1191
+ * @private
1139
1192
  */
1140
1193
  appendReplacement(replacement) {
1141
1194
  let perlMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -1153,6 +1206,7 @@ class Matcher {
1153
1206
  /**
1154
1207
  * @param {string} replacement - the replacement string
1155
1208
  * @returns {string}
1209
+ * @private
1156
1210
  */
1157
1211
  appendReplacementInternal(replacement) {
1158
1212
  let res = '';
@@ -1218,6 +1272,7 @@ class Matcher {
1218
1272
  /**
1219
1273
  * @param {string} replacement - the replacement string
1220
1274
  * @returns {string}
1275
+ * @private
1221
1276
  */
1222
1277
  appendReplacementInternalPerl(replacement) {
1223
1278
  let res = '';
@@ -3087,6 +3142,8 @@ class Parser {
3087
3142
  }
3088
3143
  /**
3089
3144
  * Parse regular expression pattern {@code pattern} with mode flags {@code flags}.
3145
+ * @param {string} pattern
3146
+ * @param {number} flags
3090
3147
  */
3091
3148
  static parse(pattern, flags) {
3092
3149
  return new Parser(pattern, flags).parseInternal();
@@ -5559,7 +5616,7 @@ class RE2JS {
5559
5616
  /**
5560
5617
  * Helper: create new RE2JS with given regex and flags. Flregex is the regex with flags applied.
5561
5618
  * @param {string} regex
5562
- * @param {number} flags
5619
+ * @param {number} [flags=0]
5563
5620
  * @returns {RE2JS}
5564
5621
  */
5565
5622
  static compile(regex) {
@@ -5591,7 +5648,7 @@ class RE2JS {
5591
5648
  * Matches a string against a regular expression.
5592
5649
  *
5593
5650
  * @param {string} regex the regular expression
5594
- * @param {*} input the input
5651
+ * @param {string|number[]} input the input
5595
5652
  * @returns {boolean} true if the regular expression matches the entire input
5596
5653
  * @throws RE2JSSyntaxException if the regular expression is malformed
5597
5654
  */
@@ -5599,7 +5656,10 @@ class RE2JS {
5599
5656
  return RE2JS.compile(regex).matcher(input).matches();
5600
5657
  }
5601
5658
 
5602
- // This is visible for testing.
5659
+ /**
5660
+ * This is visible for testing.
5661
+ * @private
5662
+ */
5603
5663
  static initTest(pattern, flags, re2) {
5604
5664
  if (pattern == null) {
5605
5665
  throw new Error('pattern is null');
@@ -5612,6 +5672,12 @@ class RE2JS {
5612
5672
  p.re2Input = re2;
5613
5673
  return p;
5614
5674
  }
5675
+
5676
+ /**
5677
+ *
5678
+ * @param {string} pattern
5679
+ * @param {number} flags
5680
+ */
5615
5681
  constructor(pattern, flags) {
5616
5682
  // The pattern string at construction time.
5617
5683
  this.patternInput = pattern;
@@ -5649,7 +5715,7 @@ class RE2JS {
5649
5715
  /**
5650
5716
  * Matches a string against a regular expression.
5651
5717
  *
5652
- * @param {*} input the input
5718
+ * @param {string|number[]} input the input
5653
5719
  * @returns {boolean} true if the regular expression matches the entire input
5654
5720
  */
5655
5721
  matches(input) {
@@ -5659,7 +5725,7 @@ class RE2JS {
5659
5725
  /**
5660
5726
  * Creates a new {@code Matcher} matching the pattern against the input.
5661
5727
  *
5662
- * @param {*} input the input string
5728
+ * @param {string|number[]} input the input string
5663
5729
  * @returns {Matcher}
5664
5730
  */
5665
5731
  matcher(input) {
@@ -5680,8 +5746,8 @@ class RE2JS {
5680
5746
  * of the input, possibly including additional matches of the pattern.
5681
5747
  *
5682
5748
  * @param {string} input the input string to be split
5683
- * @param {number} limit the limit
5684
- * @returns {java.lang.String[]} the split strings
5749
+ * @param {number} [limit=0] the limit
5750
+ * @returns {string[]} the split strings
5685
5751
  */
5686
5752
  split(input) {
5687
5753
  let limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
@@ -5731,6 +5797,11 @@ class RE2JS {
5731
5797
  }
5732
5798
  return result;
5733
5799
  }
5800
+
5801
+ /**
5802
+ *
5803
+ * @returns {string}
5804
+ */
5734
5805
  toString() {
5735
5806
  return this.patternInput;
5736
5807
  }
@@ -5753,6 +5824,12 @@ class RE2JS {
5753
5824
  namedGroups() {
5754
5825
  return this.re2Input.namedGroups;
5755
5826
  }
5827
+
5828
+ /**
5829
+ *
5830
+ * @param {*} other
5831
+ * @returns {boolean}
5832
+ */
5756
5833
  equals(other) {
5757
5834
  if (this === other) {
5758
5835
  return true;
@@ -5770,4 +5847,4 @@ exports.RE2JSException = RE2JSException;
5770
5847
  exports.RE2JSFlagsException = RE2JSFlagsException;
5771
5848
  exports.RE2JSGroupException = RE2JSGroupException;
5772
5849
  exports.RE2JSSyntaxException = RE2JSSyntaxException;
5773
- //# sourceMappingURL=index.cjs.js.map
5850
+ //# sourceMappingURL=index.cjs.cjs.map