#string #fluent #character #cow

no-std str-utils

This crate provides some traits to extend [u8], str and Cow<str>

13 releases

0.3.1 Nov 1, 2025
0.2.1 Oct 29, 2025
0.1.8 May 29, 2025
0.1.7 Sep 11, 2023
0.1.2 Jul 29, 2020

#638 in Text processing

Download history 183/week @ 2026-02-10 190/week @ 2026-02-17 159/week @ 2026-02-24 240/week @ 2026-03-03 310/week @ 2026-03-10 266/week @ 2026-03-17 306/week @ 2026-03-24 685/week @ 2026-03-31 364/week @ 2026-04-07 419/week @ 2026-04-14 469/week @ 2026-04-21 229/week @ 2026-04-28 738/week @ 2026-05-05 552/week @ 2026-05-12 446/week @ 2026-05-19 376/week @ 2026-05-26

2,123 downloads per month
Used in 9 crates (6 directly)

MIT license

60KB
1.5K SLoC

str Utils

CI

This crate provides some traits to extend [u8], str and Cow<str>.

Examples

use str_utils::*;

assert_eq!(true, "foobar".starts_with_ignore_ascii_case("FoO"));
assert_eq!(Some(1), "photo.jpg".ends_with_ignore_ascii_case_multiple(&[".png", ".jpg", ".gif"]));
assert_eq!(true, "http".eq_ignore_ascii_case_with_uppercase("HTTP")); // faster than `eq_ignore_ascii_case`
assert_eq!(true, "foobar".starts_with_ignore_ascii_case("FoO"));

assert_eq!("here is a ZERO_WIDTH_SPACE -> ​".len() - 3, "here is a ZERO_WIDTH_SPACE -> ​".remove_all_invisible_characters().len());

assert_eq!(r"foo\% b\_r", r"foo% b_r".escape_ascii_characters(b'\\', b"%_"));

assert!(!"AaBb\u{0130}Zz".is_lowercased());
assert!(!"AaBbZz".is_ascii_lowercased());
assert!(!"aabbßzz".is_uppercased());
assert!(!"aabbzz".is_ascii_uppercased());

assert_eq!("aabbi\u{0307}zz", "AaBb\u{0130}Zz".to_lowercase_cow());
assert_eq!("aabb\u{0130}zz", "AaBb\u{0130}Zz".to_ascii_lowercase_cow());
assert_eq!("AABBSSZZ", "aabbßzz".to_uppercase_cow());
assert_eq!("AABBßZZ", "aabbßzz".to_ascii_uppercase_cow());

assert_eq!("Line 1 Line 2 Line 2 Line 3 Line 4 Line 5", "Line 1\r\nLine 2\r\nLine 2\rLine 3\nLine 4\nLine 5".replace_newlines_with_space());

assert_eq!("abc", Cow::from(" abc ").trim_cow()); // the `trim_cow` family of methods can be used on a `Cow<str>` to allow fluent method chaining.

No Std

Disable the default features to compile this crate without std.

[dependencies.str-utils]
version = "*"
default-features = false

Crates.io

https://crates.io/crates/str-utils

Documentation

https://docs.rs/str-utils

License

MIT

Dependencies

~98KB