rust_regexp 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +22 -13
- data/ext/rust_regexp/src/lib.rs +3 -7
- data/lib/rust_regexp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b40dce5345e9d2dddf0899c5967ed4804c7ed37ff9c7c9dabd7fd0071690fcc1
|
4
|
+
data.tar.gz: ea50b0251c8c8b1be2fc0ebe2bd368185e7f01107d0747ac694b615565cf53e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a7307c4f68f3e56a2574ec531610f410681df01af682cf04592f6a9393318e5c820eed11c9fb90009ea0a5e08e4dfeb5a07be6f7a8c513809ac8000fecfcd50
|
7
|
+
data.tar.gz: 17565b8d2ee5f841fd4cb10d4d37c4feedfd3bd40db8c40a2437287f558abc213de5c67f586e5771c0830153d41102f436d831655056a52d79d31214fcaf3c2f
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# RustRegexp
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/rust_regexp)
|
4
|
+
[](https://github.com/ocvit/rust_regexp/actions)
|
5
|
+
|
6
|
+
Ruby bindings for [rust/regex](https://docs.rs/regex/latest/regex/) library.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -24,45 +27,51 @@ require "rust_regexp"
|
|
24
27
|
|
25
28
|
## Usage
|
26
29
|
|
27
|
-
Regular expressions should pre-compiled before use:
|
30
|
+
Regular expressions should be pre-compiled before use:
|
28
31
|
|
29
32
|
```ruby
|
30
|
-
re = RustRegexp.new('
|
33
|
+
re = RustRegexp.new('p.t{2}ern*')
|
31
34
|
# => #<RustRegexp:...>
|
32
35
|
```
|
33
36
|
|
34
37
|
> [!TIP]
|
35
38
|
> Note the use of *single quotes* when passing the regular expression as
|
36
|
-
> a string to `
|
39
|
+
> a string to `rust/regex` so that the backslashes aren't interpreted as escapes.
|
37
40
|
|
38
41
|
To find a single match in the haystack:
|
39
42
|
|
40
43
|
```ruby
|
41
|
-
|
44
|
+
RustRegexp.new('\w+:\d+').match("ruby:123, rust:456")
|
45
|
+
# => ["ruby:123"]
|
46
|
+
|
47
|
+
RustRegexp.new('(\w+):(\d+)').match("ruby:123, rust:456")
|
42
48
|
# => ["ruby", "123"]
|
43
49
|
```
|
44
50
|
|
45
51
|
To find all matches in the haystack:
|
46
52
|
|
47
53
|
```ruby
|
48
|
-
|
54
|
+
RustRegexp.new('\w+:\d+').scan("ruby:123, rust:456")
|
55
|
+
# => ["ruby:123", "rust:456"]
|
56
|
+
|
57
|
+
RustRegexp.new('(\w+):(\d+)').scan("ruby:123, rust:456")
|
49
58
|
# => [["ruby", "123"], ["rust", "456"]]
|
50
59
|
```
|
51
60
|
|
52
61
|
To check whether there is at least one match in the haystack:
|
53
62
|
|
54
63
|
```ruby
|
55
|
-
|
64
|
+
RustRegexp.new('\w+:\d+').match?("ruby:123")
|
56
65
|
# => true
|
57
66
|
|
58
|
-
|
67
|
+
RustRegexp.new('\w+:\d+').match?("ruby")
|
59
68
|
# => false
|
60
69
|
```
|
61
70
|
|
62
71
|
Inspect original pattern:
|
63
72
|
|
64
73
|
```ruby
|
65
|
-
|
74
|
+
RustRegexp.new('\w+:\d+').pattern
|
66
75
|
# => "(\\w+):(\\d+)"
|
67
76
|
```
|
68
77
|
|
@@ -91,18 +100,18 @@ set.match("ghidefabc") # => [0, 1, 2]
|
|
91
100
|
To check whether at least one pattern from the set matches the haystack:
|
92
101
|
|
93
102
|
```ruby
|
94
|
-
|
103
|
+
RustRegexp::Set.new(["abc", "def"]).match?("abc")
|
95
104
|
# => true
|
96
105
|
|
97
|
-
|
106
|
+
RustRegexp::Set.new(["abc", "def"]).match?("123")
|
98
107
|
# => false
|
99
108
|
```
|
100
109
|
|
101
110
|
Inspect original patterns:
|
102
111
|
|
103
112
|
```ruby
|
104
|
-
|
105
|
-
# => ["abc", "def"
|
113
|
+
RustRegexp::Set.new(["abc", "def"]).patterns
|
114
|
+
# => ["abc", "def"]
|
106
115
|
```
|
107
116
|
|
108
117
|
## Development
|
data/ext/rust_regexp/src/lib.rs
CHANGED
@@ -33,6 +33,7 @@ impl RustRegexp {
|
|
33
33
|
let regex = &self.0;
|
34
34
|
let haystack = unsafe { haystack.as_slice() };
|
35
35
|
|
36
|
+
// no capture groups defined except the default one
|
36
37
|
if regex.captures_len() == 1 {
|
37
38
|
// speed optimization, `.find` is faster than `.captures`
|
38
39
|
if let Some(capture) = regex.find(haystack) {
|
@@ -65,17 +66,12 @@ impl RustRegexp {
|
|
65
66
|
let regex = &self.0;
|
66
67
|
let haystack = unsafe { haystack.as_slice() };
|
67
68
|
|
69
|
+
// no capture groups defined except the default one
|
68
70
|
if regex.captures_len() == 1 {
|
69
71
|
// speed optimization, `.find_iter` is faster than `.captures_iter`
|
70
72
|
for capture in regex.find_iter(haystack) {
|
71
|
-
let group = RArray::with_capacity(1);
|
72
|
-
|
73
|
-
group
|
74
|
-
.push(Self::capture_to_ruby_string(&capture))
|
75
|
-
.expect("Non-frozen array");
|
76
|
-
|
77
73
|
result
|
78
|
-
.push(
|
74
|
+
.push(Self::capture_to_ruby_string(&capture))
|
79
75
|
.expect("Non-frozen array");
|
80
76
|
}
|
81
77
|
} else {
|
data/lib/rust_regexp/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rust_regexp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmytro Horoshko
|
@@ -9,7 +9,7 @@ bindir: exe
|
|
9
9
|
cert_chain: []
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
|
-
description: Simple bindings
|
12
|
+
description: Simple bindings for rust/regex library.
|
13
13
|
email:
|
14
14
|
- electric.molfar@gmail.com
|
15
15
|
executables: []
|