Crates.io | stringslice |
lib.rs | stringslice |
version | 0.2.0 |
source | src |
created_at | 2021-03-17 03:25:02.346387 |
updated_at | 2024-01-01 16:19:05.098756 |
description | A collection of methods to slice strings based on character indices rather than bytes |
homepage | |
repository | https://github.com/staticintlucas/stringslice |
max_upload_size | |
id | 370036 |
size | 26,062 |
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.
&str
and standard String
types#[no_std]
compatible by defaultAdd stringslice
to your Cargo.toml
file:
[dependencies]
stringslice = "0.2"
The slice
method can be used to slice a &str
.
use stringslice::StringSlice;
assert_eq!("Ùníc😎de".slice(4..5), "😎");
assert_eq!("世界こんにちは".slice(2..), "こんにちは");
The substring
method is provided for convenience and accepts
separate parameters for the start and end of the slice.
use stringslice::StringSlice;
assert_eq!("Γεια σου κόσμε".substring(9, 14), "κόσμε");
There are also equivalent try_slice
and try_substring
methods
which return None
for invalid input.
use stringslice::StringSlice;
assert_eq!("string".try_slice(4..2), None);
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.