Skip to content

Instantly share code, notes, and snippets.

Created March 13, 2018 16:39
Show Gist options
  • Save anonymous/7da24ff97f003ac17c3d382f2d35d9ef to your computer and use it in GitHub Desktop.
Save anonymous/7da24ff97f003ac17c3d382f2d35d9ef to your computer and use it in GitHub Desktop.
Rust code shared from the playground
#[macro_use] extern crate nom;
fn to_s(i: Vec<u8>) -> String {
String::from_utf8_lossy(&i).into_owned()
}
named!( single_quoted_shell_arg(&[u8]) -> String
, map!( delimited!( char!('\'')
, escaped_transform!( not!(char!('\''))
, "\\"
, tag!("'") => { |_| &b"'"[..] }
)
, char!('\'')
)
, to_s
)
);
#[test]
fn can_parse_single_quoted_shell_arg() {
assert_eq!( single_quoted_shell_arg(b"'hello'"[..])
, Done(&b""[..], b"hello"[..]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment