Skip to content

string

String manipulation and formatting helpers.

Cargo feature string (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features string

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.5", default-features = false, features = ["string"] }

Import path: helpers4::string.

ItemWhat it does
camel_caseConverts s to camelCase.
capitalizeUppercases the first character of s and leaves the rest untouched.
constant_caseConverts s to CONSTANT_CASE (also known as SCREAMING_SNAKE_CASE).
dedentStrips the indentation shared by every non-blank line of s, and drops one leading and one trailing blank line.
escape_htmlEscapes the HTML special characters &, <, >, " and '.
indentPrefixes every non-blank line of s with prefix.
kebab_caseConverts s to kebab-case.
pascal_caseConverts s to PascalCase.
slugifyConverts s into a lowercase, hyphen-separated slug safe for URLs.
snake_caseConverts s to snake_case.
squishTrims s and collapses every run of whitespace into a single space.
title_caseCapitalizes the first letter of every whitespace-separated word and lowercases the rest.
truncateShortens s to at most max_chars characters, ending with suffix when it was cut.
unescape_htmlDecodes the HTML entities &amp;, &lt;, &gt;, &quot;, &apos;, &#39; and any numeric character reference (&#65;, &#x41;).