chars 0.2.3 → 0.2.4

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: a22fd4d88e24c4f378880de5e324ac4acc4ff197c541baa1b840a8852d420afa
4
- data.tar.gz: ad9c7a38b080490366aaf4142eb642224d551da165ddeedfb4fc1fd0e6bf0728
3
+ metadata.gz: 6257e8d2fa2f62cc364fc2e0ba901d777963476968264dd7747bc4407e5ff54c
4
+ data.tar.gz: 16f5ecc2f44e8265869aac4946a64cacda2ae8dcdae3b669081a48d34f034f4e
5
5
  SHA512:
6
- metadata.gz: 5886283079f3bfcf060facf0b0520a51f75066b0301a87750d262e1e4326fad164e541c9580aad1a3f86810430732b2e1933b2ccee26eda6667d0da2aaf2bf00
7
- data.tar.gz: 0313dcedc0872cc15f84804bdea985bf726040b48d48018084800c8e07f4224267b5802df4da9d68c5ce79ff0239e4af7138db522fa8523647251524d51e6ba1
6
+ metadata.gz: ebaf16c18de6b000b6219bf4afe7142926e24293b6b1e62214f937c51c5bdf7f5ffa7f46eecb151e1da044f7b49e1479b7d2cc947a6e20fa2a586f28b4a8a525
7
+ data.tar.gz: 4c9c98dcbab77b201b86fc32a628575e4b0ebc03608c50c7591b51a70821127778ced5122f57de846c7c863440fa0e9555fe7bfd2940a913e494a929c74a513e
data/ChangeLog.md CHANGED
@@ -1,3 +1,9 @@
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
+
1
7
  ### 0.2.3 / 2020-12-25
2
8
 
3
9
  * Change {Chars::CharSet} to inherit from `Set`, instead of `SortedSet`.
@@ -66,3 +72,4 @@
66
72
  belongs to a certain character set.
67
73
  * Supports random text generation using specific character sets.
68
74
 
75
+ [ruby]: https://www.ruby-lang.org/
data/Gemfile CHANGED
@@ -8,4 +8,5 @@ group :development do
8
8
  gem 'rspec', '~> 3.0'
9
9
  gem 'kramdown'
10
10
  gem 'yard', '~> 0.9'
11
+ gem 'yard-spellcheck', require: false
11
12
  end
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2009-2012 Hal Brodigan
3
+ Copyright (c) 2009-2021 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/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Chars
2
2
 
3
- * [Source](https://github.com/postmodern/chars#readme)
4
- * [Issues](https://github.com/postmodern/chars/issues)
5
- * [Documentation](http://rubydoc.info/gems/chars)
6
- * [Email](mailto:postmodern.mod3 at gmail.com)
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)
7
8
 
8
9
  ## Description
9
10
 
@@ -13,84 +14,111 @@ recognizing text and generating random text from specific character sets.
13
14
  ## Features
14
15
 
15
16
  * Provides character sets for:
16
- * Numeric ('0' - '9')
17
- * Octal ('0' - '7')
18
- * Uppercase Hexadecimal ('0' - '9', 'A' - 'F')
19
- * Lowercase Hexadecimal ('0' - '9', 'a' - 'f')
20
- * Hexadecimal ('0' - '9', 'a' - 'f', 'A' - 'F')
21
- * Uppercase Alpha ('A' - 'Z')
22
- * Lowercase Alpha ('a' - 'z')
23
- * Alpha ('a' - 'z', 'A' - 'Z')
24
- * Alpha-numeric ('0' - '9', 'a' - 'z', 'A' - 'Z')
25
- * Punctuation (' ', '\'', '"', '`', ',', ';', ':', '~', '-', '(', ')',
26
- '[', ']', '{', '}', '.', '?', '!')
27
- * Symbols (' ', '\'', '"', '`', ',', ';', ':', '~', '-', '(', ')',
28
- '[', ']', '{', '}', '.', '?', '!', '@', '#', '$', '%', '^', '&', '*',
29
- '_', '+', '=', '|', '\\', '<', '>', '/')
30
- * Space (' ', '\f', '\n', '\r', '\t', '\v')
31
- * Visible ('0' - '9', 'a' - 'z', 'A' - 'Z', '\'', '"', '`', ',',
32
- ';', ':', '~', '-', '(', ')', '[', ']', '{', '}', '.', '?', '!', '@',
33
- '#', '$', '%', '^', '&', '*', '_', '+', '=', '|', '\\', '<', '>', '/',)
34
- * Printable ('0' - '9', 'a' - 'z', 'A' - 'Z', ' ', '\'', '"', '`', ',',
35
- ';', ':', '~', '-', '(', ')', '[', ']', '{', '}', '.', '?', '!', '@',
36
- '#', '$', '%', '^', '&', '*', '_', '+', '=', '|', '\\', '<', '>', '/',
37
- '\f', '\n', '\r', '\t', '\v')
38
- * Control ('\x00' - '\x1f', '\x7f')
39
- * Signed ASCII ('\x00' - '\x7f')
40
- * 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`
41
34
 
42
35
  ## Examples
43
36
 
44
37
  Determine whether a byte belongs to a character set:
45
38
 
46
- 0x41.alpha?
47
- # => true
39
+ ```ruby
40
+ 0x41.alpha?
41
+ # => true
42
+ ```
48
43
 
49
44
  Determine whether a String belongs to a character set:
50
45
 
51
- "22e1c0".hex?
52
- # => true
46
+ ```ruby
47
+ "22e1c0".hex?
48
+ # => true
49
+ ```
53
50
 
54
51
  Find all sub-strings that belong to a character set within a String:
55
52
 
56
- ls = File.read('/bin/ls')
57
- Chars.printable.strings_in(ls)
58
- # => ["/lib64/ld-linux-x86-64.so.2", "KIq/", "5J~!", "%L~!", ...]
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
+ ```
59
58
 
60
59
  Return a random character from the set of all characters:
61
60
 
62
- Chars.all.random_char
63
- # => "\x94"
61
+ ```ruby
62
+ Chars.all.random_char
63
+ # => "\x94"
64
+ ```
64
65
 
65
66
  Return a random Array of characters from the alpha-numeric character set:
66
67
 
67
- Chars.alpha_numeric.random_chars(10)
68
- # => ["Q", "N", "S", "4", "x", "z", "3", "M", "F", "F"]
68
+ ```ruby
69
+ Chars.alpha_numeric.random_chars(10)
70
+ # => ["Q", "N", "S", "4", "x", "z", "3", "M", "F", "F"]
71
+ ```
69
72
 
70
73
  Return a random Array of a random length of unique characters from the
71
74
  visible character set:
72
75
 
73
- Chars.visible.random_distinct_chars(1..10)
74
- # => ["S", "l", "o", "8", "'", "q"]
76
+ ```ruby
77
+ Chars.visible.random_distinct_chars(1..10)
78
+ # => ["S", "l", "o", "8", "'", "q"]
79
+ ```
75
80
 
76
81
  Return a random String from the set of all characters:
77
82
 
78
- Chars.all.random_string(10)
79
- # => "\xc2h\xad\xccm7\x1e6J\x13"
83
+ ```ruby
84
+ Chars.all.random_string(10)
85
+ # => "\xc2h\xad\xccm7\x1e6J\x13"
86
+ ```
80
87
 
81
88
  Return a random String with a random length between 5 and 10, from the
82
89
  set of space characters:
83
90
 
84
- Chars.space.random_string(5..10)
85
- # => "\r\v\n\t\n\f"
91
+ ```ruby
92
+ Chars.space.random_string(5..10)
93
+ # => "\r\v\n\t\n\f"
94
+ ```
86
95
 
87
96
  ## Requirements
88
97
 
89
- * [ruby](http://www.ruby-lang.org/) >= 1.8.7
98
+ * [ruby](https://www.ruby-lang.org/) >= 2.0.0
90
99
 
91
100
  ## Install
92
101
 
93
- $ sudo gem install chars
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/
94
122
 
95
123
  ## License
96
124
 
data/Rakefile CHANGED
@@ -9,4 +9,4 @@ task :test => :spec
9
9
  task :default => :spec
10
10
 
11
11
  require 'yard'
12
- YARD::Rake::YardocTask.new
12
+ YARD::Rake::YardocTask.new
data/chars.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.authors = Array(gemspec['authors'])
21
21
  gem.email = gemspec['email']
22
22
  gem.homepage = gemspec['homepage']
23
+ gem.metadata = gemspec['metadata'] if gemspec['metadata']
23
24
 
24
25
  glob = lambda { |patterns| gem.files & Dir[*patterns] }
25
26
 
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: https://github.com/postmodern/chars#readme
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
- required_ruby_version: ">= 1.8.7"
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"
14
20
 
15
21
  development_dependencies:
16
22
  bundler: ~> 2.0
@@ -15,7 +15,7 @@ module Chars
15
15
  def initialize(*arguments)
16
16
  super()
17
17
 
18
- @chars = Hash.new { |hash,key| hash[key] = byte_to_char(key) }
18
+ @chars = Hash.new { |hash,key| hash[key] = key.chr(Encoding::UTF_8) }
19
19
 
20
20
  arguments.each do |subset|
21
21
  case subset
@@ -28,9 +28,19 @@ module Chars
28
28
  end
29
29
  end
30
30
  end
31
-
31
+
32
+ #
33
+ # Initializes the copy of another {CharSet} object.
34
+ #
35
+ # @param [CharSet] other
36
+ # The other {CharSet} object.
32
37
  #
33
- # Creates a new character set.
38
+ def initialize_copy(other)
39
+ @chars = other.instance_variable_get('@chars').dup
40
+ end
41
+
42
+ #
43
+ # Creates a new {CharSet}.
34
44
  #
35
45
  # @see #initialize
36
46
  #
@@ -58,7 +68,7 @@ module Chars
58
68
  case other
59
69
  when String
60
70
  other.each_char do |char|
61
- byte = char_to_byte(char)
71
+ byte = char.ord
62
72
 
63
73
  @chars[byte] = char
64
74
  super(byte)
@@ -79,42 +89,42 @@ module Chars
79
89
  alias map_bytes map
80
90
 
81
91
  #
82
- # Determines if a character is contained within the character set.
92
+ # Determines if a character is contained within the {CharSet}.
83
93
  #
84
94
  # @param [String] char
85
95
  # The character to search for.
86
96
  #
87
97
  # @return [Boolean]
88
98
  # Specifies whether the character is contained within the
89
- # character set.
99
+ # {CharSet}.
90
100
  #
91
101
  def include_char?(char)
92
102
  unless char.empty?
93
- @chars.has_value?(char) || include_byte?(char_to_byte(char))
103
+ @chars.has_value?(char) || include_byte?(char.ord)
94
104
  else
95
105
  false
96
106
  end
97
107
  end
98
108
 
99
109
  #
100
- # The characters within the character set.
110
+ # The characters within the {CharSet}.
101
111
  #
102
112
  # @return [Array<String>]
103
- # All the characters within the character set.
113
+ # All the characters within the {CharSet}.
104
114
  #
105
115
  def chars
106
116
  map { |byte| @chars[byte] }
107
117
  end
108
118
 
109
119
  #
110
- # Iterates over every character within the character set.
120
+ # Iterates over every character within the {CharSet}.
111
121
  #
112
122
  # @yield [char]
113
123
  # If a block is given, it will be passed each character in the
114
- # character set.
124
+ # {CharSet}.
115
125
  #
116
126
  # @yieldparam [String] char
117
- # Each character in the character set.
127
+ # Each character in the {CharSet}.
118
128
  #
119
129
  # @return [Enumerator]
120
130
  # If no block is given, an enumerator object will be returned.
@@ -126,50 +136,54 @@ module Chars
126
136
  end
127
137
 
128
138
  #
129
- # Selects characters from the character set.
139
+ # Selects characters from the {CharSet}.
130
140
  #
131
141
  # @yield [char]
132
142
  # If a block is given, it will be used to select the characters
133
- # from the character set.
143
+ # from the {CharSet}.
134
144
  #
135
145
  # @yieldparam [String] char
136
146
  # The character to select or reject.
137
147
  #
138
148
  # @return [Array<String>]
139
- # The selected characters from the character set.
149
+ # The selected characters from the {CharSet}.
140
150
  #
141
151
  def select_chars(&block)
142
152
  each_char.select(&block)
143
153
  end
144
154
 
145
155
  #
146
- # Maps the characters of the character set.
156
+ # Maps the characters of the {CharSet}.
147
157
  #
148
158
  # @yield [char]
149
159
  # The given block will be used to transform the characters within
150
- # the character set.
160
+ # the {CharSet}.
151
161
  #
152
162
  # @yieldparam [String] char
153
- # Each character in the character set.
163
+ # Each character in the {CharSet}.
154
164
  #
155
165
  # @return [Array<String>]
156
- # The mapped characters of the character set.
166
+ # The mapped characters of the {CharSet}.
157
167
  #
158
168
  def map_chars(&block)
159
169
  each_char.map(&block)
160
170
  end
161
171
 
172
+ #
173
+ # Returns a random byte from the {CharSet}.
162
174
  #
163
175
  # @return [Integer]
164
- # A random byte from the character set.
176
+ # A random byte value.
165
177
  #
166
178
  def random_byte
167
179
  self.entries[rand(self.length)]
168
180
  end
169
181
 
182
+ #
183
+ # Returns a random character from the {CharSet}.
170
184
  #
171
185
  # @return [String]
172
- # A random char from the character set.
186
+ # A random char value.
173
187
  #
174
188
  def random_char
175
189
  @chars[random_byte]
@@ -185,7 +199,7 @@ module Chars
185
199
  # The block will receive the random bytes.
186
200
  #
187
201
  # @yieldparam [Integer] byte
188
- # The random byte from the character set.
202
+ # The random byte from the {CharSet}.
189
203
  #
190
204
  # @return [Enumerator]
191
205
  # If no block is given, an enumerator object will be returned.
@@ -207,7 +221,7 @@ module Chars
207
221
  # The block will receive the random characters.
208
222
  #
209
223
  # @yieldparam [String] char
210
- # The random character from the character set.
224
+ # The random character from the {CharSet}.
211
225
  #
212
226
  # @return [Enumerator]
213
227
  # If no block is given, an enumerator object will be returned.
@@ -219,7 +233,7 @@ module Chars
219
233
  end
220
234
 
221
235
  #
222
- # Creates an Array of random bytes from the character set.
236
+ # Creates an Array of random bytes from the {CharSet}.
223
237
  #
224
238
  # @param [Integer, Array, Range] length
225
239
  # The length of the Array of random bytes.
@@ -228,15 +242,18 @@ module Chars
228
242
  # The randomly selected bytes.
229
243
  #
230
244
  def random_bytes(length)
231
- if (length.kind_of?(Array) || length.kind_of?(Range))
232
- Array.new(length.sort_by { rand }.first) { random_byte }
245
+ case length
246
+ when Array
247
+ Array.new(length.sample) { random_byte }
248
+ when Range
249
+ Array.new(rand(length)) { random_byte }
233
250
  else
234
251
  Array.new(length) { random_byte }
235
252
  end
236
253
  end
237
254
 
238
255
  #
239
- # Creates an Array of random non-repeating bytes from the character set.
256
+ # Creates an Array of random non-repeating bytes from the {CharSet}.
240
257
  #
241
258
  # @param [Integer, Array, Range] length
242
259
  # The length of the Array of random non-repeating bytes.
@@ -245,15 +262,20 @@ module Chars
245
262
  # The randomly selected non-repeating bytes.
246
263
  #
247
264
  def random_distinct_bytes(length)
248
- if (length.kind_of?(Array) || length.kind_of?(Range))
249
- self.entries.sort_by { rand }.slice(0...(length.sort_by { rand }.first))
265
+ shuffled_bytes = bytes.shuffle
266
+
267
+ case length
268
+ when Array
269
+ shuffled_bytes[0,length.sample]
270
+ when Range
271
+ shuffled_bytes[0,rand(length)]
250
272
  else
251
- self.entries.sort_by { rand }.slice(0...length)
273
+ shuffled_bytes[0,length]
252
274
  end
253
275
  end
254
276
 
255
277
  #
256
- # Creates an Array of random characters from the character set.
278
+ # Creates an Array of random characters from the {CharSet}.
257
279
  #
258
280
  # @param [Integer, Array, Range] length
259
281
  # The length of the Array of random characters.
@@ -267,7 +289,7 @@ module Chars
267
289
 
268
290
  #
269
291
  # Creates a String containing randomly selected characters from the
270
- # character set.
292
+ # {CharSet}.
271
293
  #
272
294
  # @param [Integer, Array, Range] length
273
295
  # The length of the String of random characters.
@@ -283,7 +305,7 @@ module Chars
283
305
 
284
306
  #
285
307
  # Creates an Array of random non-repeating characters from the
286
- # character set.
308
+ # {CharSet}.
287
309
  #
288
310
  # @param [Integer, Array, Range] length
289
311
  # The length of the Array of random non-repeating characters.
@@ -297,7 +319,7 @@ module Chars
297
319
 
298
320
  #
299
321
  # Creates a String containing randomly selected non-repeating
300
- # characters from the character set.
322
+ # characters from the {CharSet}.
301
323
  #
302
324
  # @param [Integer, Array, Range] length
303
325
  # The length of the String of random non-repeating characters.
@@ -313,7 +335,7 @@ module Chars
313
335
 
314
336
  #
315
337
  # Finds sub-strings within given data that are made of characters within
316
- # the character set.
338
+ # the {CharSet}.
317
339
  #
318
340
  # @param [String] data
319
341
  # The data to find sub-strings within.
@@ -334,7 +356,7 @@ module Chars
334
356
  # optional index.
335
357
  #
336
358
  # @yield [String] match
337
- # A sub-string containing the characters from the character set.
359
+ # A sub-string containing the characters from the {CharSet}.
338
360
  #
339
361
  # @yield [Integer] index
340
362
  # The index the sub-string was found at.
@@ -386,14 +408,14 @@ module Chars
386
408
  end
387
409
 
388
410
  #
389
- # Creates a new CharSet object by unioning the character set with
390
- # another character set.
411
+ # Creates a new CharSet object by unioning the {CharSet} with another
412
+ # {CharSet}.
391
413
  #
392
414
  # @param [CharSet, Array, Range] set
393
- # The other character set to union with.
415
+ # The other {CharSet} to union with.
394
416
  #
395
417
  # @return [CharSet]
396
- # The unioned character sets.
418
+ # The unioned {ChraSet}.
397
419
  #
398
420
  def |(set)
399
421
  set = CharSet.new(set) unless set.kind_of?(CharSet)
@@ -405,14 +427,14 @@ module Chars
405
427
 
406
428
  #
407
429
  # Compares the bytes within a given string with the bytes of the
408
- # character set.
430
+ # {CharSet}.
409
431
  #
410
432
  # @param [String, Enumerable] other
411
- # The string to compare with the character set.
433
+ # The string to compare with the {CharSet}.
412
434
  #
413
435
  # @return [Boolean]
414
436
  # Specifies whether all of the bytes within the given string are
415
- # included in the character set.
437
+ # included in the {CharSet}.
416
438
  #
417
439
  # @example
418
440
  # Chars.alpha === "hello"
@@ -439,10 +461,10 @@ module Chars
439
461
  alias =~ ===
440
462
 
441
463
  #
442
- # Inspects the character set.
464
+ # Inspects the {CharSet}.
443
465
  #
444
466
  # @return [String]
445
- # The inspected character set.
467
+ # The inspected {CharSet}.
446
468
  #
447
469
  def inspect
448
470
  "#<#{self.class.name}: {" + map { |byte|
@@ -454,74 +476,10 @@ module Chars
454
476
  # to us C programmers
455
477
  '"\0"'
456
478
  else
457
- "0x%02x" % byte
479
+ sprintf("0x%02x",byte)
458
480
  end
459
481
  }.join(', ') + "}>"
460
482
  end
461
483
 
462
- protected
463
-
464
- if RUBY_VERSION > '1.9.'
465
- #
466
- # Converts a byte to a character.
467
- #
468
- # @param [Integer] byte
469
- # The byte to convert.
470
- #
471
- # @return [String]
472
- # The character.
473
- #
474
- # @since 0.2.1
475
- #
476
- def byte_to_char(byte)
477
- byte.chr(Encoding::UTF_8)
478
- end
479
-
480
- #
481
- # Converts a character to a byte.
482
- #
483
- # @param [String] char
484
- # The character to convert.
485
- #
486
- # @return [Integer]
487
- # The byte.
488
- #
489
- # @since 0.2.1
490
- #
491
- def char_to_byte(char)
492
- char.ord
493
- end
494
- else
495
- #
496
- # Converts a byte to a character.
497
- #
498
- # @param [Integer] byte
499
- # The byte to convert.
500
- #
501
- # @return [String]
502
- # The character.
503
- #
504
- # @since 0.2.1
505
- #
506
- def byte_to_char(byte)
507
- byte.chr
508
- end
509
-
510
- #
511
- # Converts a character to a byte.
512
- #
513
- # @param [String] char
514
- # The character to convert.
515
- #
516
- # @return [Integer]
517
- # The byte.
518
- #
519
- # @since 0.2.1
520
- #
521
- def char_to_byte(char)
522
- char[0]
523
- end
524
- end
525
-
526
484
  end
527
485
  end