chars 0.2.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +1 -1
- data/.gemspec +0 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +8 -0
- data/.yardopts +1 -1
- data/ChangeLog.md +30 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +1 -1
- data/README.md +79 -46
- data/Rakefile +7 -30
- data/benchmarks/compare.rb +16 -0
- data/benchmarks/strings_in.rb +23 -0
- data/chars.gemspec +58 -7
- data/gemspec.yml +10 -4
- data/lib/chars/char_set.rb +193 -94
- data/lib/chars/chars.rb +78 -38
- data/lib/chars/extensions/integer.rb +51 -34
- data/lib/chars/extensions/string.rb +34 -17
- data/lib/chars/version.rb +2 -2
- data/spec/char_set_spec.rb +236 -133
- data/spec/chars_spec.rb +14 -73
- data/spec/{integer_spec.rb → extensions/integer_spec.rb} +19 -20
- data/spec/{string_spec.rb → extensions/string_spec.rb} +20 -19
- data/spec/spec_helper.rb +0 -1
- metadata +56 -98
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6257e8d2fa2f62cc364fc2e0ba901d777963476968264dd7747bc4407e5ff54c
|
4
|
+
data.tar.gz: 16f5ecc2f44e8265869aac4946a64cacda2ae8dcdae3b669081a48d34f034f4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ebaf16c18de6b000b6219bf4afe7142926e24293b6b1e62214f937c51c5bdf7f5ffa7f46eecb151e1da044f7b49e1479b7d2cc947a6e20fa2a586f28b4a8a525
|
7
|
+
data.tar.gz: 4c9c98dcbab77b201b86fc32a628575e4b0ebc03608c50c7591b51a70821127778ced5122f57de846c7c863440fa0e9555fe7bfd2940a913e494a929c74a513e
|
data/.document
CHANGED
data/.gemspec
ADDED
File without changes
|
@@ -0,0 +1,28 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [ push, pull_request ]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
tests:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
ruby:
|
12
|
+
- 2.4
|
13
|
+
- 2.5
|
14
|
+
- 2.6
|
15
|
+
- 2.7
|
16
|
+
- 3.0
|
17
|
+
- jruby
|
18
|
+
name: Ruby ${{ matrix.ruby }}
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
- name: Install dependencies
|
26
|
+
run: bundle install --jobs 4 --retry 3
|
27
|
+
- name: Run tests
|
28
|
+
run: bundle exec rake test
|
data/.gitignore
ADDED
data/.yardopts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--markup markdown --title 'Chars Documentation' --protected --
|
1
|
+
--markup markdown --title 'Chars Documentation' --protected --quiet
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
### 0.2.4 / 2021-10-22
|
2
|
+
|
3
|
+
* Require [ruby] >= 2.0.0.
|
4
|
+
* Added {Chars::CharSet#initialize_copy} to prevent leaking characters
|
5
|
+
between copied {Chars::CharSet} objects.
|
6
|
+
|
7
|
+
### 0.2.3 / 2020-12-25
|
8
|
+
|
9
|
+
* Change {Chars::CharSet} to inherit from `Set`, instead of `SortedSet`.
|
10
|
+
|
11
|
+
### 0.2.2 / 2012-05-28
|
12
|
+
|
13
|
+
* {Chars::CharSet#initialize} now raises a TypeError when given arguments
|
14
|
+
that were neither a `String`, `Integer` or `Enumerable`.
|
15
|
+
* Allow {Chars::CharSet#strings_in} to yield results as they are found.
|
16
|
+
* Improved the performance of {Chars::CharSet#strings_in} when operating on
|
17
|
+
small Strings.
|
18
|
+
* Replaced ore-tasks with
|
19
|
+
[rubygems-tasks](https://github.com/postmodern/rubygems-tasks#readme).
|
20
|
+
|
21
|
+
### 0.2.1 / 2011-06-22
|
22
|
+
|
23
|
+
* Added {Chars::CharSet.[]}
|
24
|
+
* Added {Chars::CharSet#<<}.
|
25
|
+
* Added {Chars::CharSet#byte_to_char}.
|
26
|
+
* Added {Chars::CharSet#char_to_byte}.
|
27
|
+
* Added a cache of characters of the bytes within {Chars::CharSet}.
|
28
|
+
* Use `String#each_char` to distinguish Unicode from ASCII.
|
29
|
+
|
1
30
|
### 0.2.0 / 2010-10-27
|
2
31
|
|
3
32
|
* Make sure all enumerable methods in {Chars::CharSet} return an
|
@@ -43,3 +72,4 @@
|
|
43
72
|
belongs to a certain character set.
|
44
73
|
* Supports random text generation using specific character sets.
|
45
74
|
|
75
|
+
[ruby]: https://www.ruby-lang.org/
|
data/Gemfile
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Chars
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
*
|
3
|
+
[![CI](https://github.com/postmodern/chars.rb/actions/workflows/ruby.yml/badge.svg)](https://github.com/postmodern/chars.rb/actions/workflows/ruby.yml)
|
4
|
+
|
5
|
+
* [Source](https://github.com/postmodern/chars.rb#readme)
|
6
|
+
* [Issues](https://github.com/postmodern/chars.rb/issues)
|
7
|
+
* [Documentation](https://rubydoc.info/gems/chars)
|
6
8
|
|
7
9
|
## Description
|
8
10
|
|
@@ -12,80 +14,111 @@ recognizing text and generating random text from specific character sets.
|
|
12
14
|
## Features
|
13
15
|
|
14
16
|
* Provides character sets for:
|
15
|
-
* Numeric
|
16
|
-
* Octal
|
17
|
-
* Uppercase Hexadecimal
|
18
|
-
* Lowercase Hexadecimal
|
19
|
-
* Hexadecimal
|
20
|
-
* Uppercase Alpha
|
21
|
-
* Lowercase Alpha
|
22
|
-
* Alpha
|
23
|
-
* Alpha-numeric
|
24
|
-
* Punctuation
|
25
|
-
|
26
|
-
*
|
27
|
-
|
28
|
-
|
29
|
-
*
|
30
|
-
*
|
31
|
-
|
32
|
-
'#', '$', '%', '^', '&', '*', '_', '+', '=', '|', '\\', '<', '>', '/',)
|
33
|
-
* Printable ('0' - '9', 'a' - 'z', 'A' - 'Z', ' ', '\'', '"', '`', ',',
|
34
|
-
';', ':', '~', '-', '(', ')', '[', ']', '{', '}', '.', '?', '!', '@',
|
35
|
-
'#', '$', '%', '^', '&', '*', '_', '+', '=', '|', '\\', '<', '>', '/',
|
36
|
-
'\f', '\n', '\r', '\t', '\v')
|
37
|
-
* Control ('\x00' - '\x1f', '\x7f')
|
38
|
-
* Signed ASCII ('\x00' - '\x7f')
|
39
|
-
* ASCII ('\x00' - '\xff')
|
17
|
+
* Numeric: `0` - `9`
|
18
|
+
* Octal: `0` - `7`
|
19
|
+
* Uppercase Hexadecimal: `0` - `9`, `A` - `F`
|
20
|
+
* Lowercase Hexadecimal: `0` - `9`, `a` - `f`
|
21
|
+
* Hexadecimal: `0` - `9`, `a` - `f`, `A` - `F`
|
22
|
+
* Uppercase Alpha: `A` - `Z`
|
23
|
+
* Lowercase Alpha: `a` - `z`
|
24
|
+
* Alpha: `a` - `z`, `A` - `Z`
|
25
|
+
* Alpha-numeric: `0` - `9`, `a` - `z`, `A` - `Z`
|
26
|
+
* Punctuation: `' '`, `'`, `"`, `` ` ``, `,`, `;`, `:`, `~`, `-`, `(`, `)`, `[`, `]`, `{`, `}`, `.`, `?`, `!`
|
27
|
+
* Symbols: `' '`, `'`, `"`, `` ` ``, `,`, `;`, `:`, `~`, `-`, `(`, `)`, `[`, `]`, `{`, `}`, `.`, `?`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, `*`, `_`, `+`, `=`, `|`, `\`, `<`, `>`, `/`
|
28
|
+
* Space: `' '`, `\f`, `\n`, `\r`, `\t`, `\v`
|
29
|
+
* Visible: `0` - `9`, `a` - `z`, `A` - `Z`, `'`, `"`, `` ` ``, `,`, `;`, `:`, `~`, `-`, `(`, `)`, `[`, `]`, `{`, `}`, `.`, `?`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, `*`, `_`, `+`, `=`, `|`, `\`, `<`, `>`, `/`
|
30
|
+
* Printable: `0` - `9`, `a` - `z`, `A` - `Z`, `' '`, `'`, `"`, `` ` ``, `,`, `;`, `:`, `~`, `-`, `(`, `)`, `[`, `]`, `{`, `}`, `.`, `?`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, <code>*</code>, <code>_</code>, `+`, `=`, `|`, `\`, `<`, `>`, `/`, `\f`, `\n`, `\r`, `\t`, `\v`
|
31
|
+
* Control: `\x00` - `\x1f`, `\x7f`
|
32
|
+
* Signed ASCII: `\x00` - `\x7f`
|
33
|
+
* ASCII: `\x00` - `\xff`
|
40
34
|
|
41
35
|
## Examples
|
42
36
|
|
43
37
|
Determine whether a byte belongs to a character set:
|
44
38
|
|
45
|
-
|
46
|
-
|
39
|
+
```ruby
|
40
|
+
0x41.alpha?
|
41
|
+
# => true
|
42
|
+
```
|
47
43
|
|
48
44
|
Determine whether a String belongs to a character set:
|
49
45
|
|
50
|
-
|
51
|
-
|
46
|
+
```ruby
|
47
|
+
"22e1c0".hex?
|
48
|
+
# => true
|
49
|
+
```
|
52
50
|
|
53
51
|
Find all sub-strings that belong to a character set within a String:
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
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
58
|
|
59
59
|
Return a random character from the set of all characters:
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
```ruby
|
62
|
+
Chars.all.random_char
|
63
|
+
# => "\x94"
|
64
|
+
```
|
63
65
|
|
64
66
|
Return a random Array of characters from the alpha-numeric character set:
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
+
```ruby
|
69
|
+
Chars.alpha_numeric.random_chars(10)
|
70
|
+
# => ["Q", "N", "S", "4", "x", "z", "3", "M", "F", "F"]
|
71
|
+
```
|
68
72
|
|
69
73
|
Return a random Array of a random length of unique characters from the
|
70
74
|
visible character set:
|
71
75
|
|
72
|
-
|
73
|
-
|
76
|
+
```ruby
|
77
|
+
Chars.visible.random_distinct_chars(1..10)
|
78
|
+
# => ["S", "l", "o", "8", "'", "q"]
|
79
|
+
```
|
74
80
|
|
75
81
|
Return a random String from the set of all characters:
|
76
82
|
|
77
|
-
|
78
|
-
|
83
|
+
```ruby
|
84
|
+
Chars.all.random_string(10)
|
85
|
+
# => "\xc2h\xad\xccm7\x1e6J\x13"
|
86
|
+
```
|
79
87
|
|
80
88
|
Return a random String with a random length between 5 and 10, from the
|
81
89
|
set of space characters:
|
82
90
|
|
83
|
-
|
84
|
-
|
91
|
+
```ruby
|
92
|
+
Chars.space.random_string(5..10)
|
93
|
+
# => "\r\v\n\t\n\f"
|
94
|
+
```
|
95
|
+
|
96
|
+
## Requirements
|
97
|
+
|
98
|
+
* [ruby](https://www.ruby-lang.org/) >= 2.0.0
|
85
99
|
|
86
100
|
## Install
|
87
101
|
|
88
|
-
$
|
102
|
+
$ gem install chars
|
103
|
+
|
104
|
+
### gemspec
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
gem.add_dependency 'chars', '~> 0.2'
|
108
|
+
```
|
109
|
+
|
110
|
+
### Gemfile
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
gem 'chars', '~> 0.2'
|
114
|
+
```
|
115
|
+
|
116
|
+
## Crystal
|
117
|
+
|
118
|
+
[chars.cr] is a [Crystal] port of this library.
|
119
|
+
|
120
|
+
[chars.cr]: https://github.com/postmodern/chars.cr
|
121
|
+
[Crystal]: https://crystal-lang.org/
|
89
122
|
|
90
123
|
## License
|
91
124
|
|
data/Rakefile
CHANGED
@@ -1,35 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'rake'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
require 'ore/tasks'
|
3
|
+
require 'rubygems/tasks'
|
4
|
+
Gem::Tasks.new
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
STDERR.puts "Run `gem install ore-tasks` to install 'ore/tasks'."
|
12
|
-
end
|
13
|
-
|
14
|
-
begin
|
15
|
-
gem 'rspec', '~> 2.0.0'
|
16
|
-
require 'rspec/core/rake_task'
|
17
|
-
|
18
|
-
RSpec::Core::RakeTask.new
|
19
|
-
rescue LoadError => e
|
20
|
-
task :spec do
|
21
|
-
abort "Please run `gem install rspec` to install RSpec."
|
22
|
-
end
|
23
|
-
end
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
task :test => :spec
|
24
9
|
task :default => :spec
|
25
10
|
|
26
|
-
|
27
|
-
|
28
|
-
require 'yard'
|
29
|
-
|
30
|
-
YARD::Rake::YardocTask.new
|
31
|
-
rescue LoadError => e
|
32
|
-
task :yard do
|
33
|
-
abort "Please run `gem install yard` to install YARD."
|
34
|
-
end
|
35
|
-
end
|
11
|
+
require 'yard'
|
12
|
+
YARD::Rake::YardocTask.new
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
|
4
|
+
|
5
|
+
require 'chars'
|
6
|
+
require 'benchmark'
|
7
|
+
|
8
|
+
CHARSET = Chars::ALPHA_NUMERIC
|
9
|
+
N = 1_000_000
|
10
|
+
STRING = ('A' * N) + '!'
|
11
|
+
ENUM = (['A', 0x42] * (N / 2)) << '!'
|
12
|
+
|
13
|
+
Benchmark.bm(12) do |b|
|
14
|
+
b.report('String') { CHARSET === STRING }
|
15
|
+
b.report('Enumerable') { CHARSET === ENUM }
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
|
4
|
+
|
5
|
+
require 'chars'
|
6
|
+
require 'benchmark'
|
7
|
+
|
8
|
+
CHARSET = Chars::ALPHA_NUMERIC
|
9
|
+
STRING = File.open('/usr/bin/openssl','rb') do |file|
|
10
|
+
file.read
|
11
|
+
end
|
12
|
+
|
13
|
+
Benchmark.bm(24) do |b|
|
14
|
+
b.report('strings_in') do
|
15
|
+
CHARSET.strings_in(STRING) { |offset,string| }
|
16
|
+
end
|
17
|
+
|
18
|
+
(5..20).step(5) do |n|
|
19
|
+
b.report("strings_in (length=#{n})") do
|
20
|
+
CHARSET.strings_in(STRING, :length => n) { |offset,string| }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/chars.gemspec
CHANGED
@@ -1,10 +1,61 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gemspec = YAML.load_file('gemspec.yml')
|
7
|
+
|
8
|
+
gem.name = gemspec.fetch('name')
|
9
|
+
gem.version = gemspec.fetch('version') do
|
10
|
+
lib_dir = File.join(File.dirname(__FILE__),'lib')
|
11
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
12
|
+
|
13
|
+
require 'chars/version'
|
14
|
+
Chars::VERSION
|
15
|
+
end
|
16
|
+
|
17
|
+
gem.summary = gemspec['summary']
|
18
|
+
gem.description = gemspec['description']
|
19
|
+
gem.licenses = Array(gemspec['license'])
|
20
|
+
gem.authors = Array(gemspec['authors'])
|
21
|
+
gem.email = gemspec['email']
|
22
|
+
gem.homepage = gemspec['homepage']
|
23
|
+
gem.metadata = gemspec['metadata'] if gemspec['metadata']
|
24
|
+
|
25
|
+
glob = lambda { |patterns| gem.files & Dir[*patterns] }
|
26
|
+
|
27
|
+
gem.files = `git ls-files`.split($/)
|
28
|
+
gem.files = glob[gemspec['files']] if gemspec['files']
|
29
|
+
|
30
|
+
gem.executables = gemspec.fetch('executables') do
|
31
|
+
glob['bin/*'].map { |path| File.basename(path) }
|
32
|
+
end
|
33
|
+
gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
|
34
|
+
|
35
|
+
gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
|
36
|
+
gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
|
37
|
+
gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
|
38
|
+
|
39
|
+
gem.require_paths = Array(gemspec.fetch('require_paths') {
|
40
|
+
%w[ext lib].select { |dir| File.directory?(dir) }
|
41
|
+
})
|
42
|
+
|
43
|
+
gem.requirements = gemspec['requirements']
|
44
|
+
gem.required_ruby_version = gemspec['required_ruby_version']
|
45
|
+
gem.required_rubygems_version = gemspec['required_rubygems_version']
|
46
|
+
gem.post_install_message = gemspec['post_install_message']
|
47
|
+
|
48
|
+
split = lambda { |string| string.split(/,\s*/) }
|
49
|
+
|
50
|
+
if gemspec['dependencies']
|
51
|
+
gemspec['dependencies'].each do |name,versions|
|
52
|
+
gem.add_dependency(name,split[versions])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if gemspec['development_dependencies']
|
57
|
+
gemspec['development_dependencies'].each do |name,versions|
|
58
|
+
gem.add_development_dependency(name,split[versions])
|
59
|
+
end
|
6
60
|
end
|
7
|
-
rescue NameError
|
8
|
-
STDERR.puts "The 'chars.gemspec' file requires Ore."
|
9
|
-
STDERR.puts "Run `gem install ore` to install Ore."
|
10
61
|
end
|
data/gemspec.yml
CHANGED
@@ -5,12 +5,18 @@ description:
|
|
5
5
|
recognizing text and generating random text from specific character sets.
|
6
6
|
|
7
7
|
license: MIT
|
8
|
-
homepage:
|
8
|
+
homepage: https://github.com/postmodern/chars.rb#readme
|
9
9
|
authors: Postmodern
|
10
10
|
email: postmodern.mod3@gmail.com
|
11
11
|
has_yard: true
|
12
12
|
|
13
|
+
metadata:
|
14
|
+
documentation_uri: https://rubydoc.info/gems/chars
|
15
|
+
source_code_uri: https://github.com/postmodern/chars.rb
|
16
|
+
bug_tracker_uri: https://github.com/postmodern/chars.rb/issues
|
17
|
+
changelog_uri: https://github.com/postmodern/chars.rb/blob/master/ChangeLog.md
|
18
|
+
|
19
|
+
required_ruby_version: ">= 2.0.0"
|
20
|
+
|
13
21
|
development_dependencies:
|
14
|
-
|
15
|
-
ore-tasks: ~> 0.1.2
|
16
|
-
rspec: ~> 2.0.0
|
22
|
+
bundler: ~> 2.0
|