ctype 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ctype.rb +80 -0
- metadata +39 -0
data/lib/ctype.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#
|
2
|
+
# = ctype.rb: ctype.h as syntactic sugar for Ruby
|
3
|
+
#
|
4
|
+
# Homepage:: http://ctype.rubyforge.org
|
5
|
+
# Author:: murphy (Kornelius Kalnbach)
|
6
|
+
# Copyright:: (cc) 2005 cYcnus
|
7
|
+
# License:: GPL
|
8
|
+
# Version:: 0.2.0 (2005-03-16)
|
9
|
+
#
|
10
|
+
# === It's simple
|
11
|
+
#
|
12
|
+
# C: <code>isalpha(x)</code>
|
13
|
+
# Ruby: <code>x.alpha?</code>
|
14
|
+
#
|
15
|
+
# Also working (as of version 0.2.0):
|
16
|
+
#
|
17
|
+
# nil.digit? == false (useful if getc returns nil)
|
18
|
+
# 'a string'.alpha? == true
|
19
|
+
#
|
20
|
+
# === Further information
|
21
|
+
#
|
22
|
+
# Uses the POSIX character classes [[:...:]] implemented in Regexp.
|
23
|
+
#
|
24
|
+
# See the documentation for ctype.h at
|
25
|
+
# http://www-ccs.ucsd.edu/c/ctype.html
|
26
|
+
#
|
27
|
+
|
28
|
+
=begin
|
29
|
+
|
30
|
+
POSIX Character Classes. [:class:]
|
31
|
+
This is an alternate method of specifying a range of characters to match.
|
32
|
+
|
33
|
+
[:alnum:] matches alphabetic or numeric characters. This is equivalent to A-Za-z0-9.
|
34
|
+
[:alpha:] matches alphabetic characters. This is equivalent to A-Za-z.
|
35
|
+
[:blank:] matches a space or a tab.
|
36
|
+
[:cntrl:] matches control characters.
|
37
|
+
[:digit:] matches (decimal) digits. This is equivalent to 0-9.
|
38
|
+
[:graph:] graphic printable characters. Matches characters in the range of ASCII 33 - 126.
|
39
|
+
This is the same as [:print:], below, but excluding the space character.
|
40
|
+
[:lower:] matches lowercase alphabetic characters. This is equivalent to a-z.
|
41
|
+
[:print:] printable characters. Matches characters in the range of ASCII 32 - 126.
|
42
|
+
This is the same as [:graph:], above, but adding the space character.
|
43
|
+
[:space:] matches whitespace characters (space and horizontal tab).
|
44
|
+
[:upper:] matches uppercase alphabetic characters. This is equivalent to A-Z.
|
45
|
+
[:xdigit:] matches hexadecimal digits. This is equivalent to 0-9A-Fa-f.
|
46
|
+
=end
|
47
|
+
|
48
|
+
POSIX_CHARACTER_CLASSES = %w[ alnum alpha cntrl digit graph lower print punct space upper xdigit ]
|
49
|
+
|
50
|
+
# ?A.upper?
|
51
|
+
class Fixnum
|
52
|
+
POSIX_CHARACTER_CLASSES.each do |c|
|
53
|
+
rx = Regexp.new('[[:' + c + ':]]')
|
54
|
+
define_method((c + '?').to_sym) do
|
55
|
+
self >= 0 and rx === self.chr
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# 'A'.upper?
|
61
|
+
class String
|
62
|
+
POSIX_CHARACTER_CLASSES.each do |c|
|
63
|
+
rx = Regexp.new('[[:' + c + ':]]')
|
64
|
+
meth = (c + '?').to_sym
|
65
|
+
define_method(meth) do
|
66
|
+
if self[0]
|
67
|
+
self[0].send meth
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# nil.upper?
|
74
|
+
class NilClass
|
75
|
+
POSIX_CHARACTER_CLASSES.each do |c|
|
76
|
+
define_method((c + '?').to_sym) do
|
77
|
+
false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.8
|
3
|
+
specification_version: 1
|
4
|
+
name: ctype
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2005-03-17
|
8
|
+
summary: ctype provides Ruby-style methods known from ctype.h.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: murphy@cYcnus.de
|
12
|
+
homepage: ruby.cycnus.de
|
13
|
+
rubyforge_project: ctype
|
14
|
+
description: "ctype is a simple implementation of ctype.h. It provides methods like alpha?
|
15
|
+
and digit? for Fixnums and Strings, so it can be used for string analysing (like
|
16
|
+
scanners): 'c'.alpha? -> true"
|
17
|
+
autorequire:
|
18
|
+
default_executable:
|
19
|
+
bindir: bin
|
20
|
+
has_rdoc: true
|
21
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
22
|
+
requirements:
|
23
|
+
-
|
24
|
+
- ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.0
|
27
|
+
version:
|
28
|
+
platform: ruby
|
29
|
+
authors:
|
30
|
+
- murphy
|
31
|
+
files:
|
32
|
+
- lib/ctype.rb
|
33
|
+
test_files: []
|
34
|
+
rdoc_options: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
requirements: []
|
39
|
+
dependencies: []
|