multi_string_replace 2.0.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +36 -0
- data/Gemfile.lock +1 -1
- data/README.md +13 -3
- data/ext/multi_string_replace/aho_trie.c +1 -1
- data/ext/multi_string_replace/ahocorasick.c +12 -4
- data/ext/multi_string_replace/multi_string_replace.c +11 -3
- data/lib/multi_string_replace/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b380199fa7395925c1c6e6b2c6db5d67f6f5588d81e1af62ecff883a8866cfcd
|
4
|
+
data.tar.gz: 12f94ee8b8f68535b9eacba3db28bab0a008de85148269cf6cee64a9ab8beabc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8248181f107f7bf4d28859374255d4802728795ff7b0e7308f3dcf68a326d133fd45e1041fe01ea043d5934e38e5fca83b67465f2cdae8c7c79b280a8fdffb8
|
7
|
+
data.tar.gz: eedeec0d330d5e82e48205424f09e2b9fe165dcc0791e8715abce83dcd0519bbcc535c72986b6ee989b9878d3809beaaa25ef7560d97f24efcc7d9f89893ed49
|
@@ -0,0 +1,36 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
workflow_dispatch:
|
7
|
+
# schedule:
|
8
|
+
# - cron: '42 5 * * *'
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
test:
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
ruby: [ '3.0' ]
|
16
|
+
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
name: Ruby ${{matrix.ruby}}
|
19
|
+
container: ruby:${{matrix.ruby}}
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v3
|
23
|
+
|
24
|
+
- name: Show ruby Version
|
25
|
+
run: |
|
26
|
+
ruby -v
|
27
|
+
|
28
|
+
- name: Install Modules
|
29
|
+
run: ./bin/setup
|
30
|
+
|
31
|
+
- name: Compile
|
32
|
+
run: rake compile
|
33
|
+
|
34
|
+
- name: Run tests
|
35
|
+
run: rake spec
|
36
|
+
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -40,8 +40,18 @@ You can also pass in a Proc, these will only get evaluated when the token is enc
|
|
40
40
|
|
41
41
|
```ruby
|
42
42
|
MultiStringReplace.replace("The quick brown fox jumps over the lazy dog brown", {'brown' => 'black', 'fox' => ->(s, e) { "cat" }})
|
43
|
+
# => "The quick black cat jumps over the lazy dog black"
|
44
|
+
|
45
|
+
# returning nil will cause the substitution to be ignored.
|
46
|
+
MultiStringReplace.replace("The quick brown fox jumps over the lazy dog brown", {'brown' => 'black', 'fox' => ->(s, e) { nil }})
|
47
|
+
# => "The quick black fox jumps over the lazy dog black"
|
48
|
+
|
49
|
+
MultiStringReplace.replace("The quick brown fox jumps over the lazy dog brown", {'brown' => 'black', 'fox' => ->(s, e) { "" }})
|
50
|
+
# => "The quick black jumps over the lazy dog black"
|
43
51
|
```
|
44
52
|
|
53
|
+
This should allow for very fast and simple templating systems.
|
54
|
+
|
45
55
|
Also adds a mreplace method to String which does the same thing:
|
46
56
|
|
47
57
|
```ruby
|
@@ -63,13 +73,13 @@ Benchmark sources can be found here: <https://github.com/jedld/multi_word_replac
|
|
63
73
|
|
64
74
|
## Development
|
65
75
|
|
66
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
76
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake compile` followed by run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
67
77
|
|
68
78
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
69
79
|
|
70
80
|
## Contributing
|
71
81
|
|
72
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
82
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jedld/multi_string_replace. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
73
83
|
|
74
84
|
## License
|
75
85
|
|
@@ -77,4 +87,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
77
87
|
|
78
88
|
## Code of Conduct
|
79
89
|
|
80
|
-
Everyone interacting in the MultiStringReplace project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
90
|
+
Everyone interacting in the MultiStringReplace project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jedld/multi_string_replace/blob/master/CODE_OF_CONDUCT.md).
|
@@ -29,7 +29,7 @@ bool aho_add_trie_node(struct aho_trie * restrict t, struct aho_text_t * restric
|
|
29
29
|
|
30
30
|
for (int text_idx = 0; text_idx < text->len; text_idx++)
|
31
31
|
{
|
32
|
-
unsigned
|
32
|
+
unsigned char node_text = text->text[text_idx];
|
33
33
|
bool find_node = false;
|
34
34
|
int child_idx = 0;
|
35
35
|
|
@@ -218,13 +218,21 @@ VALUE aho_replace_text(struct ahocorasick * restrict aho, const char* data,
|
|
218
218
|
rb_str_cat(main_result, &data[last_concat_pos], pos - last_concat_pos);
|
219
219
|
}
|
220
220
|
|
221
|
-
|
222
|
-
|
223
221
|
// concatenate replace
|
224
222
|
if (values[result->id] == NULL) {
|
225
223
|
VALUE proc_result = rb_funcall(ruby_values[result->id], rb_intern("call"), 2, LONG2NUM(pos), LONG2NUM(pos + result->len));
|
226
|
-
|
227
|
-
|
224
|
+
if (RB_TYPE_P(proc_result, T_NIL)) {
|
225
|
+
rb_str_cat(main_result, &data[pos], result->len);
|
226
|
+
last_concat_pos = i + 1;
|
227
|
+
continue;
|
228
|
+
} else if (RB_TYPE_P(proc_result, T_STRING)) {
|
229
|
+
value_sizes[result->id] = RSTRING_LEN(proc_result);
|
230
|
+
values[result->id] = StringValuePtr(proc_result);
|
231
|
+
} else {
|
232
|
+
VALUE string_result = rb_funcall(proc_result, rb_intern("to_s"), 0);
|
233
|
+
value_sizes[result->id] = RSTRING_LEN(string_result);
|
234
|
+
values[result->id] = StringValuePtr(string_result);
|
235
|
+
}
|
228
236
|
}
|
229
237
|
|
230
238
|
rb_str_cat(main_result, values[result->id], value_sizes[result->id]);
|
@@ -93,10 +93,18 @@ VALUE multi_string_replace(VALUE self, VALUE body, VALUE replace)
|
|
93
93
|
values[idx] = StringValuePtr(value);
|
94
94
|
value_sizes[idx] = RSTRING_LEN(value);
|
95
95
|
} else {
|
96
|
-
|
97
|
-
|
96
|
+
|
97
|
+
VALUE responds_value = rb_funcall(value, rb_intern("respond_to?"), 1, rb_str_new_cstr("call"));
|
98
|
+
if (RB_TYPE_P(responds_value, T_TRUE)) {
|
99
|
+
values[idx] = NULL;
|
100
|
+
ruby_val[idx] = value;
|
101
|
+
} else {
|
102
|
+
VALUE value_as_string = rb_funcall(value, rb_intern("to_s"), 0);
|
103
|
+
values[idx] = StringValuePtr(value_as_string);
|
104
|
+
value_sizes[idx] = RSTRING_LEN(value_as_string);
|
105
|
+
}
|
98
106
|
}
|
99
|
-
|
107
|
+
|
100
108
|
aho_add_match_text(&aho, StringValuePtr(entry), RSTRING_LEN(entry));
|
101
109
|
}
|
102
110
|
aho_create_trie(&aho);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_string_replace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Dayo
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,6 +75,7 @@ extensions:
|
|
75
75
|
- ext/multi_string_replace/extconf.rb
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
+
- ".github/workflows/ci.yml"
|
78
79
|
- ".gitignore"
|
79
80
|
- ".rspec"
|
80
81
|
- ".travis.yml"
|
@@ -107,7 +108,7 @@ licenses:
|
|
107
108
|
- MIT
|
108
109
|
metadata:
|
109
110
|
allowed_push_host: https://rubygems.org
|
110
|
-
post_install_message:
|
111
|
+
post_install_message:
|
111
112
|
rdoc_options: []
|
112
113
|
require_paths:
|
113
114
|
- lib
|
@@ -122,8 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
123
|
- !ruby/object:Gem::Version
|
123
124
|
version: '0'
|
124
125
|
requirements: []
|
125
|
-
rubygems_version: 3.1
|
126
|
-
signing_key:
|
126
|
+
rubygems_version: 3.4.1
|
127
|
+
signing_key:
|
127
128
|
specification_version: 4
|
128
129
|
summary: A fast multiple string replace library for ruby. Uses a C implementation
|
129
130
|
of the Aho–Corasick Algorithm
|