Take the 2008 Git User's Survey and help out! [ hide ]

public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
Search Repo:
rubinius / kernel / core / ctype.rb
100644 79 lines (66 sloc) 1.363 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# depends on: module.rb
 
##
# Mixin containing byte classification methods.
#--
# isspace, islower, ... are not in MRI core library. See specs in
# spec/shotgun/ctype_spec.rb
 
module CType
  def isctrl
    self == ?\n or self == ?\r or self == ?\t or self == ?\f or
    self == ?\v or self == ?\a or self == ?\e or self == ?\b
  end
 
  def isspace
    self == ?\s or self == ?\n or self == ?\t or self == ?\r or self == ?\f or self == ?\v
  end
 
  def isupper
    self >= ?A and self <= ?Z
  end
 
  def islower
    self >= ?a and self <= ?z
  end
 
  def isdigit
    self >= ?0 and self <= ?9
  end
 
  def isalnum
    islower or isupper or isdigit
  end
 
  def toupper!
    self - ?\s
  end
 
  def toupper
    self.islower ? self.toupper! : self
  end
 
  def tolower!
    self + ?\s
  end
 
  def tolower
    self.isupper ? self.tolower! : self
  end
 
  def toprint
    if self == ?"
      "\\\""
    elsif self == ?\\
      "\\\\"
    elsif self == ?#
      "\\#"
    elsif isctrl
      case self
      when ?\n: "\\n"
      when ?\t: "\\t"
      when ?\a: "\\a"
      when ?\v: "\\v"
      when ?\f: "\\f"
      when ?\r: "\\r"
      when ?\e: "\\e"
      when ?\b: "\\b"
      end
    elsif self < 32 || self > 126
      str = "\\000"
      str.modify!
 
      c = self.to_s 8
      str.copy_from c, 0, c.size, 4-c.size
    else
      self.chr
    end
  end
end