Crate str_utils

Crate str_utils 

Source
Expand description

§str Utils

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

Traits§

EndsWithIgnoreAsciiCase
To extend [u8] and str to have ends_with_ignore_ascii_case, ends_with_ignore_ascii_case_with_lowercase and ends_with_ignore_ascii_case_with_uppercase methods.
EndsWithIgnoreAsciiCaseMultiple
To extend [u8] and str to have ends_with_ignore_ascii_case_multiple, ends_with_ignore_ascii_case_with_lowercase_multiple and ends_with_ignore_ascii_case_with_uppercase_multiple methods.
EndsWithIgnoreCasealloc
To extend str to have a ends_with_ignore_case method.
EndsWithMultiple
To extend [u8] and str to have a ends_with_multiple method.
EqIgnoreAsciiCase
To extend [u8] and str to have eq_ignore_ascii_case_with_lowercase and eq_ignore_ascii_case_with_uppercase methods.
EqIgnoreAsciiCaseMultiple
To extend [u8] and str to have eq_ignore_ascii_case_multiple, eq_ignore_ascii_case_with_lowercase_multiple and eq_ignore_ascii_case_with_uppercase_multiple methods.
EqIgnoreCaseunicase
To extend str to have a eq_ignore_case method.
EqMultiple
To extend [u8] and str to have a eq_multiple method.
EscapeCharactersalloc
To extend str and Cow<str> to have escape_characters and escape_ascii_characters method.
IsAsciiLowercased
To extend [u8] and str to have is_ascii_lowercased method.
IsAsciiUppercased
To extend [u8] and str to have is_ascii_uppercased method.
IsLowercased
To extend str to have is_lowercased method.
IsUppercased
To extend str to have is_uppercased method.
RemoveInvisibleCharactersalloc
To extend str and Cow<str> to have remove_all_invisible_characters method.
ReplaceNewlinesWithSpacealloc
To extend str and Cow<str> to have replace_newlines_with_space method.
StartsWithIgnoreAsciiCase
To extend [u8] and str to have starts_with_ignore_ascii_case, starts_with_ignore_ascii_case_with_lowercase and starts_with_ignore_ascii_case_with_uppercase methods.
StartsWithIgnoreAsciiCaseMultiple
To extend [u8] and str to have starts_with_ignore_ascii_case_multiple, starts_with_ignore_ascii_case_with_lowercase_multiple and starts_with_ignore_ascii_case_with_uppercase_multiple methods.
StartsWithIgnoreCasealloc
To extend str to have a starts_with_ignore_case method.
StartsWithMultiple
To extend [u8] and str to have a starts_with_multiple method.
ToLowercasealloc
To extend str and Cow<str> to have to_lowercase_cow and to_ascii_lowercase_cow methods.
ToUppercasealloc
To extend str and Cow<str> to have to_uppercase_cow and to_ascii_uppercase_cow methods.
Trimalloc
To extend Cow<str> to have trim_cow, trim_start_cow, trim_end_cow, trim_ascii_cow, trim_ascii_start_cow, trim_ascii_end_cow methods.