[−][src]Function binjs_io::escaped_wtf8::to_unicode_escape
pub fn to_unicode_escape(s: String) -> String
If the given bytes
contains any escaped lone surropgate, convert it to
unicode escape \uXXXX.
Failures
If the input is not well-formed escaped WTF-8, this function causes a panic.
Examples
Lone lead surrogate is converted to unicode escape.
let input = "\x7FD83E".to_string(); let expected = "\\uD83E".to_string(); assert_eq!(binjs_io::escaped_wtf8::to_unicode_escape(input), expected);
Lone trail surrogate is converted to unicode escape.
let input = "\x7FDD9D".to_string(); let expected = "\\uDD9D".to_string(); assert_eq!(binjs_io::escaped_wtf8::to_unicode_escape(input), expected);
Escape char (\x7F) is unescaped.
let input = "\x7F007F".to_string(); let expected = "\x7F".to_string(); assert_eq!(binjs_io::escaped_wtf8::to_unicode_escape(input), expected);
If the input is ill-formed, causes a panic.
// Not enough character after escape character. let input = "\x7F000".to_string(); binjs_io::escaped_wtf8::to_unicode_escape(input);
// Invalid character in the codeunit let input = "\x7F012X".to_string(); binjs_io::escaped_wtf8::to_unicode_escape(input);
// Codeunit is not in the surrogate pair range. let input = "\x7F3042".to_string(); binjs_io::escaped_wtf8::to_unicode_escape(input);