#quote #string #split #character #no-std

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

#22 in Parser tooling

Download history 1240/week @ 2024-08-17 951/week @ 2024-08-24 936/week @ 2024-08-31 1133/week @ 2024-09-07 937/week @ 2024-09-14 1586/week @ 2024-09-21 1278/week @ 2024-09-28 1081/week @ 2024-10-05 940/week @ 2024-10-12 1554/week @ 2024-10-19 987/week @ 2024-10-26 1388/week @ 2024-11-02 1068/week @ 2024-11-09 1045/week @ 2024-11-16 1132/week @ 2024-11-23 1530/week @ 2024-11-30

4,991 downloads per month
Used in broot

MIT license

9KB
120 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