Class: Elparser::SExpString

Inherits:
AbstractSExpAtom show all
Defined in:
lib/elparser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractSExpAtom

#atom?

Methods inherited from AbstractSExp

#==, #atom?, #cons?, #list?, #visit

Constructor Details

#initialize(str) ⇒ SExpString

Returns a new instance of SExpString.



64
65
66
# File 'lib/elparser.rb', line 64

def initialize(str)
  @str = str
end

Instance Attribute Details

#strObject (readonly)

Returns the value of attribute str.



63
64
65
# File 'lib/elparser.rb', line 63

def str
  @str
end

Instance Method Details

#to_rubyObject



78
79
80
# File 'lib/elparser.rb', line 78

def to_ruby
  @str
end

#to_sObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/elparser.rb', line 67

def to_s
  # replace unicode point escape syntax : \u{xxxx} -> \uxxxx, \u{yyyyy} -> \U000yyyyy
  @str.dump.gsub(/\\u\{(\h{4,6})\}/) do |m|
    i = $1
    if i.size == 4 then
      "\\u#{i}"
    else
      "\\U00%06x"%(i.hex)
    end
  end
end