stringslice
A collection of methods to slice strings based on character indices rather than bytes.
This crate implements the StringSlice trait for &str,
containing the slice, try_slice, substring, and try_substring methods.
Features
- Uses primitive
&strand standardStringtypes #[no_std]compatible by default- No
unsafecode - Small footprint
- ~50 LoC excluding blank lines, comments, and tests
- No additional dependencies (only dev-dependencies)
Usage
Add stringslice to your Cargo.toml file:
[]
= "0.1"
Examples
The slice method can be used to slice a &str.
use StringSlice;
assert_eq!;
assert_eq!;
The substring method is provided for convenience and accepts
separate parameters for the start and end of the slice.
use StringSlice;
assert_eq!;
There are also equivalent try_slice and try_substring methods
which return None for invalid input.
use StringSlice;
assert_eq!;
Documentation
Licence
Licensed under either of
- Apache License, Version 2.0, (LICENCE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENCE-MIT or http://opensource.org/licenses/MIT)
at your option.