Hello! I am a complete newbie, so this might be trivial, but I just can't figure it out and wasn't lucky with my searches either.
I have an input file containing a number of random text. These texts include hex escapes as well (see example below).
My goal would be to convert these with regex to the correct unicode escape format: \u{0000}
E.g:
File content is the following.
"\x27"
The idea is that if I have this:
let mystr = String::from("\u{0027}");
println!("{}, mystr");
It will print out a single apostrophe (').
My code looks like this:
use regex::{Regex, Captures};
fn text_parser(i: &String) -> usize {
let mut l = i.lines().next().unwrap();
let re = regex::Regex::new(r"x([a-zA-Z0-9]{2})").unwrap();
let s = re.replace_all(l, |caps: &Captures| format!("{}{}{}", "u{00", &caps[1], "}"));
This almost looks good, but it is going to be an escaped sequence of characters resulting in "\u{0027}" instead of the actual unicode character.
How can I make sure that the resulting string is a valid unicode escape?