pub fn write_utf8_escaped(out: &mut Write, s: &str) -> io::Result<()>
{
	let utf8 = s.chars().map(|c|
	{
		if !c.is_ascii()
		{
			let prefix = "\\x";
			let mut buffer = [0; 4];
			let length = c.encode_utf8(&mut buffer).len();
			let mut escaped = String::with_capacity(prefix.len() * 2 * length);
			for i in 0..length
			{
				escaped.push_str(&format!("{}{:0width$x}", prefix, buffer[i], width = 2));
			}
			return escaped;
		}
		format!("{}", c)
	})
	.collect::<String>();
	write!(out, "b\"{}\\0\"", utf8)
}
/// Prints a Rust style byte literal escaped version of the given string `s`.
Prints a Rust style byte literal escaped version of the given string `s`.
Prints a Rust style byte literal escaped version of the given string ` s ` .
pub fn write_utf8_escaped(out: &mut Write, s: &str) -> io::Result<()>
{
	let utf8 = s.chars().map(|c|
	{
		if !c.is_ascii()
		{
			let prefix = "\\x";
			let mut buffer = [0; 4];
			let length = c.encode_utf8(&mut buffer).len();
			let mut escaped = String::with_capacity(prefix.len() * 2 * length);
			for i in 0..length
			{
				escaped.push_str(&format!("{}{:0width$x}", prefix, buffer[i], width = 2));
			}
			return escaped;
		}
		format!("{}", c)
	})
	.collect::<String>();
	write!(out, "b\"{}\\0\"", utf8)
}
pub fn write_utf8_escaped ( out : & mut Write , s : & str ) -> io :: Result < ( ) > { let utf8 = s . chars ( ) . map ( | c | { if ! c . is_ascii ( ) { let prefix = " \\ " ; let mut buffer = [ 0 ; 4 ] ; let length = c . encode_utf8 ( & mut buffer ) . len ( ) ; let mut escaped = String :: with_capacity ( prefix . len ( ) * 2 * length ) ; for i in 0 .. length { escaped . push_str ( & format ! ( " " prefix buffer [ i ] width 2 ) ) ; } return escaped ; } format ! ( " " c ) } ) . collect :: < String > ( ) ; write ! ( out " \" \\ \" " utf8 ) }
Prints a Rust style byte literal escaped version of the given string `s`.
Prints a Rust style byte literal escaped version of the given string ` s ` .
out
&mut Write
s
&str
out
&mut Write
s
&str