re2 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/ext/re2/extconf.rb +20 -12
- data/ext/re2/re2.cc +18 -26
- data/lib/re2/string.rb +3 -19
- data/spec/re2/regexp_spec.rb +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddba6fe8bb8c7e51bcb0b8f4346b39ca903978ff6697a4c14d06702baae10598
|
4
|
+
data.tar.gz: f8905eeeeff7e4bebc532d23fa19b29f1c3e2a88ea303a5aa879bafb4af4e1ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44184ad41a55746903fcd350fbf473d26266c710e324eaac879b46ff45e3b77120d5100a25f5188e2d938cafbc48caf909506d79cf07c31522ccfb9e789c2ce0
|
7
|
+
data.tar.gz: eb282abd472e00ebcbb10e38f84c62bbac785bd139c69140647a29a157475600b6845472edb41ed42234caf5729188052cc1459b1ac2775c544ed0e905c6039d
|
data/README.md
CHANGED
@@ -4,9 +4,9 @@ re2 [![Build Status](https://github.com/mudge/re2/actions/workflows/tests.yml/ba
|
|
4
4
|
A Ruby binding to [re2][], an "efficient, principled regular expression
|
5
5
|
library".
|
6
6
|
|
7
|
-
**Current version:** 1.
|
8
|
-
**Supported Ruby versions:** 1.8.7, 1.9.3, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1
|
9
|
-
**Supported re2 versions:** libre2.0 (< 2020-03-02), libre2.1 (2020-03-02), libre2.6 (2020-03-03), libre2.7 (2020-05-01), libre2.8 (2020-07-06), libre2.9 (2020-11-01)
|
7
|
+
**Current version:** 1.7.0
|
8
|
+
**Supported Ruby versions:** 1.8.7, 1.9.3, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2
|
9
|
+
**Supported re2 versions:** libre2.0 (< 2020-03-02), libre2.1 (2020-03-02), libre2.6 (2020-03-03), libre2.7 (2020-05-01), libre2.8 (2020-07-06), libre2.9 (2020-11-01), libre2.10 (2022-12-01), libre2.11 (2023-07-01)
|
10
10
|
|
11
11
|
Installation
|
12
12
|
------------
|
@@ -22,7 +22,7 @@ If you are using Debian, you can install the [libre2-dev][] package like so:
|
|
22
22
|
|
23
23
|
$ sudo apt-get install libre2-dev
|
24
24
|
|
25
|
-
Recent versions of re2 require a compiler with C++
|
25
|
+
Recent versions of re2 require a compiler with C++14 support such as [clang](http://clang.llvm.org/) 3.4 or [gcc](https://gcc.gnu.org/) 5.
|
26
26
|
|
27
27
|
If you are using a packaged Ruby distribution, make sure you also have the
|
28
28
|
Ruby header files installed such as those provided by the [ruby-dev][] package
|
@@ -214,7 +214,7 @@ Contributions
|
|
214
214
|
* Thanks to [Jason Woods](https://github.com/driskell) who contributed the
|
215
215
|
original implementations of `RE2::MatchData#begin` and `RE2::MatchData#end`;
|
216
216
|
* Thanks to [Stefano Rivera](https://github.com/stefanor) who first contributed C++11 support;
|
217
|
-
* Thanks to [Stan Hu](https://github.com/stanhu) for reporting a bug with empty patterns and `RE2::Regexp#scan
|
217
|
+
* Thanks to [Stan Hu](https://github.com/stanhu) for reporting a bug with empty patterns and `RE2::Regexp#scan` and for contributing support for libre2.11 (2023-07-01);
|
218
218
|
* Thanks to [Sebastian Reitenbach](https://github.com/buzzdeee) for reporting
|
219
219
|
the deprecation and removal of the `utf8` encoding option in re2;
|
220
220
|
* Thanks to [Sergio Medina](https://github.com/serch) for reporting a bug when
|
data/ext/re2/extconf.rb
CHANGED
@@ -44,22 +44,30 @@ unless have_library("re2")
|
|
44
44
|
abort "You must have re2 installed and specified with --with-re2-dir, please see https://github.com/google/re2/wiki/Install"
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
checking_for("re2 requires C++11 compiler") do
|
49
|
-
minimal_program = <<SRC
|
47
|
+
minimal_program = <<SRC
|
50
48
|
#include <re2/re2.h>
|
51
49
|
int main() { return 0; }
|
52
50
|
SRC
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
52
|
+
re2_requires_version_flag = checking_for("re2 that requires explicit C++ version flag") do
|
53
|
+
!try_compile(minimal_program, compile_options)
|
54
|
+
end
|
55
|
+
|
56
|
+
if re2_requires_version_flag
|
57
|
+
# Recent versions of re2 depend directly on abseil, which requires a
|
58
|
+
# compiler with C++14 support (see
|
59
|
+
# https://github.com/abseil/abseil-cpp/issues/1127 and
|
60
|
+
# https://github.com/abseil/abseil-cpp/issues/1431). However, the
|
61
|
+
# `std=c++14` flag doesn't appear to suffice; we need at least
|
62
|
+
# `std=c++17`.
|
63
|
+
abort "Cannot compile re2 with your compiler: recent versions require C++14 support." unless %w[c++20 c++17 c++11 c++0x].any? do |std|
|
64
|
+
checking_for("re2 that compiles with #{std} standard") do
|
65
|
+
if try_compile(minimal_program, compile_options + " -std=#{std}")
|
66
|
+
compile_options << " -std=#{std}"
|
67
|
+
$CPPFLAGS << " -std=#{std}"
|
68
|
+
|
69
|
+
true
|
70
|
+
end
|
63
71
|
end
|
64
72
|
end
|
65
73
|
end
|
data/ext/re2/re2.cc
CHANGED
@@ -393,7 +393,7 @@ re2::StringPiece *re2_matchdata_find_match(VALUE idx, VALUE self) {
|
|
393
393
|
/*
|
394
394
|
* Returns the number of elements in the match array (including nils).
|
395
395
|
*
|
396
|
-
* @return [
|
396
|
+
* @return [Integer] the number of elements
|
397
397
|
* @example
|
398
398
|
* m = RE2::Regexp.new('(\d+)').match("bob 123")
|
399
399
|
* m.size #=> 2
|
@@ -409,8 +409,8 @@ static VALUE re2_matchdata_size(VALUE self) {
|
|
409
409
|
/*
|
410
410
|
* Returns the offset of the start of the nth element of the matchdata.
|
411
411
|
*
|
412
|
-
* @param [
|
413
|
-
* @return [
|
412
|
+
* @param [Integer, String, Symbol] n the name or number of the match
|
413
|
+
* @return [Integer] the offset of the start of the match
|
414
414
|
* @example
|
415
415
|
* m = RE2::Regexp.new('ob (\d+)').match("bob 123")
|
416
416
|
* m.begin(0) #=> 1
|
@@ -439,8 +439,8 @@ static VALUE re2_matchdata_begin(VALUE self, VALUE n) {
|
|
439
439
|
/*
|
440
440
|
* Returns the offset of the character following the end of the nth element of the matchdata.
|
441
441
|
*
|
442
|
-
* @param [
|
443
|
-
* @return [
|
442
|
+
* @param [Integer, String, Symbol] n the name or number of the match
|
443
|
+
* @return [Integer] the offset of the character following the end of the match
|
444
444
|
* @example
|
445
445
|
* m = RE2::Regexp.new('ob (\d+) b').match("bob 123 bob")
|
446
446
|
* m.end(0) #=> 9
|
@@ -584,7 +584,7 @@ static VALUE re2_matchdata_named_match(const char* name, VALUE self) {
|
|
584
584
|
* @overload [](index)
|
585
585
|
* Access a particular match by index.
|
586
586
|
*
|
587
|
-
* @param [
|
587
|
+
* @param [Integer] index the index of the match to fetch
|
588
588
|
* @return [String, nil] the specified match
|
589
589
|
* @example
|
590
590
|
* m = RE2::Regexp.new('(\d+)').match("bob 123")
|
@@ -593,8 +593,8 @@ static VALUE re2_matchdata_named_match(const char* name, VALUE self) {
|
|
593
593
|
* @overload [](start, length)
|
594
594
|
* Access a range of matches by starting index and length.
|
595
595
|
*
|
596
|
-
* @param [
|
597
|
-
* @param [
|
596
|
+
* @param [Integer] start the index from which to start
|
597
|
+
* @param [Integer] length the number of elements to fetch
|
598
598
|
* @return [Array<String, nil>] the specified matches
|
599
599
|
* @example
|
600
600
|
* m = RE2::Regexp.new('(\d+)').match("bob 123")
|
@@ -795,12 +795,9 @@ static VALUE re2_matchdata_deconstruct_keys(VALUE self, VALUE keys) {
|
|
795
795
|
|
796
796
|
/*
|
797
797
|
* Returns a new RE2 object with a compiled version of
|
798
|
-
* +pattern+ stored inside. Equivalent to +RE2.new+.
|
798
|
+
* +pattern+ stored inside. Equivalent to +RE2::Regexp.new+.
|
799
799
|
*
|
800
|
-
* @
|
801
|
-
* @param [String] pattern the pattern to compile
|
802
|
-
* @param [Hash] options the options to compile a regexp with
|
803
|
-
* @see RE2::Regexp.new
|
800
|
+
* @see RE2::Regexp#initialize
|
804
801
|
*
|
805
802
|
*/
|
806
803
|
static VALUE re2_re2(int argc, VALUE *argv, VALUE self) {
|
@@ -833,7 +830,7 @@ static VALUE re2_re2(int argc, VALUE *argv, VALUE self) {
|
|
833
830
|
* @option options [Boolean] :posix_syntax (false) restrict regexps to POSIX egrep syntax
|
834
831
|
* @option options [Boolean] :longest_match (false) search for longest match, not first match
|
835
832
|
* @option options [Boolean] :log_errors (true) log syntax and execution errors to ERROR
|
836
|
-
* @option options [
|
833
|
+
* @option options [Integer] :max_mem approx. max memory footprint of RE2
|
837
834
|
* @option options [Boolean] :literal (false) interpret string as literal, not regexp
|
838
835
|
* @option options [Boolean] :never_nl (false) never match \n, even if it is in regexp
|
839
836
|
* @option options [Boolean] :case_sensitive (true) match is case-sensitive (regexp can override with (?i) unless in posix_syntax mode)
|
@@ -984,7 +981,7 @@ static VALUE re2_regexp_log_errors(VALUE self) {
|
|
984
981
|
* Returns the max_mem setting for the regular expression
|
985
982
|
* +re2+.
|
986
983
|
*
|
987
|
-
* @return [
|
984
|
+
* @return [Integer] the max_mem option
|
988
985
|
* @example
|
989
986
|
* re2 = RE2::Regexp.new("woo?", :max_mem => 1024)
|
990
987
|
* re2.max_mem #=> 1024
|
@@ -1138,7 +1135,7 @@ static VALUE re2_regexp_error_arg(VALUE self) {
|
|
1138
1135
|
* of a regexp's "cost". Larger numbers are more expensive
|
1139
1136
|
* than smaller numbers.
|
1140
1137
|
*
|
1141
|
-
* @return [
|
1138
|
+
* @return [Integer] the regexp "cost"
|
1142
1139
|
*/
|
1143
1140
|
static VALUE re2_regexp_program_size(VALUE self) {
|
1144
1141
|
re2_pattern *p;
|
@@ -1203,7 +1200,7 @@ static VALUE re2_regexp_options(VALUE self) {
|
|
1203
1200
|
* wasn't valid on construction. The overall match ($0) does not
|
1204
1201
|
* count: if the regexp is "(a)(b)", returns 2.
|
1205
1202
|
*
|
1206
|
-
* @return [
|
1203
|
+
* @return [Integer] the number of capturing subpatterns
|
1207
1204
|
*/
|
1208
1205
|
static VALUE re2_regexp_number_of_capturing_groups(VALUE self) {
|
1209
1206
|
re2_pattern *p;
|
@@ -1273,7 +1270,7 @@ static VALUE re2_regexp_named_capturing_groups(VALUE self) {
|
|
1273
1270
|
* matches returned (padded with nils if necessary).
|
1274
1271
|
*
|
1275
1272
|
* @param [String] text the text to search
|
1276
|
-
* @param [
|
1273
|
+
* @param [Integer] number_of_matches the number of matches to return
|
1277
1274
|
* @return [RE2::MatchData] the matches
|
1278
1275
|
* @raise [ArgumentError] if given a negative number of matches
|
1279
1276
|
* @raise [NoMemoryError] if there was not enough memory to allocate the matches
|
@@ -1399,7 +1396,7 @@ static VALUE re2_regexp_scan(VALUE self, VALUE text) {
|
|
1399
1396
|
* @return [String] the resulting string
|
1400
1397
|
* @example
|
1401
1398
|
* RE2.Replace("hello there", "hello", "howdy") #=> "howdy there"
|
1402
|
-
* re2 = RE2.new("hel+o")
|
1399
|
+
* re2 = RE2::Regexp.new("hel+o")
|
1403
1400
|
* RE2.Replace("hello there", re2, "yo") #=> "yo there"
|
1404
1401
|
*/
|
1405
1402
|
static VALUE re2_Replace(VALUE self, VALUE str, VALUE pattern,
|
@@ -1435,7 +1432,7 @@ static VALUE re2_Replace(VALUE self, VALUE str, VALUE pattern,
|
|
1435
1432
|
* @param [String] rewrite the string to replace with
|
1436
1433
|
* @return [String] the resulting string
|
1437
1434
|
* @example
|
1438
|
-
* re2 = RE2.new("oo?")
|
1435
|
+
* re2 = RE2::Regexp.new("oo?")
|
1439
1436
|
* RE2.GlobalReplace("whoops-doops", re2, "e") #=> "wheps-deps"
|
1440
1437
|
* RE2.GlobalReplace("hello there", "e", "i") #=> "hillo thiri"
|
1441
1438
|
*/
|
@@ -1522,7 +1519,7 @@ static VALUE re2_set_allocate(VALUE klass) {
|
|
1522
1519
|
* @option options [Boolean] :posix_syntax (false) restrict regexps to POSIX egrep syntax
|
1523
1520
|
* @option options [Boolean] :longest_match (false) search for longest match, not first match
|
1524
1521
|
* @option options [Boolean] :log_errors (true) log syntax and execution errors to ERROR
|
1525
|
-
* @option options [
|
1522
|
+
* @option options [Integer] :max_mem approx. max memory footprint of RE2
|
1526
1523
|
* @option options [Boolean] :literal (false) interpret string as literal, not regexp
|
1527
1524
|
* @option options [Boolean] :never_nl (false) never match \n, even if it is in regexp
|
1528
1525
|
* @option options [Boolean] :case_sensitive (true) match is case-sensitive (regexp can override with (?i) unless in posix_syntax mode)
|
@@ -1889,9 +1886,4 @@ void Init_re2(void) {
|
|
1889
1886
|
id_anchor_start = rb_intern("anchor_start");
|
1890
1887
|
id_anchor_both = rb_intern("anchor_both");
|
1891
1888
|
id_exception = rb_intern("exception");
|
1892
|
-
|
1893
|
-
#if 0
|
1894
|
-
/* Fake so YARD generates the file. */
|
1895
|
-
rb_mKernel = rb_define_module("Kernel");
|
1896
|
-
#endif
|
1897
1889
|
}
|
data/lib/re2/string.rb
CHANGED
@@ -12,30 +12,14 @@ module RE2
|
|
12
12
|
# Replaces the first occurrence +pattern+ with +rewrite+ and returns a new
|
13
13
|
# string.
|
14
14
|
#
|
15
|
-
# @
|
16
|
-
# @param [String] rewrite the string to replace with
|
17
|
-
# @example
|
18
|
-
# "hello there".re2_sub("hello", "howdy") #=> "howdy there"
|
19
|
-
# re2 = RE2.new("hel+o")
|
20
|
-
# "hello there".re2_sub(re2, "yo") #=> "yo there"
|
21
|
-
# text = "Good morning"
|
22
|
-
# text.re2_sub("morn", "even") #=> "Good evening"
|
23
|
-
# text #=> "Good morning"
|
15
|
+
# @see RE2.Replace
|
24
16
|
def re2_sub(*args)
|
25
17
|
RE2.Replace(self, *args)
|
26
18
|
end
|
27
19
|
|
28
20
|
# Replaces every occurrence of +pattern+ with +rewrite+ and return a new string.
|
29
21
|
#
|
30
|
-
# @
|
31
|
-
# @param [String] rewrite the string to replace with
|
32
|
-
# @example
|
33
|
-
# "hello there".re2_gsub("e", "i") #=> "hillo thiri"
|
34
|
-
# re2 = RE2.new("oo?")
|
35
|
-
# "whoops-doops".re2_gsub(re2, "e") #=> "wheps-deps"
|
36
|
-
# text = "Good morning"
|
37
|
-
# text.re2_gsub("o", "ee") #=> "Geeeed meerning"
|
38
|
-
# text #=> "Good morning"
|
22
|
+
# @see RE2.GlobalReplace
|
39
23
|
def re2_gsub(*args)
|
40
24
|
RE2.GlobalReplace(self, *args)
|
41
25
|
end
|
@@ -74,7 +58,7 @@ module RE2
|
|
74
58
|
# matches returned (padded with nils if necessary).
|
75
59
|
#
|
76
60
|
# @param [String, RE2::Regexp] pattern the regular expression to match
|
77
|
-
# @param [
|
61
|
+
# @param [Integer] number_of_matches the number of matches to return
|
78
62
|
# @return [RE2::MatchData] the matches
|
79
63
|
# @raise [NoMemoryError] if there was not enough memory to allocate the matches
|
80
64
|
# @example
|
data/spec/re2/regexp_spec.rb
CHANGED
@@ -91,7 +91,8 @@ RSpec.describe RE2::Regexp do
|
|
91
91
|
describe "#program_size" do
|
92
92
|
it "returns a numeric value" do
|
93
93
|
program_size = RE2::Regexp.new('w(o)(o)').program_size
|
94
|
-
|
94
|
+
|
95
|
+
expect(program_size).to be_an(Integer)
|
95
96
|
end
|
96
97
|
|
97
98
|
it "returns -1 for an invalid pattern" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: re2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Mucur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
82
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
83
|
+
rubygems_version: 3.4.10
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: Ruby bindings to re2.
|