chars 0.1.1 → 0.2.3

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.
@@ -2,64 +2,79 @@ require 'chars/char_set'
2
2
 
3
3
  module Chars
4
4
  # The numeric decimal character set
5
- NUMERIC = CharSet.new('0'..'9')
5
+ NUMERIC = CharSet['0'..'9']
6
6
 
7
7
  # The octal character set
8
- OCTAL = CharSet.new('0'..'7')
8
+ OCTAL = CharSet['0'..'7']
9
9
 
10
10
  # The upper-case hexadecimal character set
11
- UPPERCASE_HEXADECIMAL = NUMERIC + ('A'..'F')
11
+ UPPERCASE_HEXADECIMAL = NUMERIC | CharSet['A'..'F']
12
12
 
13
13
  # The lower-case hexadecimal character set
14
- LOWERCASE_HEXADECIMAL = NUMERIC + ('a'..'f')
14
+ LOWERCASE_HEXADECIMAL = NUMERIC | CharSet['a'..'f']
15
15
 
16
16
  # The hexadecimal character set
17
- HEXADECIMAL = UPPERCASE_HEXADECIMAL + LOWERCASE_HEXADECIMAL
17
+ HEXADECIMAL = UPPERCASE_HEXADECIMAL | LOWERCASE_HEXADECIMAL
18
18
 
19
19
  # The upper-case alpha character set
20
- UPPERCASE_ALPHA = CharSet.new('A'..'Z')
20
+ UPPERCASE_ALPHA = CharSet['A'..'Z']
21
21
 
22
22
  # The lower-case alpha character set
23
- LOWERCASE_ALPHA = CharSet.new('a'..'z')
23
+ LOWERCASE_ALPHA = CharSet['a'..'z']
24
24
 
25
25
  # The alpha character set
26
- ALPHA = UPPERCASE_ALPHA + LOWERCASE_ALPHA
26
+ ALPHA = UPPERCASE_ALPHA | LOWERCASE_ALPHA
27
27
 
28
28
  # The alpha-numeric character set
29
- ALPHA_NUMERIC = ALPHA + NUMERIC
29
+ ALPHA_NUMERIC = ALPHA | NUMERIC
30
30
 
31
31
  # The punctuation character set
32
- PUNCTUATION = CharSet.new(' ', '\'', '"', '`', ',', ';', ':', '~', '-',
33
- '(', ')', '[', ']', '{', '}', '.', '?', '!')
32
+ PUNCTUATION = CharSet[' ', '\'', '"', '`', ',', ';', ':', '~', '-',
33
+ '(', ')', '[', ']', '{', '}', '.', '?', '!']
34
34
 
35
35
  # The symbolic character set
36
- SYMBOLS = PUNCTUATION + ['@', '#', '$', '%', '^', '&', '*', '_', '+',
37
- '=', '|', '\\', '<', '>', '/']
36
+ SYMBOLS = PUNCTUATION | CharSet[
37
+ '@', '#', '$', '%', '^', '&', '*', '_', '+',
38
+ '=', '|', '\\', '<', '>', '/'
39
+ ]
38
40
 
39
41
  # The space character set
40
42
  SPACE = CharSet.new(' ', "\f", "\n", "\r", "\t", "\v")
41
43
 
44
+ # The set of printable characters (not including spaces)
45
+ VISIBLE = ALPHA_NUMERIC | CharSet[
46
+ '\'', '"', '`', ',', ';', ':', '~', '-',
47
+ '(', ')', '[', ']', '{', '}', '.', '?', '!', '@', '#', '$',
48
+ '%', '^', '&', '*', '_', '+', '=', '|', '\\', '<', '>', '/'
49
+ ]
50
+
42
51
  # The set of printable characters (including spaces)
43
- PRINTABLE = ALPHA_NUMERIC + PUNCTUATION + SYMBOLS + SPACE
52
+ PRINTABLE = ALPHA_NUMERIC | PUNCTUATION | SYMBOLS | SPACE
44
53
 
45
54
  # The control-char character set
46
- CONTROL = CharSet.new(0..0x1f, 0x7f)
55
+ CONTROL = CharSet[0..0x1f, 0x7f]
47
56
 
48
- # The ASCII character set
49
- ASCII = CharSet.new(0..0x7f)
57
+ # The signed ASCII character set
58
+ SIGNED_ASCII = CharSet[0..0x7f]
50
59
 
51
60
  # The full 8-bit character set
52
- ALL = CharSet.new(0..0xff)
61
+ ASCII = CharSet[0..0xff]
53
62
 
54
63
  #
55
- # The numeric decimal character set.
64
+ # The decimal-digit character set.
65
+ #
66
+ # @return [CharSet]
67
+ # The decimal-digit character set.
56
68
  #
57
69
  def Chars.numeric
58
70
  NUMERIC
59
71
  end
60
72
 
61
73
  #
62
- # The octal character set.
74
+ # The octal-digit character set.
75
+ #
76
+ # @return [CharSet]
77
+ # The octal-digit character set.
63
78
  #
64
79
  def Chars.octal
65
80
  OCTAL
@@ -68,6 +83,9 @@ module Chars
68
83
  #
69
84
  # The upper-case hexadecimal character set.
70
85
  #
86
+ # @return [CharSet]
87
+ # The upper-case hexadecimal character set.
88
+ #
71
89
  def Chars.uppercase_hexadecimal
72
90
  UPPERCASE_HEXADECIMAL
73
91
  end
@@ -75,6 +93,9 @@ module Chars
75
93
  #
76
94
  # The lower-case hexadecimal character set.
77
95
  #
96
+ # @return [CharSet]
97
+ # The lower-case hexadecimal character set.
98
+ #
78
99
  def Chars.lowercase_hexadecimal
79
100
  LOWERCASE_HEXADECIMAL
80
101
  end
@@ -82,26 +103,38 @@ module Chars
82
103
  #
83
104
  # The hexadecimal character set.
84
105
  #
106
+ # @return [CharSet]
107
+ # The hexadecimal character set.
108
+ #
85
109
  def Chars.hexadecimal
86
110
  HEXADECIMAL
87
111
  end
88
112
 
89
113
  #
90
- # The upper-case alpha character set.
114
+ # The upper-case alphabetic character set.
115
+ #
116
+ # @return [CharSet]
117
+ # The upper-case alphabetic character set.
91
118
  #
92
119
  def Chars.uppercase_alpha
93
120
  UPPERCASE_ALPHA
94
121
  end
95
122
 
96
123
  #
97
- # The lower-case alpha character set.
124
+ # The lower-case alphabetic character set.
125
+ #
126
+ # @return [CharSet]
127
+ # The lower-case alphabetic character set.
98
128
  #
99
129
  def Chars.lowercase_alpha
100
130
  LOWERCASE_ALPHA
101
131
  end
102
132
 
103
133
  #
104
- # The alpha character set.
134
+ # The alphabetic character set.
135
+ #
136
+ # @return [CharSet]
137
+ # The alphabetic character set.
105
138
  #
106
139
  def Chars.alpha
107
140
  ALPHA
@@ -110,6 +143,9 @@ module Chars
110
143
  #
111
144
  # The alpha-numeric character set.
112
145
  #
146
+ # @return [CharSet]
147
+ # The alpha-numeric character set.
148
+ #
113
149
  def Chars.alpha_numeric
114
150
  ALPHA_NUMERIC
115
151
  end
@@ -117,6 +153,9 @@ module Chars
117
153
  #
118
154
  # The punctuation character set.
119
155
  #
156
+ # @return [CharSet]
157
+ # The punctuation character set.
158
+ #
120
159
  def Chars.punctuation
121
160
  PUNCTUATION
122
161
  end
@@ -124,42 +163,70 @@ module Chars
124
163
  #
125
164
  # The symbolic character set.
126
165
  #
166
+ # @return [CharSet]
167
+ # The symbolic character set.
168
+ #
127
169
  def Chars.symbols
128
170
  SYMBOLS
129
171
  end
130
172
 
131
173
  #
132
- # The space character set.
174
+ # The white-space character set.
175
+ #
176
+ # @return [CharSet]
177
+ # The white-space character set.
133
178
  #
134
179
  def Chars.space
135
180
  SPACE
136
181
  end
137
182
 
183
+ #
184
+ # The set of printable characters, not including spaces.
185
+ #
186
+ # @return [CharSet]
187
+ # The visible character set.
188
+ #
189
+ def Chars.visible
190
+ VISIBLE
191
+ end
192
+
138
193
  #
139
194
  # The set of printable characters, including spaces.
140
195
  #
196
+ # @return [CharSet]
197
+ # The printable character set.
198
+ #
141
199
  def Chars.printable
142
200
  PRINTABLE
143
201
  end
144
202
 
145
203
  #
146
- # The control-char character set.
204
+ # The control-character character set.
205
+ #
206
+ # @return [CharSet]
207
+ # The control-character character set.
147
208
  #
148
209
  def Chars.control
149
210
  CONTROL
150
211
  end
151
212
 
152
213
  #
153
- # The ASCII character set.
214
+ # The signed ASCII character set.
154
215
  #
155
- def Chars.ascii
156
- ASCII
216
+ # @return [CharSet]
217
+ # The signed ASCII character set.
218
+ #
219
+ def Chars.signed_ascii
220
+ SIGNED_ASCII
157
221
  end
158
222
 
159
223
  #
160
- # The full 8-bit character set.
224
+ # The ASCII character set.
225
+ #
226
+ # @return [CharSet]
227
+ # The ASCII character set.
161
228
  #
162
- def Chars.all
163
- ALL
229
+ def Chars.ascii
230
+ ASCII
164
231
  end
165
232
  end
@@ -2,64 +2,217 @@ require 'chars/chars'
2
2
 
3
3
  class Integer
4
4
 
5
+ #
6
+ # Determines if the byte belongs to the decimal-digit character set.
7
+ #
8
+ # @return [Boolean]
9
+ # Specifies whether the byte belongs to the decimal-digit character set.
10
+ #
11
+ # @see Chars.numeric
12
+ #
5
13
  def numeric?
6
- Chars::NUMERIC.include?(self)
14
+ Chars::NUMERIC.include_byte?(self)
7
15
  end
8
16
 
17
+ #
18
+ # Determines if the byte belongs to the octal-digit character set.
19
+ #
20
+ # @return [Boolean]
21
+ # Specifies whether the byte belongs to the octal-digit character set.
22
+ #
23
+ # @see Chars.octal
24
+ #
9
25
  def octal?
10
- Chars::OCTAL.include?(self)
26
+ Chars::OCTAL.include_byte?(self)
11
27
  end
12
28
 
29
+ #
30
+ # Determines if the byte belongs to the upper-case hexadecimal character
31
+ # set.
32
+ #
33
+ # @return [Boolean]
34
+ # Specifies whether the byte belongs to the upper-case hexadecimal
35
+ # character set.
36
+ #
37
+ # @see Chars.uppercase_hexadecimal
38
+ #
13
39
  def uppercase_hex?
14
- Chars::UPPERCASE_HEXADECIMAL.include?(self)
40
+ Chars::UPPERCASE_HEXADECIMAL.include_byte?(self)
15
41
  end
16
42
 
43
+ #
44
+ # Determines if the byte belongs to the lower-case hexadecimal character
45
+ # set.
46
+ #
47
+ # @return [Boolean]
48
+ # Specifies whether the byte belongs to the lower-case hexadecimal
49
+ # character set.
50
+ #
51
+ # @see Chars.lowercase_hexadecimal
52
+ #
17
53
  def lowercase_hex?
18
- Chars::LOWERCASE_HEXADECIMAL.include?(self)
54
+ Chars::LOWERCASE_HEXADECIMAL.include_byte?(self)
19
55
  end
20
56
 
57
+ #
58
+ # Determines if the byte belongs to the hexadecimal character set.
59
+ #
60
+ # @return [Boolean]
61
+ # Specifies whether the byte belongs to the hexadecimal character set.
62
+ #
63
+ # @see Chars.hexadecimal
64
+ #
21
65
  def hex?
22
- Chars::HEXADECIMAL.include?(self)
66
+ Chars::HEXADECIMAL.include_byte?(self)
23
67
  end
24
68
 
69
+ #
70
+ # Determines if the byte belongs to the upper-case alphabetic character
71
+ # set.
72
+ #
73
+ # @return [Boolean]
74
+ # Specifies whether the byte belongs to the upper-case alphabetic
75
+ # character set.
76
+ #
77
+ # @see Chars.uppercase_alpha
78
+ #
25
79
  def uppercase_alpha?
26
- Chars::UPPERCASE_ALPHA.include?(self)
80
+ Chars::UPPERCASE_ALPHA.include_byte?(self)
27
81
  end
28
82
 
83
+ #
84
+ # Determines if the byte belongs to the lower-case alphabetic character
85
+ # set.
86
+ #
87
+ # @return [Boolean]
88
+ # Specifies whether the byte belongs to the lower-case alphabetic
89
+ # character set.
90
+ #
91
+ # @see Chars.lowercase_alpha
92
+ #
29
93
  def lowercase_alpha?
30
- Chars::LOWERCASE_ALPHA.include?(self)
94
+ Chars::LOWERCASE_ALPHA.include_byte?(self)
31
95
  end
32
96
 
97
+ #
98
+ # Determines if the byte belongs to the alphabetic character set.
99
+ #
100
+ # @return [Boolean]
101
+ # Specifies whether the byte belongs to the alphabetic character set.
102
+ #
103
+ # @see Chars.alpha
104
+ #
33
105
  def alpha?
34
- Chars::ALPHA.include?(self)
106
+ Chars::ALPHA.include_byte?(self)
35
107
  end
36
108
 
109
+ #
110
+ # Determines if the byte belongs to the alpha-numeric character set.
111
+ #
112
+ # @return [Boolean]
113
+ # Specifies whether the byte belongs to the alpha-numeric character set.
114
+ #
115
+ # @see Chars.alpha_numeric
116
+ #
37
117
  def alpha_numeric?
38
- Chars::ALPHA_NUMERIC.include?(self)
118
+ Chars::ALPHA_NUMERIC.include_byte?(self)
39
119
  end
40
120
 
121
+ #
122
+ # Determines if the byte belongs to the punctuation character set.
123
+ #
124
+ # @return [Boolean]
125
+ # Specifies whether the byte belongs to the punctuation character set.
126
+ #
127
+ # @see Chars.punctuation
128
+ #
41
129
  def punctuation?
42
- Chars::PUNCTUATION.include?(self)
130
+ Chars::PUNCTUATION.include_byte?(self)
43
131
  end
44
132
 
133
+ #
134
+ # Determines if the byte belongs to the symbolic character set.
135
+ #
136
+ # @return [Boolean]
137
+ # Specifies whether the byte belongs to the symbolic character set.
138
+ #
139
+ # @see Chars.symbols
140
+ #
45
141
  def symbolic?
46
- Chars::SYMBOLS.include?(self)
142
+ Chars::SYMBOLS.include_byte?(self)
47
143
  end
48
144
 
145
+ #
146
+ # Determines if the byte belongs to the white-space character set.
147
+ #
148
+ # @return [Boolean]
149
+ # Specifies whether the byte belongs to the white-space character set.
150
+ #
151
+ # @see Chars.space
152
+ #
49
153
  def space?
50
- Chars::SPACE.include?(self)
154
+ Chars::SPACE.include_byte?(self)
51
155
  end
52
156
 
157
+ #
158
+ # Determines if the byte belongs to the visible character set.
159
+ #
160
+ # @return [Boolean]
161
+ # Specifies whether the byte belongs to the visible character set.
162
+ #
163
+ # @see Chars.visible
164
+ #
165
+ def visible?
166
+ Chars::VISIBLE.include_byte?(self)
167
+ end
168
+
169
+ #
170
+ # Determines if the byte belongs to the printable character set.
171
+ #
172
+ # @return [Boolean]
173
+ # Specifies whether the byte belongs to the printable character set.
174
+ #
175
+ # @see Chars.printable
176
+ #
53
177
  def printable?
54
- Chars::PRINTABLE.include?(self)
178
+ Chars::PRINTABLE.include_byte?(self)
55
179
  end
56
180
 
181
+ #
182
+ # Determines if the byte belongs to the control-character character set.
183
+ #
184
+ # @return [Boolean]
185
+ # Specifies whether the byte belongs to the control-character character
186
+ # set.
187
+ #
188
+ # @see Chars.control
189
+ #
57
190
  def control?
58
- Chars::CONTROL.include?(self)
191
+ Chars::CONTROL.include_byte?(self)
192
+ end
193
+
194
+ #
195
+ # Determines if the byte belongs to the signed-ASCII character set.
196
+ #
197
+ # @return [Boolean]
198
+ # Specifies whether the byte belongs to the signed-ASCII character set.
199
+ #
200
+ # @see Chars.signed_ascii
201
+ #
202
+ def signed_ascii?
203
+ Chars::SIGNED_ASCII.include_byte?(self)
59
204
  end
60
205
 
206
+ #
207
+ # Determines if the byte belongs to the ASCII character set.
208
+ #
209
+ # @return [Boolean]
210
+ # Specifies whether the byte belongs to the ASCII character set.
211
+ #
212
+ # @see Chars.ascii
213
+ #
61
214
  def ascii?
62
- Chars::ASCII.include?(self)
215
+ Chars::ASCII.include_byte?(self)
63
216
  end
64
217
 
65
218
  end