#string #slice #substring #unicode #utf-8

no-std stringslice

A collection of methods to slice strings based on character indices rather than bytes

3 releases

Uses old Rust 2015

0.1.2 Mar 20, 2021
0.1.1 Mar 17, 2021
0.1.0 Mar 17, 2021

#837 in Text processing

Download history 186/week @ 2022-11-29 128/week @ 2022-12-06 135/week @ 2022-12-13 181/week @ 2022-12-20 250/week @ 2022-12-27 156/week @ 2023-01-03 138/week @ 2023-01-10 262/week @ 2023-01-17 187/week @ 2023-01-24 401/week @ 2023-01-31 276/week @ 2023-02-07 221/week @ 2023-02-14 111/week @ 2023-02-21 139/week @ 2023-02-28 121/week @ 2023-03-07 290/week @ 2023-03-14

674 downloads per month

MIT/Apache

11KB
87 lines

stringslice

Build status Test status Code coverage Crate version Rust version Downloads

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 &str and standard String types
  • #[no_std] compatible by default
  • Small footprint
    • ~50 LoC excluding blank lines, comments, and tests
    • No additional dependencies (only dev-dependencies)

Usage

Add stringslice to your Cargo.toml file:

[dependencies]
stringslice = "0.1"

Examples

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);

Documentation

Licence

Licensed under either of

at your option.

No runtime deps