65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/json/objects.rb', line 65
def self.to_json(str)
return "\"\"" if (str.length == 0)
newstr = "\""
str.each_byte {
|b|
c = b.chr
case c
when /\\|\"|\//
newstr << "\\" + c
when "\b"
newstr << "\\b"
when "\t"
newstr << "\\t"
when "\n"
newstr << "\\n"
when "\f"
newstr << "\\f"
when "\r"
newstr << "\\r"
else
if (c < ' ')
t = "000" + sprintf("%0x", b)
newstr << ("\\u" + t[0,t.length - 4])
else
newstr << c
end
end
}
newstr += '"'
return(newstr)
end
|