Class: Ned::Strings

Inherits:
Object
  • Object
show all
Defined in:
lib/ned/strings.rb

Constant Summary collapse

SEQUENCES =
{
  'n' => "\n",
  't' => "\t",
  '\\' => '\\'
}

Class Method Summary collapse

Class Method Details

.unescape!(string) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ned/strings.rb', line 11

def self.unescape!(string)
  i = 0
  while i < string.size - 1
    if string[i] == '\\'
      raise 'eof' if i == (string.size - 1)
      c = string[i + 1]
      r = SEQUENCES[c]
      if r
        string[i] = r
        string[i + 1] = ''
      end
    end
    i = i + 1
  end

  nil
end