Method: Puppet::Pops::PN#double_quote

Defined in:
lib/puppet/pops/pn.rb

#double_quote(str, bld) ⇒ Object



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
# File 'lib/puppet/pops/pn.rb', line 31

def double_quote(str, bld)
  bld << '"'
  str.each_codepoint do |codepoint|
    case codepoint
    when 0x09
      bld << '\\t'
    when 0x0a
      bld << '\\n'
    when 0x0d
      bld << '\\r'
    when 0x22
      bld << '\\"'
    when 0x5c
      bld << '\\\\'
    else
      if codepoint < 0x20
        bld << sprintf('\\o%3.3o', codepoint)
      elsif codepoint <= 0x7f
        bld << codepoint
      else
        bld << [codepoint].pack('U')
      end
    end
  end
  bld << '"'
end