Class: AdLint::Cc1::EscapeSequence

Inherits:
Object
  • Object
show all
Defined in:
lib/adlint/cc1/util.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ EscapeSequence

Returns a new instance of EscapeSequence.



36
37
38
# File 'lib/adlint/cc1/util.rb', line 36

def initialize(str)
  @str = str
end

Instance Method Details

#valueObject



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
# File 'lib/adlint/cc1/util.rb', line 40

def value
  case @str
  when "\\'" then "'".ord
  when "\\\"" then "\"".ord
  when "\\?" then "?".ord
  when "\\\\" then "\\".ord
  when "\\a" then "\a".ord
  when "\\b" then "\b".ord
  when "\\f" then "\f".ord
  when "\\n" then "\n".ord
  when "\\r" then "\r".ord
  when "\\t" then "\t".ord
  when "\\v" then "\v".ord
  else
    case @str
    when /\A\\([0-9]{1,3})\z/
      $1.to_i(8)
    when /\A\\x([0-9A-F]+)\z/i
      $1.to_i(16)
    when /\A\\u([0-9A-F]{4,8})\z/i
      $1.to_i(16)
    else
      0
    end
  end
end