#split #quote #no-std #string

no-std splitty

a string splitter taking quotes into account

4 releases (stable)

1.0.2 Aug 3, 2024
1.0.1 Sep 24, 2022
1.0.0 Sep 23, 2022
0.1.0 Dec 18, 2020

#55 in Parser tooling

Download history 1717/week @ 2025-06-01 1608/week @ 2025-06-08 1207/week @ 2025-06-15 1062/week @ 2025-06-22 1016/week @ 2025-06-29 1090/week @ 2025-07-06 1799/week @ 2025-07-13 1422/week @ 2025-07-20 913/week @ 2025-07-27 609/week @ 2025-08-03 955/week @ 2025-08-10 984/week @ 2025-08-17 984/week @ 2025-08-24 1748/week @ 2025-08-31 1236/week @ 2025-09-07 2405/week @ 2025-09-14

6,409 downloads per month
Used in broot

MIT license

9KB
120 lines

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);

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"));

No runtime deps