diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..7d6283d --- /dev/null +++ b/shell.nix @@ -0,0 +1,17 @@ +{ pkgs ? import { } }: + +pkgs.mkShell { + name = "nexromancers-hacksaw-shell"; + nativeBuildInputs = [ + pkgs.pkgconfig + pkgs.python3 + ]; + buildInputs = [ + pkgs.cargo + pkgs.clippy + pkgs.rustc + pkgs.rustfmt + pkgs.xorg.libX11 + pkgs.xorg.libXrandr + ]; +} diff --git a/src/lib/parse_format.rs b/src/lib/parse_format.rs index 60e1e68..9413b5f 100644 --- a/src/lib/parse_format.rs +++ b/src/lib/parse_format.rs @@ -18,23 +18,25 @@ pub(crate) fn parse_format_string(input: &str) -> Result { let mut input = input.as_bytes(); loop { - let (token, rest) = match input { - [b'%', b'i', rest @ ..] => (FormatToken::WindowId, rest), - [b'%', b'g', rest @ ..] => (FormatToken::Geometry, rest), - [b'%', b'w', rest @ ..] => (FormatToken::Width, rest), - [b'%', b'h', rest @ ..] => (FormatToken::Height, rest), - [b'%', b'x', rest @ ..] => (FormatToken::X, rest), - [b'%', b'y', rest @ ..] => (FormatToken::Y, rest), - [b'%', b'%', rest @ ..] => (FormatToken::Literal("%".to_owned()), rest), - [b'%', c, ..] => break Err(format!("Unknown format '%{}'", *c as char)), - [b'%'] => break Err("Incorrectly terminated '%'".to_owned()), - [_, ..] => { + let (token, rest) = match input.split_first() { + Some((b'%', format_rest)) => match format_rest.split_first() { + Some((b'i', rest)) => (FormatToken::WindowId, rest), + Some((b'g', rest)) => (FormatToken::Geometry, rest), + Some((b'w', rest)) => (FormatToken::Width, rest), + Some((b'h', rest)) => (FormatToken::Height, rest), + Some((b'x', rest)) => (FormatToken::X, rest), + Some((b'y', rest)) => (FormatToken::Y, rest), + Some((b'%', rest)) => (FormatToken::Literal("%".to_owned()), rest), + Some((c, _)) => break Err(format!("Unknown format '%{}'", *c as char)), + None => break Err("Incorrectly terminated '%'".to_owned()), + } + Some((_, _)) => { let next_perc = input.iter().position(|&c| c == b'%'); let (literal, rest) = input.split_at(next_perc.unwrap_or_else(|| input.len())); let literal = FormatToken::Literal(String::from_utf8_lossy(literal).into_owned()); (literal, rest) } - [] => break Ok(tokens), + None => break Ok(tokens), }; tokens.push(token);