To go in the opposite direction, you’re correct that you can’t use escape_string. You’d have to write your own function, something like:
function escape_unicode(s::AbstractString)
buf = IOBuffer()
for c in s
if isascii(c)
print(buf, c)
else
i = UInt32(c)
if i < 0x10000
print(buf, "\\u", hex(i, 4))
else
print(buf, "\\U", hex(i, 6))
end
end
end
return String(take!(buf))
end
Why do you need this, however? If it is because you want to embed Unicode data into an ASCII (7-bit) stream, base64 encoding is a much more standard way to do this (and is implemented in Base).