def strenc(s)
t = StringIO.new
t.putc(?")
r = 0
rubydoesenc = s.class.method_defined?(:encoding)
while r < s.length
case s[r]
when ?" then t.print('\\"')
when ?\\ then t.print('\\\\')
when ?\b then t.print('\\b')
when ?\f then t.print('\\f')
when ?\n then t.print('\\n')
when ?\r then t.print('\\r')
when ?\t then t.print('\\t')
else
c = s[r]
case true
when rubydoesenc
begin
c.ord
t.write(c)
rescue
t.write(Ustrerr)
end
when Spc <= c && c <= ?~
t.putc(c)
else
n = ucharcopy(t, s, r)
r += n - 1
end
end
r += 1
end
t.putc(?")
t.string
end