Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept array of str for split_str #165

Closed
Sytten opened this issue Jul 10, 2023 · 1 comment
Closed

Accept array of str for split_str #165

Sytten opened this issue Jul 10, 2023 · 1 comment
Labels
wontfix This will not be worked on

Comments

@Sytten
Copy link

Sytten commented Jul 10, 2023

Hello! Love the library, thanks a lot for it

I had a small feature proposition for the split_str function.
I had a usecase where I wanted to split on two different strings, but it only accepts a single str.
I was able to work around it because I wanted to split on \n and \r\n, so I decided to split on \n and trimmed the end \r but it would not be possible in most other cases.

The api could look like:

let x: Vec<&[u8]> = b"Mary had a little lamb".split_str_many([" ", "a"]).collect();
assert_eq!(x, vec![
    B("M"), B("ry"), B("h"), B("d"), B(""), B("little"), B("l"), B("mb"),
]);

The order of the needles would be relevant here, so if the input was ["bl","l"], it would split table like ["ta","e"].
The haystack algo can still be used, but it would only be able to advance by the length of the smallest needle (unless match is found).

@BurntSushi
Copy link
Owner

I don't think I want to (currently, at least) support multi-substring stuff in bstr. For that, I'd rather you use the aho-corasick or regex crates. (The former doesn't have split APIs, but I think I'd be open to adding them. PRs are welcome. You can base it off the Split iterator in regex.)

Basically, if this API were added, it would require bringing aho-corasick in as a dependency anyway. We could make it optional, but it just seems like a lot of ceremony that would be better served by just using aho-corasick directly.

@BurntSushi BurntSushi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2023
@BurntSushi BurntSushi added the wontfix This will not be worked on label Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants