|
nfx-stringutils 0.3.0
Modern C++20 header-only library providing high-performance string utilities and zero-allocation splitting
|
High-performance string utilities for NFX C++ library. More...
#include <cstdint>#include <optional>#include <string>#include <string_view>#include "nfx/detail/string/Utils.inl"

Go to the source code of this file.
Functions | |
| constexpr bool | nfx::string::hasExactLength (std::string_view str, std::size_t expectedLength) noexcept |
| Fast check if string has exact length. | |
| constexpr bool | nfx::string::isEmpty (std::string_view str) noexcept |
| Fast check if string is empty. | |
| constexpr bool | nfx::string::isNullOrWhiteSpace (std::string_view str) noexcept |
| Fast check if string is null, empty, or contains only whitespace. | |
| constexpr bool | nfx::string::isAllDigits (std::string_view str) noexcept |
| Check if string contains only ASCII digits. | |
| constexpr bool | nfx::string::isWhitespace (char c) noexcept |
| Check if character is whitespace. | |
| constexpr bool | nfx::string::isDigit (char c) noexcept |
| Check if character is ASCII digit. | |
| constexpr bool | nfx::string::isAlpha (char c) noexcept |
| Check if character is ASCII alphabetic. | |
| constexpr bool | nfx::string::isAlphaNumeric (char c) noexcept |
| Check if character is ASCII alphanumeric. | |
| constexpr bool | nfx::string::isHexDigit (char c) noexcept |
| Check if character is ASCII hexadecimal digit. | |
| constexpr bool | nfx::string::startsWith (std::string_view str, std::string_view prefix) noexcept |
| Fast check if string starts with prefix. | |
| constexpr bool | nfx::string::endsWith (std::string_view str, std::string_view suffix) noexcept |
| Fast check if string ends with suffix. | |
| constexpr bool | nfx::string::contains (std::string_view str, std::string_view substr) noexcept |
| Fast check if string contains substring. | |
| constexpr bool | nfx::string::equals (std::string_view lhs, std::string_view rhs) noexcept |
| Fast case-sensitive string comparison. | |
| bool | nfx::string::iequals (std::string_view lhs, std::string_view rhs) noexcept |
| Fast case-insensitive string comparison. | |
| std::size_t | nfx::string::count (std::string_view str, std::string_view substr) noexcept |
| Count occurrences of substring in string. | |
| std::size_t | nfx::string::countOverlapping (std::string_view str, std::string_view substr) noexcept |
| Count overlapping occurrences of substring in string. | |
| constexpr std::size_t | nfx::string::count (std::string_view str, char ch) noexcept |
| Count occurrences of character in string. | |
| std::string | nfx::string::replace (std::string_view str, std::string_view oldStr, std::string_view newStr) |
| Replace first occurrence of substring with replacement. | |
| std::string | nfx::string::replaceAll (std::string_view str, std::string_view oldStr, std::string_view newStr) |
| Replace all occurrences of substring with replacement. | |
| template<typename Container> | |
| std::string | nfx::string::join (const Container &elements, std::string_view delimiter) |
| Join container elements with delimiter. | |
| template<typename Iterator> | |
| std::string | nfx::string::join (Iterator begin, Iterator end, std::string_view delimiter) |
| Join iterator range with delimiter. | |
| std::string | nfx::string::reverse (std::string_view str) |
| Reverse a string. | |
| constexpr std::size_t | nfx::string::indexOf (std::string_view str, std::string_view substr) noexcept |
| Find first occurrence of substring. | |
| constexpr std::size_t | nfx::string::lastIndexOf (std::string_view str, std::string_view substr) noexcept |
| Find last occurrence of substring. | |
| std::string | nfx::string::padLeft (std::string_view str, std::size_t width, char fillChar=' ') |
| Pad string on the left to reach specified width. | |
| std::string | nfx::string::padRight (std::string_view str, std::size_t width, char fillChar=' ') |
| Pad string on the right to reach specified width. | |
| std::string | nfx::string::center (std::string_view str, std::size_t width, char fillChar=' ') |
| Center string within specified width. | |
| std::string | nfx::string::repeat (std::string_view str, std::size_t count) |
| Repeat string specified number of times. | |
| constexpr std::string_view | nfx::string::substringBefore (std::string_view str, std::string_view delimiter) noexcept |
| Extract substring before first occurrence of delimiter. | |
| constexpr std::string_view | nfx::string::substringAfter (std::string_view str, std::string_view delimiter) noexcept |
| Extract substring after first occurrence of delimiter. | |
| constexpr std::string_view | nfx::string::substringBeforeLast (std::string_view str, std::string_view delimiter) noexcept |
| Extract substring before last occurrence of delimiter. | |
| constexpr std::string_view | nfx::string::substringAfterLast (std::string_view str, std::string_view delimiter) noexcept |
| Extract substring after last occurrence of delimiter. | |
| constexpr std::string_view | nfx::string::extractBetween (std::string_view str, std::string_view start, std::string_view end) noexcept |
| Extract substring between start and end delimiters. | |
| constexpr std::string_view | nfx::string::removePrefix (std::string_view str, std::string_view prefix) noexcept |
| Remove prefix from string if present. | |
| constexpr std::string_view | nfx::string::removeSuffix (std::string_view str, std::string_view suffix) noexcept |
| Remove suffix from string if present. | |
| std::string | nfx::string::removeAll (std::string_view str, char ch) |
| Remove all occurrences of a character from string. | |
| std::string | nfx::string::removeAll (std::string_view str, std::string_view substr) |
| Remove all occurrences of a substring from string. | |
| template<typename Predicate> | |
| std::string | nfx::string::removeIf (std::string_view str, Predicate pred) |
| Remove all characters matching a predicate from string. | |
| std::string | nfx::string::removeWhitespace (std::string_view str) |
| Remove all whitespace characters from string. | |
| std::string | nfx::string::collapseWhitespace (std::string_view str) |
| Collapse consecutive whitespace characters to single space. | |
| constexpr std::string_view | nfx::string::trimStart (std::string_view str) noexcept |
| Remove leading whitespace from string. | |
| constexpr std::string_view | nfx::string::trimEnd (std::string_view str) noexcept |
| Remove trailing whitespace from string. | |
| constexpr std::string_view | nfx::string::trim (std::string_view str) noexcept |
| Remove leading and trailing whitespace from string. | |
| template<typename Predicate> | |
| constexpr std::string_view | nfx::string::trimStartIf (std::string_view str, Predicate pred) noexcept |
| Remove leading characters matching predicate. | |
| template<typename Predicate> | |
| constexpr std::string_view | nfx::string::trimEndIf (std::string_view str, Predicate pred) noexcept |
| Remove trailing characters matching predicate. | |
| template<typename Predicate> | |
| constexpr std::string_view | nfx::string::trimIf (std::string_view str, Predicate pred) noexcept |
| Remove leading and trailing characters matching predicate. | |
| template<typename Predicate> | |
| constexpr std::size_t | nfx::string::countIf (std::string_view str, Predicate pred) noexcept |
| Count characters matching predicate. | |
| template<typename Predicate> | |
| constexpr std::size_t | nfx::string::findIf (std::string_view str, Predicate pred) noexcept |
| Find first character matching predicate. | |
| template<typename Predicate> | |
| constexpr std::size_t | nfx::string::findIfNot (std::string_view str, Predicate pred) noexcept |
| Find first character NOT matching predicate. | |
| template<typename Predicate> | |
| std::string | nfx::string::replaceIf (std::string_view str, Predicate pred, char replacement) |
| Replace characters matching predicate with replacement character. | |
| std::string | nfx::string::toLower (std::string_view str) |
| Convert string to lowercase. | |
| std::string | nfx::string::toUpper (std::string_view str) |
| Convert string to uppercase. | |
| constexpr char | nfx::string::toLower (char c) noexcept |
| Convert ASCII character to lowercase. | |
| constexpr char | nfx::string::toUpper (char c) noexcept |
| Convert ASCII character to uppercase. | |
| constexpr bool | nfx::string::isUriReserved (char c) noexcept |
| Check if character is URI reserved (RFC 3986 Section 2.2). | |
| constexpr bool | nfx::string::isUriReserved (std::string_view str) noexcept |
| Check if string contains only URI reserved characters. | |
| constexpr bool | nfx::string::isUriUnreserved (char c) noexcept |
| Check if character is URI unreserved (RFC 3986 Section 2.3). | |
| constexpr bool | nfx::string::isUriUnreserved (std::string_view str) noexcept |
| Check if string contains only URI unreserved characters. | |
| std::string | nfx::string::urlEncode (std::string_view str) |
| Encode string for use in URLs (percent-encoding per RFC 3986). | |
| std::string | nfx::string::urlDecode (std::string_view str) noexcept |
| Decode percent-encoded URL string (RFC 3986). | |
| std::string | nfx::string::jsonEscape (std::string_view str) |
| Escape string for use in JSON (RFC 8259). | |
| std::string | nfx::string::jsonUnescape (std::string_view str) noexcept |
| Unescape JSON string literal (RFC 8259). | |
| std::string | nfx::string::xmlEscape (std::string_view str) |
| Escape string for use in XML/HTML content. | |
| std::string | nfx::string::xmlUnescape (std::string_view str) noexcept |
| Unescape XML/HTML entity references. | |
| std::string | nfx::string::cppEscape (std::string_view str) |
| Escape string for use as C/C++ string literal. | |
| std::string | nfx::string::cppUnescape (std::string_view str) noexcept |
| Unescape C/C++ string literal escape sequences. | |
| std::string | nfx::string::truncate (std::string_view str, size_t maxLength) |
| Truncate string to maximum length. | |
| std::string | nfx::string::truncate (std::string_view str, size_t maxLength, std::string_view ellipsis) |
| Truncate string to maximum length with ellipsis. | |
| std::string | nfx::string::wordWrap (std::string_view str, size_t width) |
| Wrap text to specified width. | |
| std::string | nfx::string::indent (std::string_view str, size_t spaces) |
| Add indentation to all lines. | |
| std::string | nfx::string::dedent (std::string_view str) |
| Remove common leading whitespace from all lines. | |
| constexpr int | nfx::string::compareIgnoreCase (std::string_view lhs, std::string_view rhs) noexcept |
| Case-insensitive three-way comparison. | |
| constexpr int | nfx::string::naturalCompare (std::string_view lhs, std::string_view rhs) noexcept |
| Natural sorting comparison (handles embedded numbers). | |
| constexpr std::string_view | nfx::string::commonPrefix (std::string_view lhs, std::string_view rhs) noexcept |
| Find longest common prefix of two strings. | |
| constexpr std::string_view | nfx::string::commonSuffix (std::string_view lhs, std::string_view rhs) noexcept |
| Find longest common suffix of two strings. | |
| constexpr bool | nfx::string::isIpv4Address (std::string_view str) noexcept |
| Validate IPv4 address format (RFC 791). | |
| constexpr bool | nfx::string::isIpv6Address (std::string_view str) noexcept |
| Validate IPv6 address format (RFC 4291, RFC 5952). | |
| constexpr bool | nfx::string::isHostname (std::string_view str) noexcept |
| Validate hostname format (RFC 1123). | |
| constexpr bool | nfx::string::isIdnHostname (std::string_view str) noexcept |
| Validate Internationalized Domain Name (IDN) hostname format. | |
| constexpr bool | nfx::string::isDomainName (std::string_view str) noexcept |
| Validate domain name format (RFC 1035). | |
| constexpr bool | nfx::string::isPortNumber (std::string_view str) noexcept |
| Validate port number string (RFC 6335). | |
| bool | nfx::string::tryParseEndpoint (std::string_view endpoint, std::string_view &host, uint16_t &port) noexcept |
| Parse network endpoint into host and port. | |
| constexpr bool | nfx::string::isDateTime (std::string_view str) noexcept |
| Validate RFC 3339 date-time format. | |
| constexpr bool | nfx::string::isDate (std::string_view str) noexcept |
| Validate RFC 3339 full-date format. | |
| constexpr bool | nfx::string::isTime (std::string_view str) noexcept |
| Validate RFC 3339 full-time format. | |
| constexpr bool | nfx::string::isDuration (std::string_view str) noexcept |
| Validate ISO 8601 duration format. | |
| constexpr bool | nfx::string::isEmail (std::string_view str) noexcept |
| Validate email address format (RFC 5321). | |
| constexpr bool | nfx::string::isIdnEmail (std::string_view str) noexcept |
| Validate Internationalized email address format (EAI/SMTPUTF8). | |
| constexpr bool | nfx::string::isUuid (std::string_view str) noexcept |
| Validate UUID format (RFC 4122). | |
| constexpr bool | nfx::string::isUri (std::string_view str) noexcept |
| Validate URI format (RFC 3986). | |
| constexpr bool | nfx::string::isUriReference (std::string_view str) noexcept |
| Validate URI-reference format (RFC 3986). | |
| constexpr bool | nfx::string::isUriTemplate (std::string_view str) noexcept |
| Validate URI Template format (RFC 6570). | |
| constexpr bool | nfx::string::isIri (std::string_view str) noexcept |
| Validate IRI format (RFC 3987). | |
| constexpr bool | nfx::string::isIriReference (std::string_view str) noexcept |
| Validate IRI-reference format (RFC 3987). | |
| constexpr bool | nfx::string::isJsonPointer (std::string_view str) noexcept |
| Validate JSON Pointer format (RFC 6901). | |
| constexpr bool | nfx::string::isRelativeJsonPointer (std::string_view str) noexcept |
| Validate relative JSON Pointer format. | |
High-performance string utilities for NFX C++ library.
Provides fast, zero-allocation string operations including validation, parsing, and comparison functions using std::string_view for maximum performance.
Definition in file Utils.h.
|
inlinenodiscard |
Center string within specified width.
| str | String to center |
| width | Target width (total length after padding) |
| fillChar | Character to use for padding (default: space) |
If padding is odd, extra character goes on the right. Example: center("Hi", 6, '*') returns "**Hi**"
|
inlinenodiscard |
Collapse consecutive whitespace characters to single space.
| str | String to process |
Allocates a new std::string. Trims leading/trailing whitespace and collapses consecutive whitespace (spaces, tabs, newlines) to single space. Example: collapseWhitespace(" hello world ") returns "hello world"
|
inlinenodiscardconstexprnoexcept |
Find longest common prefix of two strings.
| lhs | First string |
| rhs | Second string |
Returns a string_view pointing to the beginning of lhs that matches rhs. If no common prefix, returns empty string_view.
|
inlinenodiscardconstexprnoexcept |
Find longest common suffix of two strings.
| lhs | First string |
| rhs | Second string |
Returns a string_view pointing to the end of lhs that matches rhs. If no common suffix, returns empty string_view.
|
inlinenodiscardconstexprnoexcept |
Case-insensitive three-way comparison.
| lhs | First string to compare |
| rhs | Second string to compare |
Performs case-insensitive comparison similar to strcasecmp. Returns -1/0/+1 for ordering. ASCII-only conversion.
|
inlinenodiscardconstexprnoexcept |
Fast check if string contains substring.
| str | String to check |
| substr | Substring to find |
|
inlinenodiscardconstexprnoexcept |
Count occurrences of character in string.
| str | String to search in |
| ch | Character to count |
|
inlinenodiscardnoexcept |
Count occurrences of substring in string.
| str | String to search in |
| substr | Substring to count |
Returns 0 if substr is empty or not found. Counts non-overlapping matches.
|
inlinenodiscardconstexprnoexcept |
Count characters matching predicate.
| Predicate | Callable type accepting char and returning bool |
| str | String to count from |
| pred | Predicate function to test characters |
Predicate should return true for characters to count.
|
inlinenodiscardnoexcept |
Count overlapping occurrences of substring in string.
| str | String to search in |
| substr | Substring to count |
Returns 0 if substr is empty or not found. Counts all matches including overlapping ones. Example: countOverlapping("aaaa", "aa") returns 3 (positions 0, 1, 2)
|
inlinenodiscard |
Escape string for use as C/C++ string literal.
| str | String to escape |
Escapes common C++ escape sequences: newline -> \n, tab -> \t, carriage-return -> \r, backslash -> \\, double-quote -> \", single-quote -> \', null -> \0, backspace -> \b, form-feed -> \f, vertical-tab -> \v, alert -> \a. Other control characters are escaped as \xHH. This function allocates a new std::string.
|
inlinenodiscardnoexcept |
Unescape C/C++ string literal escape sequences.
| str | C++ string literal with escape sequences |
Unescapes all standard C++ escape sequences including: \n, \t, \r, \\, \", \', \0, \b, \f, \v, \a, hexadecimal (\xHH), and octal (\NNN) sequences. Returns empty string if malformed escape sequences are detected. This function allocates a new std::string.
|
inlinenodiscard |
Remove common leading whitespace from all lines.
| str | Text to dedent |
Finds the minimum indentation across all non-empty lines and removes that amount of leading whitespace from every line. This function allocates a new std::string.
|
inlinenodiscardconstexprnoexcept |
Fast check if string ends with suffix.
| str | String to check |
| suffix | Suffix to find |
|
inlinenodiscardconstexprnoexcept |
Fast case-sensitive string comparison.
| lhs | First string |
| rhs | Second string |
|
inlinenodiscardconstexprnoexcept |
Extract substring between start and end delimiters.
| str | String to search in |
| start | Starting delimiter |
| end | Ending delimiter |
Zero-allocation. Searches for first occurrence of start, then first occurrence of end after that. Example: extractBetween("Hello [world] test", "[", "]") returns "world"
|
inlinenodiscardconstexprnoexcept |
Find first character matching predicate.
| Predicate | Callable type accepting char and returning bool |
| str | String to search |
| pred | Predicate function to test characters |
Predicate should return true for the character to find.
|
inlinenodiscardconstexprnoexcept |
Find first character NOT matching predicate.
| Predicate | Callable type accepting char and returning bool |
| str | String to search |
| pred | Predicate function to test characters |
Predicate should return true for characters to skip.
|
inlinenodiscardconstexprnoexcept |
Fast check if string has exact length.
| str | String to check |
| expectedLength | Expected length |
|
inlinenodiscardnoexcept |
Fast case-insensitive string comparison.
| lhs | First string |
| rhs | Second string |
|
inlinenodiscard |
Add indentation to all lines.
| str | Text to indent |
| spaces | Number of spaces to indent each line |
Adds the specified number of spaces to the beginning of each line, including the first line. Empty lines are also indented. This function allocates a new std::string.
|
inlinenodiscardconstexprnoexcept |
Find first occurrence of substring.
| str | String to search in |
| substr | Substring to find |
Returns 0 for empty substr. Case-sensitive search. Example: indexOf("hello world", "world") returns 6
|
inlinenodiscardconstexprnoexcept |
Check if string contains only ASCII digits.
| str | String to check |
Returns false for empty strings. Uses the existing isDigit() function for validation.
|
inlinenodiscardconstexprnoexcept |
Check if character is ASCII alphabetic.
| c | Character to check |
|
inlinenodiscardconstexprnoexcept |
Check if character is ASCII alphanumeric.
| c | Character to check |
|
inlinenodiscardconstexprnoexcept |
Validate RFC 3339 full-date format.
| str | String to validate |
Validates YYYY-MM-DD format with proper month/day ranges.
|
inlinenodiscardconstexprnoexcept |
Validate RFC 3339 date-time format.
| str | String to validate |
Validates YYYY-MM-DDTHH:MM:SS with optional fractional seconds and timezone. Timezone can be 'Z' or ±HH:MM offset. Does not allocate memory.
|
inlinenodiscardconstexprnoexcept |
Check if character is ASCII digit.
| c | Character to check |
|
inlinenodiscardconstexprnoexcept |
Validate domain name format (RFC 1035).
| str | String to validate |
Validates fully qualified domain names (FQDN). Stricter than hostname validation. Must contain at least one dot. Examples: "example.com", "mail.google.com"
|
inlinenodiscardconstexprnoexcept |
Validate ISO 8601 duration format.
| str | String to validate |
Validates P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W format.
|
inlinenodiscardconstexprnoexcept |
Validate email address format (RFC 5321).
| str | String to validate |
Validates basic email format: local-part followed by at-sign and domain. Not exhaustive per RFC 5321.
|
inlinenodiscardconstexprnoexcept |
Fast check if string is empty.
| str | String to check |
|
inlinenodiscardconstexprnoexcept |
Check if character is ASCII hexadecimal digit.
| c | Character to check |
|
inlinenodiscardconstexprnoexcept |
Validate hostname format (RFC 1123).
| str | String to validate |
Validates DNS hostname format: labels separated by dots, alphanumeric with hyphens. Max length 253 characters, labels max 63 characters. Case-insensitive. Examples: "localhost", "example.com", "my-server-01.local"
|
inlinenodiscardconstexprnoexcept |
Validate Internationalized email address format (EAI/SMTPUTF8).
| str | String to validate |
Validates email addresses containing Unicode characters in the local-part or domain.
|
inlinenodiscardconstexprnoexcept |
Validate Internationalized Domain Name (IDN) hostname format.
| str | String to validate |
Validates hostnames containing Unicode characters (IDN).
|
inlinenodiscardconstexprnoexcept |
Validate IPv4 address format (RFC 791).
| str | String to validate |
Validates dotted-decimal notation with four octets (0-255 each).
|
inlinenodiscardconstexprnoexcept |
Validate IPv6 address format (RFC 4291, RFC 5952).
| str | String to validate |
Validates standard and compressed notation.
|
inlinenodiscardconstexprnoexcept |
Validate IRI format (RFC 3987).
| str | String to validate |
Validates Internationalized Resource Identifier with Unicode characters.
|
inlinenodiscardconstexprnoexcept |
Validate IRI-reference format (RFC 3987).
| str | String to validate |
Validates IRI or relative-reference with Unicode support (scheme optional).
|
inlinenodiscardconstexprnoexcept |
Validate JSON Pointer format (RFC 6901).
| str | String to validate |
Validates empty string or sequence of /reference-token. Escape sequences ~0 and ~1 are validated.
|
inlinenodiscardconstexprnoexcept |
Fast check if string is null, empty, or contains only whitespace.
| str | String to check |
Considers space, tab, newline, carriage return, form feed, and vertical tab as whitespace
|
inlinenodiscardconstexprnoexcept |
Validate port number string (RFC 6335).
| str | String to validate |
Validates string contains only digits and value is in valid port range. Examples: "80", "8080", "443", "65535"
|
inlinenodiscardconstexprnoexcept |
Validate relative JSON Pointer format.
| str | String to validate |
Validates non-negative integer followed by either # or JSON Pointer.
|
inlinenodiscardconstexprnoexcept |
Validate RFC 3339 full-time format.
| str | String to validate |
Validates HH:MM:SS with optional fractional seconds and required timezone.
|
inlinenodiscardconstexprnoexcept |
Validate URI format (RFC 3986).
| str | String to validate |
Validates scheme://authority/path?query::fragment format.
|
inlinenodiscardconstexprnoexcept |
Validate URI-reference format (RFC 3986).
| str | String to validate |
Validates URI or relative-reference (scheme optional).
|
inlinenodiscardconstexprnoexcept |
Check if character is URI reserved (RFC 3986 Section 2.2).
| c | Character to check |
|
inlinenodiscardconstexprnoexcept |
Check if string contains only URI reserved characters.
| str | String to check |
Returns false for empty strings. Uses RFC 3986 Section 2.2 definition.
|
inlinenodiscardconstexprnoexcept |
Validate URI Template format (RFC 6570).
| str | String to validate |
Validates URI templates with {expression} syntax. Expressions may contain operator prefixes (+, #, ., /, ;, ?, &) and variable names. No whitespace allowed. Braces must be balanced.
|
inlinenodiscardconstexprnoexcept |
Check if character is URI unreserved (RFC 3986 Section 2.3).
| c | Character to check |
|
inlinenodiscardconstexprnoexcept |
Check if string contains only URI unreserved characters.
| str | String to check |
Returns false for empty strings. Uses RFC 3986 Section 2.3 definition.
|
inlinenodiscardconstexprnoexcept |
Validate UUID format (RFC 4122).
| str | String to validate |
Validates 8-4-4-4-12 hexadecimal digit format with hyphens.
|
inlinenodiscardconstexprnoexcept |
Check if character is whitespace.
| c | Character to check |
|
inlinenodiscard |
Join container elements with delimiter.
| Container | Container type (must support begin()/end() and value_type convertible to string_view) |
| elements | Container of elements to join |
| delimiter | Delimiter to insert between elements |
Returns empty string for empty container. Single element returns that element without delimiter.
|
inlinenodiscard |
Join iterator range with delimiter.
| Iterator | Forward iterator type (value_type must be convertible to string_view) |
| begin | Iterator to first element |
| end | Iterator past last element |
| delimiter | Delimiter to insert between elements |
Returns empty string for empty range. Single element returns that element without delimiter.
|
inlinenodiscard |
Escape string for use in JSON (RFC 8259).
| str | String to escape |
Escapes: quote, backslash, slash, backspace, form-feed, newline, carriage-return, tab and control characters (U+0000 to U+001F) as \uXXXX Unicode escape sequences. This function allocates a new std::string.
|
inlinenodiscardnoexcept |
Unescape JSON string literal (RFC 8259).
| str | Escaped JSON string to unescape |
Unescapes all standard JSON escape sequences and \uXXXX Unicode sequences. Returns empty string if malformed escape sequences are detected. This function allocates a new std::string.
|
inlinenodiscardconstexprnoexcept |
Find last occurrence of substring.
| str | String to search in |
| substr | Substring to find |
Returns 0 for empty substr. Case-sensitive search. Example: lastIndexOf("hello hello", "hello") returns 6
|
inlinenodiscardconstexprnoexcept |
Natural sorting comparison (handles embedded numbers).
| lhs | First string to compare |
| rhs | Second string to compare |
Compares strings naturally, treating embedded numbers as integers. Example: "file2.txt" < "file10.txt" (not "file10.txt" < "file2.txt"). Useful for sorting filenames, version numbers, etc.
|
inlinenodiscard |
Pad string on the left to reach specified width.
| str | String to pad |
| width | Target width (total length after padding) |
| fillChar | Character to use for padding (default: space) |
Example: padLeft("42", 5, '0') returns "00042"
|
inlinenodiscard |
Pad string on the right to reach specified width.
| str | String to pad |
| width | Target width (total length after padding) |
| fillChar | Character to use for padding (default: space) |
Example: padRight("42", 5, '0') returns "42000"
|
inlinenodiscard |
Remove all occurrences of a character from string.
| str | String to process |
| ch | Character to remove |
Allocates a new std::string. Example: removeAll("hello", 'l') returns "heo"
|
inlinenodiscard |
Remove all occurrences of a substring from string.
| str | String to process |
| substr | Substring to remove |
Allocates a new std::string. Does not handle overlapping matches. Example: removeAll("hello world", "l") returns "heo word"
|
inlinenodiscard |
Remove all characters matching a predicate from string.
| Predicate | Callable type accepting char and returning bool |
| str | String to process |
| pred | Predicate function or lambda to test each character |
Allocates a new std::string. Example: removeIf("hello123", isDigit) returns "hello"
|
inlinenodiscardconstexprnoexcept |
Remove prefix from string if present.
| str | String to process |
| prefix | Prefix to remove |
Zero-allocation. Example: removePrefix("HelloWorld", "Hello") returns "World"
|
inlinenodiscardconstexprnoexcept |
Remove suffix from string if present.
| str | String to process |
| suffix | Suffix to remove |
Zero-allocation. Example: removeSuffix("HelloWorld", "World") returns "Hello"
|
inlinenodiscard |
Remove all whitespace characters from string.
| str | String to process |
Allocates a new std::string. Removes spaces, tabs, newlines, etc. Example: removeWhitespace("hello world") returns "helloworld"
|
inlinenodiscard |
Repeat string specified number of times.
| str | String to repeat |
| count | Number of repetitions |
Example: repeat("*", 5) returns "*****"
|
inlinenodiscard |
Replace first occurrence of substring with replacement.
| str | String to search in |
| oldStr | Substring to replace |
| newStr | Replacement string |
Returns original string if oldStr is empty
|
inlinenodiscard |
Replace all occurrences of substring with replacement.
| str | String to search in |
| oldStr | Substring to replace |
| newStr | Replacement string |
Returns original string if oldStr is empty or not found
|
inlinenodiscard |
Replace characters matching predicate with replacement character.
| Predicate | Callable type accepting char and returning bool |
| str | String to process |
| pred | Predicate function to test characters |
| replacement | Character to replace matching characters with |
Predicate should return true for characters to replace. This function allocates a new std::string.
|
inlinenodiscard |
Reverse a string.
| str | String to reverse |
Returns empty string for empty input. Efficient single-pass algorithm. Example: reverse("hello") returns "olleh"
|
inlinenodiscardconstexprnoexcept |
Fast check if string starts with prefix.
| str | String to check |
| prefix | Prefix to find |
|
inlinenodiscardconstexprnoexcept |
Extract substring after first occurrence of delimiter.
| str | String to search in |
| delimiter | Delimiter to search for |
Zero-allocation. Example: substringAfter("hello.world.txt", ".") returns "world.txt"
|
inlinenodiscardconstexprnoexcept |
Extract substring after last occurrence of delimiter.
| str | String to search in |
| delimiter | Delimiter to search for |
Zero-allocation. Example: substringAfterLast("hello.world.txt", ".") returns "txt"
|
inlinenodiscardconstexprnoexcept |
Extract substring before first occurrence of delimiter.
| str | String to search in |
| delimiter | Delimiter to search for |
Zero-allocation. Example: substringBefore("hello.world.txt", ".") returns "hello"
|
inlinenodiscardconstexprnoexcept |
Extract substring before last occurrence of delimiter.
| str | String to search in |
| delimiter | Delimiter to search for |
Zero-allocation. Example: substringBeforeLast("hello.world.txt", ".") returns "hello.world"
|
inlinenodiscardconstexprnoexcept |
Convert ASCII character to lowercase.
| c | Character to convert |
Only works with ASCII characters (A-Z, a-z). Non-ASCII characters are returned unchanged.
|
inlinenodiscard |
Convert string to lowercase.
| str | String to convert |
Only ASCII characters (A-Z) are converted. Non-ASCII characters are preserved unchanged. This function allocates a new std::string.
|
inlinenodiscardconstexprnoexcept |
Convert ASCII character to uppercase.
| c | Character to convert |
Only works with ASCII characters (A-Z, a-z). Non-ASCII characters are returned unchanged.
|
inlinenodiscard |
Convert string to uppercase.
| str | String to convert |
Only ASCII characters (a-z) are converted. Non-ASCII characters are preserved unchanged. This function allocates a new std::string.
|
inlinenodiscardconstexprnoexcept |
Remove leading and trailing whitespace from string.
| str | String to trim |
Returns a view into the original string, no allocation performed
|
inlinenodiscardconstexprnoexcept |
Remove trailing whitespace from string.
| str | String to trim |
Returns a view into the original string, no allocation performed
|
inlinenodiscardconstexprnoexcept |
Remove trailing characters matching predicate.
| Predicate | Callable type accepting char and returning bool |
| str | String to trim |
| pred | Predicate function to test characters |
Returns a view into the original string, no allocation performed. Predicate should return true for characters to remove.
|
inlinenodiscardconstexprnoexcept |
Remove leading and trailing characters matching predicate.
| Predicate | Callable type accepting char and returning bool |
| str | String to trim |
| pred | Predicate function to test characters |
Returns a view into the original string, no allocation performed. Predicate should return true for characters to remove.
|
inlinenodiscardconstexprnoexcept |
Remove leading whitespace from string.
| str | String to trim |
Returns a view into the original string, no allocation performed
|
inlinenodiscardconstexprnoexcept |
Remove leading characters matching predicate.
| Predicate | Callable type accepting char and returning bool |
| str | String to trim |
| pred | Predicate function to test characters |
Returns a view into the original string, no allocation performed. Predicate should return true for characters to remove.
|
inlinenodiscard |
Truncate string to maximum length.
| str | String to truncate |
| maxLength | Maximum length of result |
If string is longer than maxLength, it is truncated to exactly maxLength characters. This function allocates a new std::string.
|
inlinenodiscard |
Truncate string to maximum length with ellipsis.
| str | String to truncate |
| maxLength | Maximum length of result (including ellipsis) |
| ellipsis | String to append when truncating (default: "...") |
If string is longer than maxLength, it is truncated and ellipsis is appended. The total length including ellipsis will not exceed maxLength. This function allocates a new std::string.
|
inlinenodiscardnoexcept |
Parse network endpoint into host and port.
| endpoint | Endpoint string to parse |
| host | Output parameter for host portion |
| port | Output parameter for port number |
Supports formats: "host:port", "ipv4:port", "[ipv6]:port" IPv6 addresses must be enclosed in brackets. Examples: "localhost:8080", "192.168.1.1:80", "[::1]:443"
|
inlinenodiscardnoexcept |
Decode percent-encoded URL string (RFC 3986).
| str | Percent-encoded string to decode |
Decodes XX sequences to their corresponding characters. Returns empty string if malformed encoding is detected (invalid hex digits). This function allocates a new std::string.
|
inlinenodiscard |
Encode string for use in URLs (percent-encoding per RFC 3986).
| str | String to encode |
Encodes all characters except unreserved characters (A-Z, a-z, 0-9, -, ., _, ~). Reserved characters and all other characters are percent-encoded as XX. This function allocates a new std::string.
|
inlinenodiscard |
Wrap text to specified width.
| str | Text to wrap |
| width | Maximum width per line |
Breaks text at word boundaries when possible. If a single word is longer than width, it will be placed on its own line exceeding the width. Existing newlines are preserved. This function allocates a new std::string.
|
inlinenodiscard |
Escape string for use in XML/HTML content.
| str | String to escape |
Escapes the five predefined XML entities: & (ampersand) -> & < (less-than) -> < > (greater-than) -> > " (quote) -> " ' (apostrophe) -> ' This function allocates a new std::string.
|
inlinenodiscardnoexcept |
Unescape XML/HTML entity references.
| str | XML/HTML string with entity references |
Unescapes predefined XML entities (&, <, >, ", ') and numeric character references (&xHHHH; and &DDDD;). Returns empty string if malformed entity references are detected. This function allocates a new std::string.