Simplify match statement in escape_string_script

This commit is contained in:
Johannes Altmanninger 2024-04-19 14:42:38 +02:00
parent 334946af61
commit 30fbd4280d

View file

@ -308,33 +308,30 @@ fn escape_string_script(input: &wstr, flags: EscapeFlags) -> WString {
}
out.push(c);
}
_ => {
'\x00'..='\x19' => {
let cval = u32::from(c);
if cval < 32 {
need_escape = true;
need_complex_escape = true;
need_escape = true;
need_complex_escape = true;
if symbolic {
out.push(char::from_u32(0x2400 + cval).unwrap());
continue;
}
if cval < 27 && cval != 0 {
out.push('\\');
out.push('c');
out.push(char::from_u32(u32::from(b'a') + cval - 1).unwrap());
continue;
}
let nibble = cval % 16;
out.push('\\');
out.push('x');
out.push(if cval > 15 { '1' } else { '0' });
out.push(char::from_digit(nibble, 16).unwrap());
} else {
out.push(c);
if symbolic {
out.push(char::from_u32(0x2400 + cval).unwrap());
continue;
}
if cval < 27 && cval != 0 {
out.push('\\');
out.push('c');
out.push(char::from_u32(u32::from(b'a') + cval - 1).unwrap());
continue;
}
let nibble = cval % 16;
out.push('\\');
out.push('x');
out.push(if cval > 15 { '1' } else { '0' });
out.push(char::from_digit(nibble, 16).unwrap());
}
_ => out.push(c),
}
}