https://github.com/rustynova016/i_splits
More ways to split your strs!
https://github.com/rustynova016/i_splits
Last synced: 9 months ago
JSON representation
More ways to split your strs!
- Host: GitHub
- URL: https://github.com/rustynova016/i_splits
- Owner: RustyNova016
- License: unlicense
- Created: 2025-02-14T10:45:39.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-14T13:45:41.000Z (over 1 year ago)
- Last Synced: 2025-06-16T03:32:21.611Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# i_splits
This crate add two string splitting methods:
- `split_i`: Split the string in half at the occurence `i` of a pattern.
- `split_once_last`: Split the string in half at the last occurence of a pattern.
This crate use no dependencies and no unsafe code. This comes at a compromise of having to return `String`s instead of `&str`s, as well as only being able to pass `&str`s as patterns.
This is due to the fact that the `Pattern` trait isn't stable yet in std.
## Example
```rust
use i_splits::ISplitExt as _;
// split_i
let v = "To show you the power of i_split, I cut that sentence in half!".split_i(", ", 1);
assert_eq!(v, Some(("To show you the power of i_split".to_string(), "I cut that sentence in half!".to_string())));
let v = "cookie|lolipop|muffin|pancake".split_i("|", 2);
assert_eq!(v, Some(("cookie|lolipop".to_string(), "muffin|pancake".to_string())));
let v = "No splits? That's a `None` for you".split_i("!", 2);
assert_eq!(v, None);
let v = "Don't go too far either!".split_i(" ", 10);
assert_eq!(v, None);
// split_once_last
let v = "To show you the power of i_split, I cut that sentence in half!".split_once_last(", ");
assert_eq!(v, Some(("To show you the power of i_split".to_string(), "I cut that sentence in half!".to_string())));
let v = "cookie|lolipop|muffin|pancake".split_once_last("|");
assert_eq!(v, Some(("cookie|lolipop|muffin".to_string(), "pancake".to_string())));
```