Crate strtools

Source
Expand description

This crate provides the StrTools trait which exposes a variety of helper functions for handling strings for use cases like handling user input.

§Examples

use strtools::StrTools;

// split a string by some separator but ignore escaped ones
let parts: Vec<_> = r"this string\ is split by\ spaces and commas, unless they are\ escaped"
    .split_non_escaped_sanitize('\\', [' ', ','])?
    .collect();

assert_eq!(
    parts,
    [
        "this",
        "string is",
        "split",
        "by spaces",
        "and",
        "commas",
        "",
        "unless",
        "they",
        "are escaped"
    ]
);
use strtools::StrTools;

let parts: Vec<_> = r"\.\/.*s(\d\d)e(\d\d[a-d])/S$1E$2/gu"
    .split_non_escaped_sanitize('\\', '/')?
    .collect();

// parsing user input regex rules like `<rule>/<replace>/<flags>`
// the rule contained an escaped separator but we don't want to
// actually escape it for the regex engine
assert_eq!(parts, [r"\./.*s(\d\d)e(\d\d[a-d])", "S$1E$2", "gu"]);

Modules§

escape
This module contains functions with the primary purpose of escaping characters in strs.
find
This module contains functions with the primary purpose of searching strs.
parse
This module contains parsing extensions to the standard library implementations. Notably implementations of FromStrFront/FromStrBack which will try to parse as much of a string as it can.
split
This module contains functions with the primary purpose of splitting strs.
util
This module contains helper functions and types, some for easy of use, some for upholding some invariants statically.

Traits§

StrTools
The main trait of this crate, providing various extension methods for str. See the individual function documentation for more info. The methods on this trait are subject to change during the development of the crates core functionality.