#string #split #quote #no-std

no-std splitty

a string splitter taking quotes into account

3 releases (stable)

1.0.1 Sep 24, 2022
1.0.0 Sep 23, 2022
0.1.0 Dec 18, 2020

#111 in Parser tooling

Download history 405/week @ 2023-06-07 695/week @ 2023-06-14 448/week @ 2023-06-21 546/week @ 2023-06-28 501/week @ 2023-07-05 641/week @ 2023-07-12 397/week @ 2023-07-19 340/week @ 2023-07-26 314/week @ 2023-08-02 309/week @ 2023-08-09 455/week @ 2023-08-16 348/week @ 2023-08-23 400/week @ 2023-08-30 362/week @ 2023-09-06 385/week @ 2023-09-13 514/week @ 2023-09-20

1,702 downloads per month
Used in broot

MIT license

9KB
113 lines

MIT Latest Version docs Chat on Miaou

splitty

A no-std string splitter for which spaces between quotes aren't separators.

Quotes not starting or ending a substring are handled as ordinary characters.

use splitty::*;

let cmd = "xterm -e \"vi /some/path\"";

let mut token = split_unquoted_char(cmd, ' ')
    .unwrap_quotes(true);

assert_eq!(token.next(), Some("xterm"));
assert_eq!(token.next(), Some("-e"));
assert_eq!(token.next(), Some("vi /some/path"));

lib.rs:

A no-std string splitter for which spaces between quotes aren't separators.

use splitty::*;

let cmd = "xterm -e \"vi /some/path\"";

let mut token = split_unquoted_char(cmd, ' ')
    .unwrap_quotes(true);

assert_eq!(token.next(), Some("xterm"));
assert_eq!(token.next(), Some("-e"));
assert_eq!(token.next(), Some("vi /some/path"));
assert_eq!(token.next(), None);

Quotes not starting or ending a substring are handled as ordinary characters.

Splitty has a limited set of features but is tested for corner-cases:

use splitty::*;

let cmd = r#" a  "2 * 试" x"x "z "#;

let mut token = split_unquoted_whitespace(cmd)
    .unwrap_quotes(true);

assert_eq!(token.next(), Some("a"));
assert_eq!(token.next(), Some("2 * 试"));
assert_eq!(token.next(), Some("x\"x"));
assert_eq!(token.next(), Some("\"z "));
assert_eq!(token.next(), None);

No runtime deps