#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

#776 in Algorithms

Download history 166/week @ 2022-04-24 275/week @ 2022-05-01 165/week @ 2022-05-08 232/week @ 2022-05-15 346/week @ 2022-05-22 161/week @ 2022-05-29 155/week @ 2022-06-05 205/week @ 2022-06-12 177/week @ 2022-06-19 161/week @ 2022-06-26 201/week @ 2022-07-03 167/week @ 2022-07-10 279/week @ 2022-07-17 487/week @ 2022-07-24 517/week @ 2022-07-31 314/week @ 2022-08-07

1,611 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