• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use nom::bytes::complete::escaped;
2 use nom::character::complete::digit1;
3 use nom::character::complete::one_of;
4 use nom::{error::ErrorKind, Err, IResult};
5 
esc(s: &str) -> IResult<&str, &str, (&str, ErrorKind)>6 fn esc(s: &str) -> IResult<&str, &str, (&str, ErrorKind)> {
7   escaped(digit1, '\\', one_of("\"n\\"))(s)
8 }
9 
10 #[cfg(feature = "alloc")]
11 fn esc_trans(s: &str) -> IResult<&str, String, (&str, ErrorKind)> {
12   use nom::bytes::complete::{escaped_transform, tag};
13   escaped_transform(digit1, '\\', tag("n"))(s)
14 }
15 
16 #[test]
17 fn test_escaped() {
18   assert_eq!(esc("abcd"), Err(Err::Error(("abcd", ErrorKind::Escaped))));
19 }
20 
21 #[test]
22 #[cfg(feature = "alloc")]
23 fn test_escaped_transform() {
24   assert_eq!(
25     esc_trans("abcd"),
26     Err(Err::Error(("abcd", ErrorKind::EscapedTransform)))
27   );
28 }
29