Skip to content

Instantly share code, notes, and snippets.

@boxofrox
Forked from anonymous/playground.rs
Created March 13, 2018 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boxofrox/9ec79fbad9726d61e5b14efaf10dbe31 to your computer and use it in GitHub Desktop.
Save boxofrox/9ec79fbad9726d61e5b14efaf10dbe31 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!( take_until!("\\'")
, "\\"
, 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