Class: AdLint::Cpp::EscapeSequence

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ EscapeSequence

TODO: Remove duplication in cc1/util.rb and cpp/util.rb .



37
38
39
# File 'lib/adlint/cpp/util.rb', line 37

def initialize(str)
  @str = str
end

Instance Method Details

#valueObject



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

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