chars 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b408bb91d6c66422ccb57e66af6cdeceeb97d50c610628a9b99780319f4af57
4
- data.tar.gz: '039bef18f59a8ea05fd2a259839432e9ad2eee15c692969bf611d11b15255b75'
3
+ metadata.gz: 56d15d9a339ad8d7a1106fcf031445010e73eca3c86184baf9d793d7c1765ce2
4
+ data.tar.gz: 75f7ce1ecfba11f41bcc64d26900d5da05a0cf30a0fcca4100cf6e3b6967f1e8
5
5
  SHA512:
6
- metadata.gz: 803264ba7bafc4546df334bd2a508389f525c9814ab0452ef7b2b7c9b75cc0fb952c729f0b5b093cbede36d60be5badeb29ada0e29ee5b12ae3d681878aeb163
7
- data.tar.gz: 2e9f1c229d9987e5cb1dfc0caada8c71582e0c72e8c03e7b39313c4bc1e9e447bdbdfcf641009174de47b4e0e94384296dc26cf8a136f72881bfd664fa311720
6
+ metadata.gz: ac159bcca8f06abaf6962a1d0c7b693fea39202bcce3426cd72baea4cbba4650cabbbf0cdc0147031ba71752f359c8659def748b3462454ac8fe992150b0de83
7
+ data.tar.gz: f8b148a08e9dd8b2f8b087b3cb88896e66c138460a317a591f9c3088e02129945b0a836f3f37c0894e86ad6f064a7cf747807efcc54df9712e51e5a034069d5e
@@ -9,15 +9,15 @@ jobs:
9
9
  fail-fast: false
10
10
  matrix:
11
11
  ruby:
12
- - '2.6'
13
- - '2.7'
14
12
  - '3.0'
15
13
  - '3.1'
14
+ - '3.2'
15
+ - '3.3'
16
16
  - jruby
17
17
  - truffleruby
18
18
  name: Ruby ${{ matrix.ruby }}
19
19
  steps:
20
- - uses: actions/checkout@v2
20
+ - uses: actions/checkout@v4
21
21
  - name: Set up Ruby
22
22
  uses: ruby/setup-ruby@v1
23
23
  with:
data/.yardopts CHANGED
@@ -1 +1 @@
1
- --markup markdown --title 'Chars Documentation' --protected --quiet
1
+ --markup markdown --title 'Chars Documentation' --protected
data/ChangeLog.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### 0.3.3 / 2024-01-23
2
+
3
+ * Switch to using `require_relative` to improve load-times.
4
+
5
+ ### 0.3.2 / 2022-12-02
6
+
7
+ * Ensure all character Strings within the {Chars} character sets are encoded as
8
+ ASCII-8bit. This prevents transcoding issues when calling
9
+ `Chars::ASCII.random_string(length)`.
10
+ * Changed {Chars::CharSet#initialize} to encode bytes greater than 256 as UTF-8.
11
+ Otherwise, bytes less than 256 will be encoded as ASCII-8bit.
12
+
1
13
  ### 0.3.1 / 2022-12-01
2
14
 
3
15
  * Removed the space character from {Chars::PUNCTUATION}, as spaces are not
@@ -42,8 +54,8 @@
42
54
 
43
55
  * Added {Chars::CharSet.[]}
44
56
  * Added {Chars::CharSet#<<}.
45
- * Added {Chars::CharSet#byte_to_char}.
46
- * Added {Chars::CharSet#char_to_byte}.
57
+ * Added `Chars::CharSet#byte_to_char`.
58
+ * Added `Chars::CharSet#char_to_byte`.
47
59
  * Added a cache of characters of the bytes within {Chars::CharSet}.
48
60
  * Use `String#each_char` to distinguish Unicode from ASCII.
49
61
 
@@ -57,10 +69,10 @@
57
69
  * Require `hoe` >= 2.3.3.
58
70
  * Require `yard` >= 0.2.3.5.
59
71
  * Require `rspec` >= 1.2.8.
60
- * Added {Chars.visibile} and {Chars::VISIBLE} (thanks flatline).
72
+ * Added {Chars.visible} and {Chars::VISIBLE} (thanks flatline).
61
73
  * Added {Chars::CharSet#random_distinct_bytes},
62
- {Chars::CharSet#random_distinct_chars}, and {CharSet#random_distinct_string}
63
- (thanks flatline).
74
+ {Chars::CharSet#random_distinct_chars}, and
75
+ {Chars::CharSet#random_distinct_string} (thanks flatline).
64
76
  * Use `hoe/signing` for signed RubyGems.
65
77
  * Moved to YARD based documentation.
66
78
  * All specs now pass on JRuby 1.3.1.
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2009-2021 Hal Brodigan
3
+ Copyright (c) 2009-2024 Hal Brodigan
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- require 'rubygems'
2
-
3
1
  require 'rubygems/tasks'
4
2
  Gem::Tasks.new
5
3
 
data/chars.gemspec CHANGED
@@ -7,10 +7,7 @@ Gem::Specification.new do |gem|
7
7
 
8
8
  gem.name = gemspec.fetch('name')
9
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'
10
+ require_relative 'lib/chars/version'
14
11
  Chars::VERSION
15
12
  end
16
13
 
@@ -1,4 +1,4 @@
1
- require 'chars/string_enumerator'
1
+ require_relative 'string_enumerator'
2
2
 
3
3
  require 'set'
4
4
 
@@ -17,7 +17,13 @@ module Chars
17
17
  def initialize(*arguments)
18
18
  super()
19
19
 
20
- @chars = Hash.new { |hash,key| hash[key] = key.chr(Encoding::UTF_8) }
20
+ @chars = Hash.new do |hash,key|
21
+ hash[key] = if key > 0xff
22
+ key.chr(Encoding::UTF_8)
23
+ else
24
+ key.chr(Encoding::ASCII_8BIT)
25
+ end
26
+ end
21
27
 
22
28
  arguments.each do |subset|
23
29
  case subset
@@ -574,7 +580,7 @@ module Chars
574
580
  # If no block is given, an Array or Hash of sub-strings is returned.
575
581
  #
576
582
  # @deprecated
577
- # Use {#each_substring_with_index}, {#substrings_with_index},
583
+ # Use {#each_substring_with_index}, {#substrings_with_indexes},
578
584
  # {#each_substring}, or {#substrings} instead.
579
585
  #
580
586
  def strings_in(data,options={},&block)
@@ -607,7 +613,7 @@ module Chars
607
613
  # The given block will be passed each sequential string.
608
614
  #
609
615
  # @yieldparam [String] string
610
- # A string belonging to {#char_set} and `length` long.
616
+ # A string belonging to the {CharSet} and of `length` long.
611
617
  #
612
618
  # @return [Enumerator]
613
619
  # If no block is given, an Enumerator will be returned.
@@ -629,7 +635,7 @@ module Chars
629
635
 
630
636
  #
631
637
  # Returns an Enumerator that enumerates through every possible string
632
- # belonging to the {CharSEt} and of the given length.
638
+ # belonging to the {CharSet} and of the given length.
633
639
  #
634
640
  # @param [Range, Array, Integer] length
635
641
  # The desired length(s) of each string.
@@ -650,7 +656,7 @@ module Chars
650
656
  # The other {CharSet} to union with.
651
657
  #
652
658
  # @return [CharSet]
653
- # The unioned {ChraSet}.
659
+ # The unioned {CharSet}.
654
660
  #
655
661
  def |(set)
656
662
  set = CharSet.new(set) unless set.kind_of?(CharSet)
data/lib/chars/chars.rb CHANGED
@@ -1,6 +1,7 @@
1
+ # encoding: ASCII-8BIT
1
2
  # frozen_string_literal: true
2
3
 
3
- require 'chars/char_set'
4
+ require_relative 'char_set'
4
5
 
5
6
  module Chars
6
7
  # The numeric decimal character set
@@ -1,4 +1,4 @@
1
- require 'chars/chars'
1
+ require_relative '../chars'
2
2
 
3
3
  class Integer
4
4
 
@@ -1,4 +1,4 @@
1
- require 'chars/chars'
1
+ require_relative '../chars'
2
2
 
3
3
  class String
4
4
 
@@ -1,2 +1,2 @@
1
- require 'chars/extensions/integer'
2
- require 'chars/extensions/string'
1
+ require_relative 'extensions/integer'
2
+ require_relative 'extensions/string'
data/lib/chars/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Chars
2
2
  # chars version
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.3'
4
4
  end
data/lib/chars.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'chars/char_set'
2
- require 'chars/chars'
3
- require 'chars/extensions'
4
- require 'chars/version'
1
+ require_relative 'chars/char_set'
2
+ require_relative 'chars/chars'
3
+ require_relative 'chars/extensions'
4
+ require_relative 'chars/version'
@@ -42,6 +42,18 @@ describe Chars::CharSet do
42
42
  it "must populate the char set using the Integers as bytes" do
43
43
  expect(integers.all? { |i| subject.include?(i) }).to be(true)
44
44
  end
45
+
46
+ it "must encode them as ASCII 8bit Strings" do
47
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
48
+ end
49
+
50
+ context "when one of the Integers is greater than 0xff" do
51
+ let(:integers) { [0x100, 0xffff] }
52
+
53
+ it "must encode the Integer as a UTF-8 String" do
54
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::UTF_8))
55
+ end
56
+ end
45
57
  end
46
58
 
47
59
  context "when given an Array of Integers" do
@@ -50,6 +62,18 @@ describe Chars::CharSet do
50
62
  it "must populate the char set using the Integers as bytes" do
51
63
  expect(integers.all? { |i| subject.include?(i) }).to be(true)
52
64
  end
65
+
66
+ it "must encode them as ASCII 8bit Strings" do
67
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
68
+ end
69
+
70
+ context "when one of the Integers is greater than 0xff" do
71
+ let(:integers) { [0x100, 0xffff] }
72
+
73
+ it "must encode the Integer as a UTF-8 String" do
74
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::UTF_8))
75
+ end
76
+ end
53
77
  end
54
78
 
55
79
  context "when given a Range of Integers" do
@@ -58,6 +82,18 @@ describe Chars::CharSet do
58
82
  it "must populate the char set by enumerating over the Integer's bytes" do
59
83
  expect(integers.all? { |i| subject.include?(i) }).to be(true)
60
84
  end
85
+
86
+ it "must encode them as ASCII 8bit Strings" do
87
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
88
+ end
89
+
90
+ context "when one of the Integers is greater than 0xff" do
91
+ let(:integer_range) { (0x100..0x200) }
92
+
93
+ it "must encode the Integer as a UTF-8 String" do
94
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::UTF_8))
95
+ end
96
+ end
61
97
  end
62
98
  end
63
99
 
data/spec/chars_spec.rb CHANGED
@@ -10,6 +10,10 @@ describe Chars do
10
10
  it "must contain numeric characters" do
11
11
  expect(subject.chars).to match_array(numeric_chars)
12
12
  end
13
+
14
+ it "must only contain ASCII-8bit encoded characters" do
15
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
16
+ end
13
17
  end
14
18
 
15
19
  describe "DIGITS" do
@@ -18,6 +22,10 @@ describe Chars do
18
22
  it "must equal NUMERIC" do
19
23
  expect(subject).to be(described_class::NUMERIC)
20
24
  end
25
+
26
+ it "must only contain ASCII-8bit encoded characters" do
27
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
28
+ end
21
29
  end
22
30
 
23
31
  describe "OCTAL" do
@@ -26,6 +34,10 @@ describe Chars do
26
34
  it "must contain all octal characters" do
27
35
  expect(subject.chars).to match_array("01234567".chars)
28
36
  end
37
+
38
+ it "must only contain ASCII-8bit encoded characters" do
39
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
40
+ end
29
41
  end
30
42
 
31
43
  let(:uppercase_hex_chars) { "0123456789ABCDEF".chars }
@@ -36,6 +48,10 @@ describe Chars do
36
48
  it "must contain all upper-case hexadecimal characters" do
37
49
  expect(subject.chars).to match_array(uppercase_hex_chars)
38
50
  end
51
+
52
+ it "must only contain ASCII-8bit encoded characters" do
53
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
54
+ end
39
55
  end
40
56
 
41
57
  let(:lowercase_hex_chars) { "0123456789abcdef".chars }
@@ -46,6 +62,10 @@ describe Chars do
46
62
  it "must contain all lower-case hexadecimal characters" do
47
63
  expect(subject.chars).to match_array(lowercase_hex_chars)
48
64
  end
65
+
66
+ it "must only contain ASCII-8bit encoded characters" do
67
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
68
+ end
49
69
  end
50
70
 
51
71
  describe "HEXADECIMAL" do
@@ -54,6 +74,10 @@ describe Chars do
54
74
  it "must contain both upper-case and lower-case hexadecimal characters" do
55
75
  expect(subject.chars).to match_array(uppercase_hex_chars | lowercase_hex_chars)
56
76
  end
77
+
78
+ it "must only contain ASCII-8bit encoded characters" do
79
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
80
+ end
57
81
  end
58
82
 
59
83
  let(:uppercase_alpha_chars) { "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars }
@@ -64,6 +88,10 @@ describe Chars do
64
88
  it "must contain all upper-case alpha characters" do
65
89
  expect(subject.chars).to match_array(uppercase_alpha_chars)
66
90
  end
91
+
92
+ it "must only contain ASCII-8bit encoded characters" do
93
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
94
+ end
67
95
  end
68
96
 
69
97
  let(:lowercase_alpha_chars) { "abcdefghijklmnopqrstuvwxyz".chars }
@@ -74,6 +102,10 @@ describe Chars do
74
102
  it "must contain all lower-case alpha characters" do
75
103
  expect(subject.chars).to match_array(lowercase_alpha_chars)
76
104
  end
105
+
106
+ it "must only contain ASCII-8bit encoded characters" do
107
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
108
+ end
77
109
  end
78
110
 
79
111
  let(:alpha_chars) { uppercase_alpha_chars | lowercase_alpha_chars }
@@ -84,6 +116,10 @@ describe Chars do
84
116
  it "must contain all alpha characters" do
85
117
  expect(subject.chars).to match_array(alpha_chars)
86
118
  end
119
+
120
+ it "must only contain ASCII-8bit encoded characters" do
121
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
122
+ end
87
123
  end
88
124
 
89
125
  let(:alpha_numeric_chars) { alpha_chars | numeric_chars }
@@ -94,6 +130,10 @@ describe Chars do
94
130
  it "must contain all alpha-numeric characters" do
95
131
  expect(subject.chars).to match_array(alpha_numeric_chars)
96
132
  end
133
+
134
+ it "must only contain ASCII-8bit encoded characters" do
135
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
136
+ end
97
137
  end
98
138
 
99
139
  let(:punctuation_chars) { "!\"'(),-.:;?[]`{}~".chars }
@@ -104,6 +144,10 @@ describe Chars do
104
144
  it "must contain all punctuation characters" do
105
145
  expect(subject.chars).to match_array(punctuation_chars)
106
146
  end
147
+
148
+ it "must only contain ASCII-8bit encoded characters" do
149
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
150
+ end
107
151
  end
108
152
 
109
153
  let(:symbolic_chars) { "!\"\#$%&'()*+,-./:;<=>?@[\\]^_`{|}~".chars }
@@ -114,6 +158,10 @@ describe Chars do
114
158
  it "must contain all symbolic characters" do
115
159
  expect(subject.chars).to match_array(symbolic_chars)
116
160
  end
161
+
162
+ it "must only contain ASCII-8bit encoded characters" do
163
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
164
+ end
117
165
  end
118
166
 
119
167
  let(:whitespace_chars) { "\t\n\v\f\r ".chars }
@@ -124,6 +172,10 @@ describe Chars do
124
172
  it "must contain all white-space characters" do
125
173
  expect(subject.chars).to match_array(whitespace_chars)
126
174
  end
175
+
176
+ it "must only contain ASCII-8bit encoded characters" do
177
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
178
+ end
127
179
  end
128
180
 
129
181
  describe "SPACE" do
@@ -132,6 +184,10 @@ describe Chars do
132
184
  it "must equal WHITESPACE" do
133
185
  expect(subject).to be(described_class::WHITESPACE)
134
186
  end
187
+
188
+ it "must only contain ASCII-8bit encoded characters" do
189
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
190
+ end
135
191
  end
136
192
 
137
193
  describe "VISIBLE" do
@@ -140,6 +196,10 @@ describe Chars do
140
196
  it "must contain all all alpha-numeric, symbols, and some punctuation" do
141
197
  expect(subject.chars).to match_array(alpha_numeric_chars | "!\"\#$%&'()*+,-./:;<=>?@[\\]^_`{|}~".chars)
142
198
  end
199
+
200
+ it "must only contain ASCII-8bit encoded characters" do
201
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
202
+ end
143
203
  end
144
204
 
145
205
  describe "PRINTABLE" do
@@ -153,6 +213,10 @@ describe Chars do
153
213
  [' ']
154
214
  )
155
215
  end
216
+
217
+ it "must only contain ASCII-8bit encoded characters" do
218
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
219
+ end
156
220
  end
157
221
 
158
222
  describe "CONTROL" do
@@ -161,6 +225,10 @@ describe Chars do
161
225
  it "must contain ASCII bytes 0x00 - 0x1f and 0x7f" do
162
226
  expect(subject.bytes).to eq([*0x00..0x1f, 0x7f])
163
227
  end
228
+
229
+ it "must only contain ASCII-8bit encoded characters" do
230
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
231
+ end
164
232
  end
165
233
 
166
234
  describe "SIGNED_ASCII" do
@@ -169,6 +237,10 @@ describe Chars do
169
237
  it "must contain ASCII bytes 0x00 - 0x7f" do
170
238
  expect(subject.bytes).to eq([*0x00..0x7f])
171
239
  end
240
+
241
+ it "must only contain ASCII-8bit encoded characters" do
242
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
243
+ end
172
244
  end
173
245
 
174
246
  describe "ASCII" do
@@ -177,6 +249,10 @@ describe Chars do
177
249
  it "must contain ASCII bytes 0x00 - 0xff" do
178
250
  expect(subject.bytes).to eq([*0x00..0xff])
179
251
  end
252
+
253
+ it "must only contain ASCII-8bit encoded characters" do
254
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
255
+ end
180
256
  end
181
257
 
182
258
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-01 00:00:00.000000000 Z
11
+ date: 2024-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 3.3.7
90
+ rubygems_version: 3.4.10
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: A Ruby library for working with various character sets