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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e186368d8d88a70355a0101812a8d8cd1fce54d02bbb910a316db7cf36800cd7
4
- data.tar.gz: 7e08a707cd22e155ecde210a3e99f72eafe45efe5d998b3bdcafd0aab407e7f3
3
+ metadata.gz: b40dce5345e9d2dddf0899c5967ed4804c7ed37ff9c7c9dabd7fd0071690fcc1
4
+ data.tar.gz: ea50b0251c8c8b1be2fc0ebe2bd368185e7f01107d0747ac694b615565cf53e0
5
5
  SHA512:
6
- metadata.gz: 71b5dfce5fdc308ff46018f00608804429fa4a58d2d41f439a0add00f5b225669fd957149917be33beb43e1b3f4831ad618d51a9b62491e8cb5562130e762133
7
- data.tar.gz: 71186a8b4fb00a89e53f4a1b736b54fdb3b0a3e3e682f04e96a10effade4704c0c602ebbbd45e150a066da574fc41f8fef7bb78f440e321d7161d486c191aa56
6
+ metadata.gz: 7a7307c4f68f3e56a2574ec531610f410681df01af682cf04592f6a9393318e5c820eed11c9fb90009ea0a5e08e4dfeb5a07be6f7a8c513809ac8000fecfcd50
7
+ data.tar.gz: 17565b8d2ee5f841fd4cb10d4d37c4feedfd3bd40db8c40a2437287f558abc213de5c67f586e5771c0830153d41102f436d831655056a52d79d31214fcaf3c2f
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # RustRegexp
2
2
 
3
- Simple bindings for [rust/regex](https://docs.rs/regex/latest/regex/) library.
3
+ [![Gem Version](https://badge.fury.io/rb/rust_regexp.svg)](https://badge.fury.io/rb/rust_regexp)
4
+ [![Test](https://github.com/ocvit/rust_regexp/workflows/CI/badge.svg)](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('(\w+):(\d+)')
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 `rust_regexp` so that the backslashes aren't interpreted as escapes.
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
- re.match("ruby:123, rust:456")
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
- re.scan("ruby:123, rust:456")
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
- re.match?("ruby:123")
64
+ RustRegexp.new('\w+:\d+').match?("ruby:123")
56
65
  # => true
57
66
 
58
- re.match?("ruby")
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
- re.pattern
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
- set.match?("abc")
103
+ RustRegexp::Set.new(["abc", "def"]).match?("abc")
95
104
  # => true
96
105
 
97
- set.match?("123")
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
- set.patterns
105
- # => ["abc", "def", "ghi", "xyz"]
113
+ RustRegexp::Set.new(["abc", "def"]).patterns
114
+ # => ["abc", "def"]
106
115
  ```
107
116
 
108
117
  ## Development
@@ -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(group)
74
+ .push(Self::capture_to_ruby_string(&capture))
79
75
  .expect("Non-frozen array");
80
76
  }
81
77
  } else {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RustRegexp
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
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.0
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 to rust/regex library.
12
+ description: Simple bindings for rust/regex library.
13
13
  email:
14
14
  - electric.molfar@gmail.com
15
15
  executables: []