Encode a String to include c type escape and quotes

Hi I am trying to port a project haystack library to rust and one part of it is to output a string to zinc format (a souped up CSV)

I have wrapped a string to HString and to implement to_zinc that string has to be output with c like escaping and double quotes.

The spec shows examples like

Str: "hello" "foo\nbar\" (uses all standard escape chars as C like languages)

The file I am porting

I can port the java version easily but was wondering if there was a built in method that does this or crate. I can't seem to find one but it seems like a common thing.

Thanks

Standard library has some escaping functions:

https://doc.rust-lang.org/std/primitive.str.html#method.escape_debug

and I've found some crates:


1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.