nfx-stringutils 1.2.0
Cross-platform C++ string utilities library with validation and manipulation functions
Loading...
Searching...
No Matches
Utils.h File Reference

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

#include <cstdint>
#include <string>
#include <string_view>
#include "nfx/detail/string/Utils.inl"
Include dependency graph for Utils.h:

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::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::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.
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.
bool nfx::string::tryParseBool (std::string_view str, bool &result) noexcept
 Fast boolean parsing with error handling.
bool nfx::string::tryParseInt (std::string_view str, int &result) noexcept
 Fast integer parsing with error handling.
bool nfx::string::tryParseUInt (std::string_view str, std::uint32_t &result) noexcept
 Fast unsigned integer parsing with error handling.
bool nfx::string::tryParseLong (std::string_view str, std::int64_t &result) noexcept
 Fast long integer parsing with error handling.
bool nfx::string::tryParseFloat (std::string_view str, float &result) noexcept
 Fast float parsing with error handling.
bool nfx::string::tryParseDouble (std::string_view str, double &result) noexcept
 Fast double parsing with error handling.
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.
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::isValidHostname (std::string_view str) noexcept
 Validate hostname format (RFC 1123).
constexpr bool nfx::string::isDomainName (std::string_view str) noexcept
 Validate domain name format (RFC 1035).
constexpr bool nfx::string::isValidPort (std::string_view str) noexcept
 Validate port number string (RFC 6335).
template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
constexpr bool nfx::string::isValidPort (T port) noexcept
 Validate port number value (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.

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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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). Does not allocate memory. Examples: "127.0.0.1", "192.168.0.1"

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. Supports :: compression. Examples: "2001:db8::1", "::1", "fe80::1%eth0"

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

◆ 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

◆ 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

◆ isValidHostname()

bool nfx::string::isValidHostname ( 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

◆ isValidPort() [1/2]

bool nfx::string::isValidPort ( 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

◆ isValidPort() [2/2]

template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
bool nfx::string::isValidPort ( T port)
inlinenodiscardconstexprnoexcept

Validate port number value (RFC 6335).

Template Parameters
TIntegral type (int, uint16_t, uint32_t, uint64_t, etc.)
Parameters
portPort number to validate
Returns
True if port is in valid range (0-65535)

Accepts any integral type and validates the value is within the valid port range. Prevents implicit narrowing conversions that could silently accept invalid values. Examples: isValidPort(80) = true, isValidPort(70000) = false, isValidPort(-1) = false

Deprecated
This function will be removed in v2.0.0. Use manual range check instead: (port >= 0 && port <= 65535)
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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ tryParseBool()

bool nfx::string::tryParseBool ( std::string_view str,
bool & result )
inlinenodiscardnoexcept

Fast boolean parsing with error handling.

Parameters
strString to parse (case-insensitive)
resultOutput boolean value
Returns
True if parsing succeeded, false otherwise

Supports: "true"/"false", "1"/"0", "yes"/"no", "on"/"off", "t"/"f", "y"/"n"

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

◆ tryParseDouble()

bool nfx::string::tryParseDouble ( std::string_view str,
double & result )
inlinenodiscardnoexcept

Fast double parsing with error handling.

Parameters
strString to parse
resultOutput double value
Returns
True if parsing succeeded, false otherwise

Supports decimal, scientific notation, and special values (nan, inf, infinity). Examples: "123.456", "1.23e-2", "nan", "inf", "-infinity"

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

◆ tryParseFloat()

bool nfx::string::tryParseFloat ( std::string_view str,
float & result )
inlinenodiscardnoexcept

Fast float parsing with error handling.

Parameters
strString to parse
resultOutput float value
Returns
True if parsing succeeded, false otherwise

Supports decimal, scientific notation, and special values (nan, inf, infinity). Examples: "123.456", "1.23e-2", "nan", "inf", "-infinity"

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

◆ tryParseInt()

bool nfx::string::tryParseInt ( std::string_view str,
int & result )
inlinenodiscardnoexcept

Fast integer parsing with error handling.

Parameters
strString to parse
resultOutput integer value
Returns
True if parsing succeeded, false otherwise
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ tryParseLong()

bool nfx::string::tryParseLong ( std::string_view str,
std::int64_t & result )
inlinenodiscardnoexcept

Fast long integer parsing with error handling.

Parameters
strString to parse
resultOutput long integer value
Returns
True if parsing succeeded, false otherwise
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ tryParseUInt()

bool nfx::string::tryParseUInt ( std::string_view str,
std::uint32_t & result )
inlinenodiscardnoexcept

Fast unsigned integer parsing with error handling.

Parameters
strString to parse
resultOutput unsigned integer value
Returns
True if parsing succeeded, false otherwise
Note
This function is marked [[nodiscard]] - the return value should not be ignored