]>
git.proxmox.com Git - rustc.git/blob - vendor/regex-automata-0.1.10/tests/unescape.rs
1 #[derive(Clone, Copy, Eq, PartialEq)]
3 /// The state after seeing a `\`.
5 /// The state after seeing a `\x`.
7 /// The state after seeing a `\x[0-9A-Fa-f]`.
13 pub fn unescape(s
: &str) -> Vec
<u8> {
16 let mut bytes
= vec
![];
17 let mut state
= Literal
;
41 bytes
.extend(format
!(r
"\{}", c
).into_bytes());
46 '
0'
..='
9'
| 'A'
..='F'
| 'a'
..='f'
=> {
50 bytes
.extend(format
!(r
"\x{}", c
).into_bytes());
54 HexSecond(first
) => match c
{
55 '
0'
..='
9'
| 'A'
..='F'
| 'a'
..='f'
=> {
56 let ordinal
= format
!("{}{}", first
, c
);
57 let byte
= u8::from_str_radix(&ordinal
, 16).unwrap();
62 let original
= format
!(r
"\x{}{}", first
, c
);
63 bytes
.extend(original
.into_bytes());
72 bytes
.extend(c
.to_string().as_bytes());
78 Escape
=> bytes
.push(b'
\\'
),
79 HexFirst
=> bytes
.extend(b
"\\x"),
80 HexSecond(c
) => bytes
.extend(format
!("\\x{}", c
).into_bytes()),