chars 0.2.4 → 0.3.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/.github/workflows/ruby.yml +5 -5
- data/ChangeLog.md +32 -11
- data/Gemfile +2 -0
- data/README.md +64 -13
- data/benchmarks/compare.rb +1 -1
- data/benchmarks/substrings.rb +25 -0
- data/gemspec.yml +1 -0
- data/lib/chars/char_set.rb +291 -56
- data/lib/chars/chars.rb +42 -6
- data/lib/chars/string_enumerator.rb +98 -0
- data/lib/chars/version.rb +1 -1
- data/spec/char_set_spec.rb +415 -31
- data/spec/chars_spec.rb +183 -27
- data/spec/extensions/string_spec.rb +1 -1
- data/spec/string_enumerator_spec.rb +99 -0
- metadata +7 -4
- data/benchmarks/strings_in.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b408bb91d6c66422ccb57e66af6cdeceeb97d50c610628a9b99780319f4af57
|
4
|
+
data.tar.gz: '039bef18f59a8ea05fd2a259839432e9ad2eee15c692969bf611d11b15255b75'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 803264ba7bafc4546df334bd2a508389f525c9814ab0452ef7b2b7c9b75cc0fb952c729f0b5b093cbede36d60be5badeb29ada0e29ee5b12ae3d681878aeb163
|
7
|
+
data.tar.gz: 2e9f1c229d9987e5cb1dfc0caada8c71582e0c72e8c03e7b39313c4bc1e9e447bdbdfcf641009174de47b4e0e94384296dc26cf8a136f72881bfd664fa311720
|
data/.github/workflows/ruby.yml
CHANGED
data/ChangeLog.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
### 0.3.1 / 2022-12-01
|
2
|
+
|
3
|
+
* Removed the space character from {Chars::PUNCTUATION}, as spaces are not
|
4
|
+
technically a punctuation character.
|
5
|
+
* Removed `\f`, `\n`, `\r`, `\t`, and `\v` from {Chars::PRINTABLE}, as other
|
6
|
+
whitespace characters besides space (`' '`) are not considered printable
|
7
|
+
characters.
|
8
|
+
|
9
|
+
### 0.3.0 / 2021-10-23
|
10
|
+
|
11
|
+
* Added {Chars::WHITESPACE}.
|
12
|
+
* Added {Chars::DIGITS}.
|
13
|
+
* Added {Chars::CharSet#each_substring_with_index}.
|
14
|
+
* Added {Chars::CharSet#substrings_with_indexes}.
|
15
|
+
* Added {Chars::CharSet#each_substring}.
|
16
|
+
* Added {Chars::CharSet#substrings}.
|
17
|
+
* Added {Chars::CharSet#each_string_of_length}.
|
18
|
+
* Added {Chars::CharSet#strings_of_length}.
|
19
|
+
* Added {Chars::StringEnumerator}.
|
20
|
+
|
1
21
|
### 0.2.4 / 2021-10-22
|
2
22
|
|
3
23
|
* Require [ruby] >= 2.0.0.
|
@@ -10,7 +30,7 @@
|
|
10
30
|
|
11
31
|
### 0.2.2 / 2012-05-28
|
12
32
|
|
13
|
-
* {Chars::CharSet#initialize} now raises a TypeError when given arguments
|
33
|
+
* {Chars::CharSet#initialize} now raises a `TypeError` when given arguments
|
14
34
|
that were neither a `String`, `Integer` or `Enumerable`.
|
15
35
|
* Allow {Chars::CharSet#strings_in} to yield results as they are found.
|
16
36
|
* Improved the performance of {Chars::CharSet#strings_in} when operating on
|
@@ -34,20 +54,21 @@
|
|
34
54
|
|
35
55
|
### 0.1.2 / 2009-09-21
|
36
56
|
|
37
|
-
* Require
|
38
|
-
* Require
|
39
|
-
* Require
|
40
|
-
* Added Chars.visibile and Chars::VISIBLE (thanks flatline).
|
41
|
-
* Added CharSet#random_distinct_bytes,
|
42
|
-
and CharSet#random_distinct_string
|
43
|
-
|
57
|
+
* Require `hoe` >= 2.3.3.
|
58
|
+
* Require `yard` >= 0.2.3.5.
|
59
|
+
* Require `rspec` >= 1.2.8.
|
60
|
+
* Added {Chars.visibile} and {Chars::VISIBLE} (thanks flatline).
|
61
|
+
* Added {Chars::CharSet#random_distinct_bytes},
|
62
|
+
{Chars::CharSet#random_distinct_chars}, and {CharSet#random_distinct_string}
|
63
|
+
(thanks flatline).
|
64
|
+
* Use `hoe/signing` for signed RubyGems.
|
44
65
|
* Moved to YARD based documentation.
|
45
66
|
* All specs now pass on JRuby 1.3.1.
|
46
67
|
|
47
68
|
### 0.1.1 / 2009-04-01
|
48
69
|
|
49
|
-
* Renamed CharSet#=~ to CharSet
|
50
|
-
* Added an alias from CharSet
|
70
|
+
* Renamed {Chars::CharSet#=~} to {Chars::CharSet#===}.
|
71
|
+
* Added an alias from `Chars::CharSet#=~` to {Chars::CharSet#===}.
|
51
72
|
|
52
73
|
### 0.1.0 / 2009-03-16
|
53
74
|
|
@@ -68,7 +89,7 @@
|
|
68
89
|
* Printable
|
69
90
|
* Control
|
70
91
|
* ASCII
|
71
|
-
* Provides convenience methods for testing
|
92
|
+
* Provides convenience methods for testing whether a `String` or `Integer`
|
72
93
|
belongs to a certain character set.
|
73
94
|
* Supports random text generation using specific character sets.
|
74
95
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -23,11 +23,11 @@ recognizing text and generating random text from specific character sets.
|
|
23
23
|
* Lowercase Alpha: `a` - `z`
|
24
24
|
* Alpha: `a` - `z`, `A` - `Z`
|
25
25
|
* Alpha-numeric: `0` - `9`, `a` - `z`, `A` - `Z`
|
26
|
-
* Punctuation: `'
|
27
|
-
* Symbols: `'
|
26
|
+
* Punctuation: `'`, `"`, `` ` ``, `,`, `;`, `:`, `~`, `-`, `(`, `)`, `[`, `]`, `{`, `}`, `.`, `?`, `!`
|
27
|
+
* Symbols: `'`, `"`, `` ` ``, `,`, `;`, `:`, `~`, `-`, `(`, `)`, `[`, `]`, `{`, `}`, `.`, `?`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, `*`, `_`, `+`, `=`, `|`, `\`, `<`, `>`, `/`
|
28
28
|
* Space: `' '`, `\f`, `\n`, `\r`, `\t`, `\v`
|
29
29
|
* Visible: `0` - `9`, `a` - `z`, `A` - `Z`, `'`, `"`, `` ` ``, `,`, `;`, `:`, `~`, `-`, `(`, `)`, `[`, `]`, `{`, `}`, `.`, `?`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, `*`, `_`, `+`, `=`, `|`, `\`, `<`, `>`, `/`
|
30
|
-
* Printable: `0` - `9`, `a` - `z`, `A` - `Z`, `' '`, `'`, `"`, `` ` ``, `,`, `;`, `:`, `~`, `-`, `(`, `)`, `[`, `]`, `{`, `}`, `.`, `?`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, <code>*</code>, <code>_</code>, `+`, `=`, `|`, `\`, `<`, `>`,
|
30
|
+
* Printable: `0` - `9`, `a` - `z`, `A` - `Z`, `' '`, `'`, `"`, `` ` ``, `,`, `;`, `:`, `~`, `-`, `(`, `)`, `[`, `]`, `{`, `}`, `.`, `?`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, <code>*</code>, <code>_</code>, `+`, `=`, `|`, `\`, `<`, `>`, `/`
|
31
31
|
* Control: `\x00` - `\x1f`, `\x7f`
|
32
32
|
* Signed ASCII: `\x00` - `\x7f`
|
33
33
|
* ASCII: `\x00` - `\xff`
|
@@ -48,14 +48,6 @@ Determine whether a String belongs to a character set:
|
|
48
48
|
# => true
|
49
49
|
```
|
50
50
|
|
51
|
-
Find all sub-strings that belong to a character set within a String:
|
52
|
-
|
53
|
-
```ruby
|
54
|
-
ls = File.read('/bin/ls')
|
55
|
-
Chars.printable.strings_in(ls)
|
56
|
-
# => ["/lib64/ld-linux-x86-64.so.2", "KIq/", "5J~!", "%L~!", ...]
|
57
|
-
```
|
58
|
-
|
59
51
|
Return a random character from the set of all characters:
|
60
52
|
|
61
53
|
```ruby
|
@@ -85,6 +77,14 @@ Chars.all.random_string(10)
|
|
85
77
|
# => "\xc2h\xad\xccm7\x1e6J\x13"
|
86
78
|
```
|
87
79
|
|
80
|
+
Generate a secure password:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
require 'securerandom'
|
84
|
+
Chars.visible.random_string(10..14, random: SecureRandom)
|
85
|
+
# => ".*$X=D*XK2h8gC"
|
86
|
+
```
|
87
|
+
|
88
88
|
Return a random String with a random length between 5 and 10, from the
|
89
89
|
set of space characters:
|
90
90
|
|
@@ -93,6 +93,57 @@ Chars.space.random_string(5..10)
|
|
93
93
|
# => "\r\v\n\t\n\f"
|
94
94
|
```
|
95
95
|
|
96
|
+
Find all sub-strings that belong to a character set within a String:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
ls = File.binread('/bin/ls')
|
100
|
+
Chars.printable.substrings(ls)
|
101
|
+
# =>
|
102
|
+
# ["/lib64/ld-linux-x86-64.so.2",
|
103
|
+
# "_ITM_deregisterTMCloneTable",
|
104
|
+
# "__gmon_start__",
|
105
|
+
# "_ITM_registerTMCloneTable",
|
106
|
+
# ...
|
107
|
+
# ]
|
108
|
+
```
|
109
|
+
|
110
|
+
Find all sub-strings that belong to a character set within a String, with
|
111
|
+
indexes:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
ls = File.binread('/bin/ls')
|
115
|
+
Chars.printable.substrings_with_indexes(ls)
|
116
|
+
# =>
|
117
|
+
# [["/lib64/ld-linux-x86-64.so.2", 792],
|
118
|
+
# ["_ITM_deregisterTMCloneTable", 4009],
|
119
|
+
# ["__gmon_start__", 4037],
|
120
|
+
# ["_ITM_registerTMCloneTable", 4052],
|
121
|
+
# ...
|
122
|
+
# ]
|
123
|
+
```
|
124
|
+
|
125
|
+
Enumerate over all strings from a character set of a given length:
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
passwords = Chars.visible.strings_of_length(6)
|
129
|
+
passwords.each { |password| puts password }
|
130
|
+
# AAAAAA
|
131
|
+
# AAAAAB
|
132
|
+
# AAAAAC
|
133
|
+
# ...
|
134
|
+
```
|
135
|
+
|
136
|
+
Enumerate over all strings from a character set of lengths between 4 and 8:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
passwords = Chars.visible.strings_of_length(4..8)
|
140
|
+
passwords.each { |password| puts password }
|
141
|
+
# AAAA
|
142
|
+
# AAAB
|
143
|
+
# AAAC
|
144
|
+
# ...
|
145
|
+
```
|
146
|
+
|
96
147
|
## Requirements
|
97
148
|
|
98
149
|
* [ruby](https://www.ruby-lang.org/) >= 2.0.0
|
@@ -104,13 +155,13 @@ Chars.space.random_string(5..10)
|
|
104
155
|
### gemspec
|
105
156
|
|
106
157
|
```ruby
|
107
|
-
gem.add_dependency 'chars', '~> 0.
|
158
|
+
gem.add_dependency 'chars', '~> 0.3'
|
108
159
|
```
|
109
160
|
|
110
161
|
### Gemfile
|
111
162
|
|
112
163
|
```ruby
|
113
|
-
gem 'chars', '~> 0.
|
164
|
+
gem 'chars', '~> 0.3'
|
114
165
|
```
|
115
166
|
|
116
167
|
## Crystal
|
data/benchmarks/compare.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(__dir__,'..','lib')))
|
4
|
+
|
5
|
+
require 'chars'
|
6
|
+
require 'benchmark'
|
7
|
+
|
8
|
+
CHARSET = Chars::ALPHA_NUMERIC
|
9
|
+
STRING = File.binread('/usr/bin/openssl')
|
10
|
+
|
11
|
+
Benchmark.bm(41) do |b|
|
12
|
+
b.report('Chars::CharSet#each_substring_with_index') do
|
13
|
+
CHARSET.each_substring_with_index(STRING) { |string,index| }
|
14
|
+
end
|
15
|
+
|
16
|
+
b.report('Chars::CharSet#each_substring') do
|
17
|
+
CHARSET.each_substring(STRING) { |string| }
|
18
|
+
end
|
19
|
+
|
20
|
+
(5..20).step(5) do |n|
|
21
|
+
b.report("Chars::CharSet#each_substring (length=#{n})") do
|
22
|
+
CHARSET.strings_in(STRING, :length => n) { |offset,string| }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/gemspec.yml
CHANGED
@@ -15,6 +15,7 @@ metadata:
|
|
15
15
|
source_code_uri: https://github.com/postmodern/chars.rb
|
16
16
|
bug_tracker_uri: https://github.com/postmodern/chars.rb/issues
|
17
17
|
changelog_uri: https://github.com/postmodern/chars.rb/blob/master/ChangeLog.md
|
18
|
+
rubygems_mfa_required: 'true'
|
18
19
|
|
19
20
|
required_ruby_version: ">= 2.0.0"
|
20
21
|
|