|
nfx-stringutils 1.2.0
Cross-platform C++ string utilities library with validation and manipulation functions
|
High-performance string utilities for NFX C++ library. More...
#include <cstdint>#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::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. | |
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**"
|
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.
|
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)
|
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 |
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 |
|
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 |
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 |
Fast check if string is empty.
| str | String to check |
|
inlinenodiscardconstexprnoexcept |
Validate IPv4 address format (RFC 791).
| str | String to validate |
Validates dotted-decimal notation with four octets (0-255 each). Does not allocate memory. Examples: "127.0.0.1", "192.168.0.1"
|
inlinenodiscardconstexprnoexcept |
Validate IPv6 address format (RFC 4291, RFC 5952).
| str | String to validate |
Validates standard and compressed notation. Supports :: compression. Examples: "2001:db8::1", "::1", "fe80::1%eth0"
|
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 |
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 |
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 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 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 port number value (RFC 6335).
| T | Integral type (int, uint16_t, uint32_t, uint64_t, etc.) |
| port | Port number to validate |
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
|
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.
|
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
|
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 |
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 |
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 |
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 leading whitespace from string.
| str | String to trim |
Returns a view into the original string, no allocation performed
|
inlinenodiscardnoexcept |
Fast boolean parsing with error handling.
| str | String to parse (case-insensitive) |
| result | Output boolean value |
Supports: "true"/"false", "1"/"0", "yes"/"no", "on"/"off", "t"/"f", "y"/"n"
|
inlinenodiscardnoexcept |
Fast double parsing with error handling.
| str | String to parse |
| result | Output double value |
Supports decimal, scientific notation, and special values (nan, inf, infinity). Examples: "123.456", "1.23e-2", "nan", "inf", "-infinity"
|
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 |
Fast float parsing with error handling.
| str | String to parse |
| result | Output float value |
Supports decimal, scientific notation, and special values (nan, inf, infinity). Examples: "123.456", "1.23e-2", "nan", "inf", "-infinity"
|
inlinenodiscardnoexcept |
Fast integer parsing with error handling.
| str | String to parse |
| result | Output integer value |
|
inlinenodiscardnoexcept |
Fast long integer parsing with error handling.
| str | String to parse |
| result | Output long integer value |
|
inlinenodiscardnoexcept |
Fast unsigned integer parsing with error handling.
| str | String to parse |
| result | Output unsigned integer value |