nfx-stringutils 0.3.0
Modern C++20 header-only library providing high-performance string utilities and zero-allocation splitting
Loading...
Searching...
No Matches
Utils.h File Reference

High-performance string utilities for NFX C++ library. More...

#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
#include "nfx/detail/string/Utils.inl"
Include dependency graph for Utils.h:
This graph shows which files directly or indirectly include this file:

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.

Detailed Description

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.

Function Documentation

◆ center()

std::string nfx::string::center ( std::string_view str,
std::size_t width,
char fillChar = ' ' )
inlinenodiscard

Center string within specified width.

Parameters
strString to center
widthTarget width (total length after padding)
fillCharCharacter to use for padding (default: space)
Returns
Centered string with fillChar on both sides. Returns original if already wider than width.

If padding is odd, extra character goes on the right. Example: center("Hi", 6, '*') returns "**Hi**"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ collapseWhitespace()

std::string nfx::string::collapseWhitespace ( std::string_view str)
inlinenodiscard

Collapse consecutive whitespace characters to single space.

Parameters
strString to process
Returns
New string with consecutive whitespace collapsed and trimmed

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"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ commonPrefix()

std::string_view nfx::string::commonPrefix ( std::string_view lhs,
std::string_view rhs )
inlinenodiscardconstexprnoexcept

Find longest common prefix of two strings.

Parameters
lhsFirst string
rhsSecond string
Returns
View of the common prefix substring

Returns a string_view pointing to the beginning of lhs that matches rhs. If no common prefix, returns empty string_view.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ commonSuffix()

std::string_view nfx::string::commonSuffix ( std::string_view lhs,
std::string_view rhs )
inlinenodiscardconstexprnoexcept

Find longest common suffix of two strings.

Parameters
lhsFirst string
rhsSecond string
Returns
View of the common suffix substring

Returns a string_view pointing to the end of lhs that matches rhs. If no common suffix, returns empty string_view.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ compareIgnoreCase()

int nfx::string::compareIgnoreCase ( std::string_view lhs,
std::string_view rhs )
inlinenodiscardconstexprnoexcept

Case-insensitive three-way comparison.

Parameters
lhsFirst string to compare
rhsSecond string to compare
Returns
Negative if lhs < rhs, 0 if equal, positive if lhs > rhs

Performs case-insensitive comparison similar to strcasecmp. Returns -1/0/+1 for ordering. ASCII-only conversion.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ contains()

bool nfx::string::contains ( std::string_view str,
std::string_view substr )
inlinenodiscardconstexprnoexcept

Fast check if string contains substring.

Parameters
strString to check
substrSubstring to find
Returns
True if str contains substr
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ count() [1/2]

std::size_t nfx::string::count ( std::string_view str,
char ch )
inlinenodiscardconstexprnoexcept

Count occurrences of character in string.

Parameters
strString to search in
chCharacter to count
Returns
Number of occurrences of ch in str
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ count() [2/2]

std::size_t nfx::string::count ( std::string_view str,
std::string_view substr )
inlinenodiscardnoexcept

Count occurrences of substring in string.

Parameters
strString to search in
substrSubstring to count
Returns
Number of non-overlapping occurrences of substr in str

Returns 0 if substr is empty or not found. Counts non-overlapping matches.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ countIf()

template<typename Predicate>
std::size_t nfx::string::countIf ( std::string_view str,
Predicate pred )
inlinenodiscardconstexprnoexcept

Count characters matching predicate.

Template Parameters
PredicateCallable type accepting char and returning bool
Parameters
strString to count from
predPredicate function to test characters
Returns
Number of characters matching predicate

Predicate should return true for characters to count.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ countOverlapping()

std::size_t nfx::string::countOverlapping ( std::string_view str,
std::string_view substr )
inlinenodiscardnoexcept

Count overlapping occurrences of substring in string.

Parameters
strString to search in
substrSubstring to count
Returns
Number of overlapping occurrences of substr in str

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)

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ cppEscape()

std::string nfx::string::cppEscape ( std::string_view str)
inlinenodiscard

Escape string for use as C/C++ string literal.

Parameters
strString to escape
Returns
C++-escaped string with special characters replaced by escape sequences

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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ cppUnescape()

std::string nfx::string::cppUnescape ( std::string_view str)
inlinenodiscardnoexcept

Unescape C/C++ string literal escape sequences.

Parameters
strC++ string literal with escape sequences
Returns
Unescaped string, or empty string if input contains invalid 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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ dedent()

std::string nfx::string::dedent ( std::string_view str)
inlinenodiscard

Remove common leading whitespace from all lines.

Parameters
strText to dedent
Returns
Text with common leading whitespace removed

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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ endsWith()

bool nfx::string::endsWith ( std::string_view str,
std::string_view suffix )
inlinenodiscardconstexprnoexcept

Fast check if string ends with suffix.

Parameters
strString to check
suffixSuffix to find
Returns
True if str ends with suffix
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ equals()

bool nfx::string::equals ( std::string_view lhs,
std::string_view rhs )
inlinenodiscardconstexprnoexcept

Fast case-sensitive string comparison.

Parameters
lhsFirst string
rhsSecond string
Returns
True if strings are exactly equal
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ extractBetween()

std::string_view nfx::string::extractBetween ( std::string_view str,
std::string_view start,
std::string_view end )
inlinenodiscardconstexprnoexcept

Extract substring between start and end delimiters.

Parameters
strString to search in
startStarting delimiter
endEnding delimiter
Returns
String view of portion between delimiters, or empty string if either delimiter not found

Zero-allocation. Searches for first occurrence of start, then first occurrence of end after that. Example: extractBetween("Hello [world] test", "[", "]") returns "world"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ findIf()

template<typename Predicate>
std::size_t nfx::string::findIf ( std::string_view str,
Predicate pred )
inlinenodiscardconstexprnoexcept

Find first character matching predicate.

Template Parameters
PredicateCallable type accepting char and returning bool
Parameters
strString to search
predPredicate function to test characters
Returns
Position of first matching character, or std::string_view::npos if not found

Predicate should return true for the character to find.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ findIfNot()

template<typename Predicate>
std::size_t nfx::string::findIfNot ( std::string_view str,
Predicate pred )
inlinenodiscardconstexprnoexcept

Find first character NOT matching predicate.

Template Parameters
PredicateCallable type accepting char and returning bool
Parameters
strString to search
predPredicate function to test characters
Returns
Position of first non-matching character, or std::string_view::npos if not found

Predicate should return true for characters to skip.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ hasExactLength()

bool nfx::string::hasExactLength ( std::string_view str,
std::size_t expectedLength )
inlinenodiscardconstexprnoexcept

Fast check if string has exact length.

Parameters
strString to check
expectedLengthExpected length
Returns
True if string has exact expected length
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ iequals()

bool nfx::string::iequals ( std::string_view lhs,
std::string_view rhs )
inlinenodiscardnoexcept

Fast case-insensitive string comparison.

Parameters
lhsFirst string
rhsSecond string
Returns
True if strings are equal (case-insensitive)
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ indent()

std::string nfx::string::indent ( std::string_view str,
size_t spaces )
inlinenodiscard

Add indentation to all lines.

Parameters
strText to indent
spacesNumber of spaces to indent each line
Returns
Indented text

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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ indexOf()

std::size_t nfx::string::indexOf ( std::string_view str,
std::string_view substr )
inlinenodiscardconstexprnoexcept

Find first occurrence of substring.

Parameters
strString to search in
substrSubstring to find
Returns
Index of first occurrence, or std::string_view::npos if not found

Returns 0 for empty substr. Case-sensitive search. Example: indexOf("hello world", "world") returns 6

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isAllDigits()

bool nfx::string::isAllDigits ( std::string_view str)
inlinenodiscardconstexprnoexcept

Check if string contains only ASCII digits.

Parameters
strString to check
Returns
True if string is non-empty and contains only digits (0-9)

Returns false for empty strings. Uses the existing isDigit() function for validation.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isAlpha()

bool nfx::string::isAlpha ( char c)
inlinenodiscardconstexprnoexcept

Check if character is ASCII alphabetic.

Parameters
cCharacter to check
Returns
True if character is a-z or A-Z
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isAlphaNumeric()

bool nfx::string::isAlphaNumeric ( char c)
inlinenodiscardconstexprnoexcept

Check if character is ASCII alphanumeric.

Parameters
cCharacter to check
Returns
True if character is a-z, A-Z, or 0-9
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isDate()

bool nfx::string::isDate ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate RFC 3339 full-date format.

Parameters
strString to validate
Returns
True if string is a valid date (e.g., "2025-11-29")

Validates YYYY-MM-DD format with proper month/day ranges.

See also
https://datatracker.ietf.org/doc/html/rfc3339
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isDateTime()

bool nfx::string::isDateTime ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate RFC 3339 date-time format.

Parameters
strString to validate
Returns
True if string is a valid date-time (e.g., "2025-11-29T14:30:00Z")

Validates YYYY-MM-DDTHH:MM:SS with optional fractional seconds and timezone. Timezone can be 'Z' or ±HH:MM offset. Does not allocate memory.

See also
https://datatracker.ietf.org/doc/html/rfc3339
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isDigit()

bool nfx::string::isDigit ( char c)
inlinenodiscardconstexprnoexcept

Check if character is ASCII digit.

Parameters
cCharacter to check
Returns
True if character is 0-9
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isDomainName()

bool nfx::string::isDomainName ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate domain name format (RFC 1035).

Parameters
strString to validate
Returns
True if string is a valid domain name

Validates fully qualified domain names (FQDN). Stricter than hostname validation. Must contain at least one dot. Examples: "example.com", "mail.google.com"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isDuration()

bool nfx::string::isDuration ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate ISO 8601 duration format.

Parameters
strString to validate
Returns
True if string is a valid duration (e.g., "P1Y2M3DT4H5M6S")

Validates P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W format.

See also
https://en.wikipedia.org/wiki/ISO_8601#Durations
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isEmail()

bool nfx::string::isEmail ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate email address format (RFC 5321).

Parameters
strString to validate
Returns
True if string is a valid email address

Validates basic email format: local-part followed by at-sign and domain. Not exhaustive per RFC 5321.

See also
https://datatracker.ietf.org/doc/html/rfc5321
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isEmpty()

bool nfx::string::isEmpty ( std::string_view str)
inlinenodiscardconstexprnoexcept

Fast check if string is empty.

Parameters
strString to check
Returns
True if string is empty
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isHexDigit()

bool nfx::string::isHexDigit ( char c)
inlinenodiscardconstexprnoexcept

Check if character is ASCII hexadecimal digit.

Parameters
cCharacter to check
Returns
True if character is 0-9, a-f, or A-F
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isHostname()

bool nfx::string::isHostname ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate hostname format (RFC 1123).

Parameters
strString to validate
Returns
True if string is a valid hostname

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"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isIdnEmail()

bool nfx::string::isIdnEmail ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate Internationalized email address format (EAI/SMTPUTF8).

Parameters
strString to validate
Returns
True if string is a valid internationalized email address

Validates email addresses containing Unicode characters in the local-part or domain.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isIdnHostname()

bool nfx::string::isIdnHostname ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate Internationalized Domain Name (IDN) hostname format.

Parameters
strString to validate
Returns
True if string is a valid IDN hostname

Validates hostnames containing Unicode characters (IDN).

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isIpv4Address()

bool nfx::string::isIpv4Address ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate IPv4 address format (RFC 791).

Parameters
strString to validate
Returns
True if string is a valid IPv4 address (e.g., "192.168.1.1")

Validates dotted-decimal notation with four octets (0-255 each).

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isIpv6Address()

bool nfx::string::isIpv6Address ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate IPv6 address format (RFC 4291, RFC 5952).

Parameters
strString to validate
Returns
True if string is a valid IPv6 address

Validates standard and compressed notation.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isIri()

bool nfx::string::isIri ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate IRI format (RFC 3987).

Parameters
strString to validate
Returns
True if string is a valid IRI (e.g., "https://example.com/路径")

Validates Internationalized Resource Identifier with Unicode characters.

See also
https://datatracker.ietf.org/doc/html/rfc3987
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isIriReference()

bool nfx::string::isIriReference ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate IRI-reference format (RFC 3987).

Parameters
strString to validate
Returns
True if string is a valid IRI or relative IRI-reference

Validates IRI or relative-reference with Unicode support (scheme optional).

See also
https://datatracker.ietf.org/doc/html/rfc3987
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isJsonPointer()

bool nfx::string::isJsonPointer ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate JSON Pointer format (RFC 6901).

Parameters
strString to validate
Returns
True if string is a valid JSON Pointer (e.g., "/foo/bar/0")

Validates empty string or sequence of /reference-token. Escape sequences ~0 and ~1 are validated.

See also
https://datatracker.ietf.org/doc/html/rfc6901
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isNullOrWhiteSpace()

bool nfx::string::isNullOrWhiteSpace ( std::string_view str)
inlinenodiscardconstexprnoexcept

Fast check if string is null, empty, or contains only whitespace.

Parameters
strString to check
Returns
True if string is empty or contains only whitespace characters

Considers space, tab, newline, carriage return, form feed, and vertical tab as whitespace

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isPortNumber()

bool nfx::string::isPortNumber ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate port number string (RFC 6335).

Parameters
strString to validate
Returns
True if string represents a valid port number (0-65535)

Validates string contains only digits and value is in valid port range. Examples: "80", "8080", "443", "65535"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isRelativeJsonPointer()

bool nfx::string::isRelativeJsonPointer ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate relative JSON Pointer format.

Parameters
strString to validate
Returns
True if string is a valid relative JSON Pointer (e.g., "1/foo")

Validates non-negative integer followed by either # or JSON Pointer.

See also
https://datatracker.ietf.org/doc/html/draft-handrews-relative-json-pointer
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isTime()

bool nfx::string::isTime ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate RFC 3339 full-time format.

Parameters
strString to validate
Returns
True if string is a valid time (e.g., "14:30:00Z")

Validates HH:MM:SS with optional fractional seconds and required timezone.

See also
https://datatracker.ietf.org/doc/html/rfc3339
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isUri()

bool nfx::string::isUri ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate URI format (RFC 3986).

Parameters
strString to validate
Returns
True if string is a valid URI (e.g., "https://example.com/path")

Validates scheme://authority/path?query::fragment format.

See also
https://datatracker.ietf.org/doc/html/rfc3986
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isUriReference()

bool nfx::string::isUriReference ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate URI-reference format (RFC 3986).

Parameters
strString to validate
Returns
True if string is a valid URI or relative-reference

Validates URI or relative-reference (scheme optional).

See also
https://datatracker.ietf.org/doc/html/rfc3986
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isUriReserved() [1/2]

bool nfx::string::isUriReserved ( char c)
inlinenodiscardconstexprnoexcept

Check if character is URI reserved (RFC 3986 Section 2.2).

Parameters
cCharacter to check
Returns
True if character is a reserved URI character (:/?#[]!$&'()*+,;=)
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isUriReserved() [2/2]

bool nfx::string::isUriReserved ( std::string_view str)
inlinenodiscardconstexprnoexcept

Check if string contains only URI reserved characters.

Parameters
strString to check
Returns
True if string is non-empty and contains only reserved characters

Returns false for empty strings. Uses RFC 3986 Section 2.2 definition.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isUriTemplate()

bool nfx::string::isUriTemplate ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate URI Template format (RFC 6570).

Parameters
strString to validate
Returns
True if string is a valid URI Template (e.g., "https://example.com/{user}/repos")

Validates URI templates with {expression} syntax. Expressions may contain operator prefixes (+, #, ., /, ;, ?, &) and variable names. No whitespace allowed. Braces must be balanced.

See also
https://datatracker.ietf.org/doc/html/rfc6570
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isUriUnreserved() [1/2]

bool nfx::string::isUriUnreserved ( char c)
inlinenodiscardconstexprnoexcept

Check if character is URI unreserved (RFC 3986 Section 2.3).

Parameters
cCharacter to check
Returns
True if character is A-Z, a-z, 0-9, -, ., _, or ~
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isUriUnreserved() [2/2]

bool nfx::string::isUriUnreserved ( std::string_view str)
inlinenodiscardconstexprnoexcept

Check if string contains only URI unreserved characters.

Parameters
strString to check
Returns
True if string is non-empty and contains only unreserved characters

Returns false for empty strings. Uses RFC 3986 Section 2.3 definition.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isUuid()

bool nfx::string::isUuid ( std::string_view str)
inlinenodiscardconstexprnoexcept

Validate UUID format (RFC 4122).

Parameters
strString to validate
Returns
True if string is a valid UUID (e.g., "550e8400-e29b-41d4-a716-446655440000")

Validates 8-4-4-4-12 hexadecimal digit format with hyphens.

See also
https://datatracker.ietf.org/doc/html/rfc4122
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isWhitespace()

bool nfx::string::isWhitespace ( char c)
inlinenodiscardconstexprnoexcept

Check if character is whitespace.

Parameters
cCharacter to check
Returns
True if character is space, tab, newline, carriage return, form feed, or vertical tab
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ join() [1/2]

template<typename Container>
std::string nfx::string::join ( const Container & elements,
std::string_view delimiter )
inlinenodiscard

Join container elements with delimiter.

Template Parameters
ContainerContainer type (must support begin()/end() and value_type convertible to string_view)
Parameters
elementsContainer of elements to join
delimiterDelimiter to insert between elements
Returns
Joined string with delimiter between elements

Returns empty string for empty container. Single element returns that element without delimiter.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ join() [2/2]

template<typename Iterator>
std::string nfx::string::join ( Iterator begin,
Iterator end,
std::string_view delimiter )
inlinenodiscard

Join iterator range with delimiter.

Template Parameters
IteratorForward iterator type (value_type must be convertible to string_view)
Parameters
beginIterator to first element
endIterator past last element
delimiterDelimiter to insert between elements
Returns
Joined string with delimiter between elements

Returns empty string for empty range. Single element returns that element without delimiter.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ jsonEscape()

std::string nfx::string::jsonEscape ( std::string_view str)
inlinenodiscard

Escape string for use in JSON (RFC 8259).

Parameters
strString to escape
Returns
JSON-escaped string with special characters properly escaped

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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ jsonUnescape()

std::string nfx::string::jsonUnescape ( std::string_view str)
inlinenodiscardnoexcept

Unescape JSON string literal (RFC 8259).

Parameters
strEscaped JSON string to unescape
Returns
Unescaped string, or empty string if input contains invalid escape sequences

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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ lastIndexOf()

std::size_t nfx::string::lastIndexOf ( std::string_view str,
std::string_view substr )
inlinenodiscardconstexprnoexcept

Find last occurrence of substring.

Parameters
strString to search in
substrSubstring to find
Returns
Index of last occurrence, or std::string_view::npos if not found

Returns 0 for empty substr. Case-sensitive search. Example: lastIndexOf("hello hello", "hello") returns 6

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ naturalCompare()

int nfx::string::naturalCompare ( std::string_view lhs,
std::string_view rhs )
inlinenodiscardconstexprnoexcept

Natural sorting comparison (handles embedded numbers).

Parameters
lhsFirst string to compare
rhsSecond string to compare
Returns
Negative if lhs < rhs, 0 if equal, positive if lhs > rhs

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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ padLeft()

std::string nfx::string::padLeft ( std::string_view str,
std::size_t width,
char fillChar = ' ' )
inlinenodiscard

Pad string on the left to reach specified width.

Parameters
strString to pad
widthTarget width (total length after padding)
fillCharCharacter to use for padding (default: space)
Returns
Padded string (right-aligned). Returns original if already wider than width.

Example: padLeft("42", 5, '0') returns "00042"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ padRight()

std::string nfx::string::padRight ( std::string_view str,
std::size_t width,
char fillChar = ' ' )
inlinenodiscard

Pad string on the right to reach specified width.

Parameters
strString to pad
widthTarget width (total length after padding)
fillCharCharacter to use for padding (default: space)
Returns
Padded string (left-aligned). Returns original if already wider than width.

Example: padRight("42", 5, '0') returns "42000"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ removeAll() [1/2]

std::string nfx::string::removeAll ( std::string_view str,
char ch )
inlinenodiscard

Remove all occurrences of a character from string.

Parameters
strString to process
chCharacter to remove
Returns
New string with all occurrences of character removed

Allocates a new std::string. Example: removeAll("hello", 'l') returns "heo"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ removeAll() [2/2]

std::string nfx::string::removeAll ( std::string_view str,
std::string_view substr )
inlinenodiscard

Remove all occurrences of a substring from string.

Parameters
strString to process
substrSubstring to remove
Returns
New string with all occurrences of substring removed

Allocates a new std::string. Does not handle overlapping matches. Example: removeAll("hello world", "l") returns "heo word"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ removeIf()

template<typename Predicate>
std::string nfx::string::removeIf ( std::string_view str,
Predicate pred )
inlinenodiscard

Remove all characters matching a predicate from string.

Template Parameters
PredicateCallable type accepting char and returning bool
Parameters
strString to process
predPredicate function or lambda to test each character
Returns
New string with all matching characters removed

Allocates a new std::string. Example: removeIf("hello123", isDigit) returns "hello"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ removePrefix()

std::string_view nfx::string::removePrefix ( std::string_view str,
std::string_view prefix )
inlinenodiscardconstexprnoexcept

Remove prefix from string if present.

Parameters
strString to process
prefixPrefix to remove
Returns
String view with prefix removed, or original string if prefix not present

Zero-allocation. Example: removePrefix("HelloWorld", "Hello") returns "World"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ removeSuffix()

std::string_view nfx::string::removeSuffix ( std::string_view str,
std::string_view suffix )
inlinenodiscardconstexprnoexcept

Remove suffix from string if present.

Parameters
strString to process
suffixSuffix to remove
Returns
String view with suffix removed, or original string if suffix not present

Zero-allocation. Example: removeSuffix("HelloWorld", "World") returns "Hello"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ removeWhitespace()

std::string nfx::string::removeWhitespace ( std::string_view str)
inlinenodiscard

Remove all whitespace characters from string.

Parameters
strString to process
Returns
New string with all whitespace removed

Allocates a new std::string. Removes spaces, tabs, newlines, etc. Example: removeWhitespace("hello world") returns "helloworld"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ repeat()

std::string nfx::string::repeat ( std::string_view str,
std::size_t count )
inlinenodiscard

Repeat string specified number of times.

Parameters
strString to repeat
countNumber of repetitions
Returns
String repeated count times. Returns empty string if count is 0.

Example: repeat("*", 5) returns "*****"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ replace()

std::string nfx::string::replace ( std::string_view str,
std::string_view oldStr,
std::string_view newStr )
inlinenodiscard

Replace first occurrence of substring with replacement.

Parameters
strString to search in
oldStrSubstring to replace
newStrReplacement string
Returns
New string with first occurrence replaced, or copy of original if oldStr not found

Returns original string if oldStr is empty

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ replaceAll()

std::string nfx::string::replaceAll ( std::string_view str,
std::string_view oldStr,
std::string_view newStr )
inlinenodiscard

Replace all occurrences of substring with replacement.

Parameters
strString to search in
oldStrSubstring to replace
newStrReplacement string
Returns
New string with all non-overlapping occurrences replaced

Returns original string if oldStr is empty or not found

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ replaceIf()

template<typename Predicate>
std::string nfx::string::replaceIf ( std::string_view str,
Predicate pred,
char replacement )
inlinenodiscard

Replace characters matching predicate with replacement character.

Template Parameters
PredicateCallable type accepting char and returning bool
Parameters
strString to process
predPredicate function to test characters
replacementCharacter to replace matching characters with
Returns
New string with matching characters replaced

Predicate should return true for characters to replace. This function allocates a new std::string.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ reverse()

std::string nfx::string::reverse ( std::string_view str)
inlinenodiscard

Reverse a string.

Parameters
strString to reverse
Returns
New string with characters in reverse order

Returns empty string for empty input. Efficient single-pass algorithm. Example: reverse("hello") returns "olleh"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ startsWith()

bool nfx::string::startsWith ( std::string_view str,
std::string_view prefix )
inlinenodiscardconstexprnoexcept

Fast check if string starts with prefix.

Parameters
strString to check
prefixPrefix to find
Returns
True if str starts with prefix
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ substringAfter()

std::string_view nfx::string::substringAfter ( std::string_view str,
std::string_view delimiter )
inlinenodiscardconstexprnoexcept

Extract substring after first occurrence of delimiter.

Parameters
strString to search in
delimiterDelimiter to search for
Returns
String view of portion after delimiter, or empty string if delimiter not found

Zero-allocation. Example: substringAfter("hello.world.txt", ".") returns "world.txt"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ substringAfterLast()

std::string_view nfx::string::substringAfterLast ( std::string_view str,
std::string_view delimiter )
inlinenodiscardconstexprnoexcept

Extract substring after last occurrence of delimiter.

Parameters
strString to search in
delimiterDelimiter to search for
Returns
String view of portion after last delimiter, or empty string if delimiter not found

Zero-allocation. Example: substringAfterLast("hello.world.txt", ".") returns "txt"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ substringBefore()

std::string_view nfx::string::substringBefore ( std::string_view str,
std::string_view delimiter )
inlinenodiscardconstexprnoexcept

Extract substring before first occurrence of delimiter.

Parameters
strString to search in
delimiterDelimiter to search for
Returns
String view of portion before delimiter, or entire string if delimiter not found

Zero-allocation. Example: substringBefore("hello.world.txt", ".") returns "hello"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ substringBeforeLast()

std::string_view nfx::string::substringBeforeLast ( std::string_view str,
std::string_view delimiter )
inlinenodiscardconstexprnoexcept

Extract substring before last occurrence of delimiter.

Parameters
strString to search in
delimiterDelimiter to search for
Returns
String view of portion before last delimiter, or entire string if delimiter not found

Zero-allocation. Example: substringBeforeLast("hello.world.txt", ".") returns "hello.world"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ toLower() [1/2]

char nfx::string::toLower ( char c)
inlinenodiscardconstexprnoexcept

Convert ASCII character to lowercase.

Parameters
cCharacter to convert
Returns
Lowercase character if ASCII letter, otherwise unchanged

Only works with ASCII characters (A-Z, a-z). Non-ASCII characters are returned unchanged.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ toLower() [2/2]

std::string nfx::string::toLower ( std::string_view str)
inlinenodiscard

Convert string to lowercase.

Parameters
strString to convert
Returns
New string with all ASCII characters converted to lowercase

Only ASCII characters (A-Z) are converted. Non-ASCII characters are preserved unchanged. This function allocates a new std::string.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ toUpper() [1/2]

char nfx::string::toUpper ( char c)
inlinenodiscardconstexprnoexcept

Convert ASCII character to uppercase.

Parameters
cCharacter to convert
Returns
Uppercase character if ASCII letter, otherwise unchanged

Only works with ASCII characters (A-Z, a-z). Non-ASCII characters are returned unchanged.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ toUpper() [2/2]

std::string nfx::string::toUpper ( std::string_view str)
inlinenodiscard

Convert string to uppercase.

Parameters
strString to convert
Returns
New string with all ASCII characters converted to uppercase

Only ASCII characters (a-z) are converted. Non-ASCII characters are preserved unchanged. This function allocates a new std::string.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ trim()

std::string_view nfx::string::trim ( std::string_view str)
inlinenodiscardconstexprnoexcept

Remove leading and trailing whitespace from string.

Parameters
strString to trim
Returns
String view with leading and trailing whitespace removed

Returns a view into the original string, no allocation performed

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ trimEnd()

std::string_view nfx::string::trimEnd ( std::string_view str)
inlinenodiscardconstexprnoexcept

Remove trailing whitespace from string.

Parameters
strString to trim
Returns
String view with trailing whitespace removed

Returns a view into the original string, no allocation performed

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ trimEndIf()

template<typename Predicate>
std::string_view nfx::string::trimEndIf ( std::string_view str,
Predicate pred )
inlinenodiscardconstexprnoexcept

Remove trailing characters matching predicate.

Template Parameters
PredicateCallable type accepting char and returning bool
Parameters
strString to trim
predPredicate function to test characters
Returns
String view with trailing matching characters removed

Returns a view into the original string, no allocation performed. Predicate should return true for characters to remove.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ trimIf()

template<typename Predicate>
std::string_view nfx::string::trimIf ( std::string_view str,
Predicate pred )
inlinenodiscardconstexprnoexcept

Remove leading and trailing characters matching predicate.

Template Parameters
PredicateCallable type accepting char and returning bool
Parameters
strString to trim
predPredicate function to test characters
Returns
String view with leading and trailing matching characters removed

Returns a view into the original string, no allocation performed. Predicate should return true for characters to remove.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ trimStart()

std::string_view nfx::string::trimStart ( std::string_view str)
inlinenodiscardconstexprnoexcept

Remove leading whitespace from string.

Parameters
strString to trim
Returns
String view with leading whitespace removed

Returns a view into the original string, no allocation performed

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ trimStartIf()

template<typename Predicate>
std::string_view nfx::string::trimStartIf ( std::string_view str,
Predicate pred )
inlinenodiscardconstexprnoexcept

Remove leading characters matching predicate.

Template Parameters
PredicateCallable type accepting char and returning bool
Parameters
strString to trim
predPredicate function to test characters
Returns
String view with leading matching characters removed

Returns a view into the original string, no allocation performed. Predicate should return true for characters to remove.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ truncate() [1/2]

std::string nfx::string::truncate ( std::string_view str,
size_t maxLength )
inlinenodiscard

Truncate string to maximum length.

Parameters
strString to truncate
maxLengthMaximum length of result
Returns
Truncated string, or original if shorter than maxLength

If string is longer than maxLength, it is truncated to exactly maxLength characters. This function allocates a new std::string.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ truncate() [2/2]

std::string nfx::string::truncate ( std::string_view str,
size_t maxLength,
std::string_view ellipsis )
inlinenodiscard

Truncate string to maximum length with ellipsis.

Parameters
strString to truncate
maxLengthMaximum length of result (including ellipsis)
ellipsisString to append when truncating (default: "...")
Returns
Truncated string with ellipsis, or original if shorter than maxLength

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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ tryParseEndpoint()

bool nfx::string::tryParseEndpoint ( std::string_view endpoint,
std::string_view & host,
uint16_t & port )
inlinenodiscardnoexcept

Parse network endpoint into host and port.

Parameters
endpointEndpoint string to parse
hostOutput parameter for host portion
portOutput parameter for port number
Returns
True if parsing succeeded, false otherwise

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"

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ urlDecode()

std::string nfx::string::urlDecode ( std::string_view str)
inlinenodiscardnoexcept

Decode percent-encoded URL string (RFC 3986).

Parameters
strPercent-encoded string to decode
Returns
Decoded string, or empty string if input contains invalid percent-encoding

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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ urlEncode()

std::string nfx::string::urlEncode ( std::string_view str)
inlinenodiscard

Encode string for use in URLs (percent-encoding per RFC 3986).

Parameters
strString to encode
Returns
URL-encoded string with special characters percent-encoded

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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ wordWrap()

std::string nfx::string::wordWrap ( std::string_view str,
size_t width )
inlinenodiscard

Wrap text to specified width.

Parameters
strText to wrap
widthMaximum width per line
Returns
Text wrapped to specified width with newlines inserted

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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ xmlEscape()

std::string nfx::string::xmlEscape ( std::string_view str)
inlinenodiscard

Escape string for use in XML/HTML content.

Parameters
strString to escape
Returns
XML-escaped string with special characters replaced by entities

Escapes the five predefined XML entities: & (ampersand) -> & < (less-than) -> < > (greater-than) -> > " (quote) -> " ' (apostrophe) -> ' This function allocates a new std::string.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ xmlUnescape()

std::string nfx::string::xmlUnescape ( std::string_view str)
inlinenodiscardnoexcept

Unescape XML/HTML entity references.

Parameters
strXML/HTML string with entity references
Returns
Unescaped string, or empty string if input contains invalid 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.

Note
This function is marked [[nodiscard]] - the return value should not be ignored