string
String manipulation and formatting helpers.
Install
Section titled “Install”Cargo feature string (enabled by default). To compile only this module:
or in Cargo.toml:
Opt-in sub-feature string-diacritics (adds the unicode-normalization dependency): remove_diacritics.
Import path: helpers4::string.
| Item | What it does |
|---|---|
camel_case | Converts s to camelCase. |
capitalize | Uppercases the first character of s and leaves the rest untouched. |
constant_case | Converts s to CONSTANT_CASE (also known as SCREAMING_SNAKE_CASE). |
dedent | Strips the indentation shared by every non-blank line of s, and drops one leading and one trailing blank line. |
escape_html | Escapes the HTML special characters &, <, >, " and '. |
escape_regex | Escapes regular expression metacharacters (`. |
excerpt | Derives a short, readable excerpt from a longer text — for a card, header or preview where a full paragraph does not fit. |
indent | Prefixes every non-blank line of s with prefix. |
kebab_case | Converts s to kebab-case. |
levenshtein_distance | The Levenshtein edit distance between a and b: the fewest single-character insertions, deletions or substitutions needed to turn one into the other. |
levenshtein_similarity | Normalized levenshtein_distance between a and b, in [0, 1]. |
pascal_case | Converts s to PascalCase. |
remove_diacritics | Removes diacritical marks (accents) from s, e.g. |
slugify | Converts s into a lowercase, hyphen-separated slug safe for URLs. |
snake_case | Converts s to snake_case. |
squish | Trims s and collapses every run of whitespace into a single space. |
title_case | Capitalizes the first letter of every whitespace-separated word and lowercases the rest. |
truncate | Shortens s to at most max_chars characters, ending with suffix when it was cut. |
unescape_html | Decodes the HTML entities &, <, >, ", ', ' and any numeric character reference (A, A). |
words | Splits s into its words, keeping their original casing. |
