Contains various utility functions for working with strings.
More...
|
| template<typename T> |
| std::string | nnl::utl::string::PrependZero (T num, std::size_t digits=2) |
| | Converts a number to a string padded with zero's.
|
| bool | nnl::utl::string::EndsWith (std::string_view str, std::string_view suffix) |
| | Checks if a string ends with a specific suffix.
|
| bool | nnl::utl::string::StartsWith (std::string_view str, std::string_view prefix) |
| | Checks if a string starts with a specific prefix.
|
| std::string | nnl::utl::string::Join (const std::vector< std::string > &strings, std::string delim=",") |
| | Joins a container of strings into one string using a delimiter.
|
| std::vector< std::string > | nnl::utl::string::Split (std::string_view str, std::string delim=",") |
| | Splits a string by delimiter.
|
| std::string | nnl::utl::string::Truncate (std::string_view str, std::size_t n) |
| | Truncates a string to specified length.
|
| std::string | nnl::utl::string::FloatToString (float value, int n=6) |
| | Converts a float value to a string with fixed precision.
|
| template<typename T> |
| std::string | nnl::utl::string::IntToHex (T i, bool prefix=false, bool prepend=true) |
| | Converts an integer to a hexadecimal string.
|
| std::string | nnl::utl::string::ToLower (std::string_view str) |
| | Converts a string to lowercase.
|
| bool | nnl::utl::string::CompareNat (std::string_view a, std::string_view b) |
| | Performs natural string comparison for sorting.
|
Contains various utility functions for working with strings.
◆ CompareNat()
| bool nnl::utl::string::CompareNat |
( |
std::string_view | a, |
|
|
std::string_view | b ) |
Performs natural string comparison for sorting.
While standard alphabetical order compares strings character-by-character (where "10" sorts before "2" because "1" is less than "2"), natural sort order compares them by magnitude of the number, placing "2" before "10".
- Parameters
-
| a | First string |
| b | Second string |
- Returns
- true if a < b using natural ordering
◆ EndsWith()
| bool nnl::utl::string::EndsWith |
( |
std::string_view | str, |
|
|
std::string_view | suffix ) |
Checks if a string ends with a specific suffix.
- Parameters
-
| str | The string to check |
| suffix | The suffix to look for |
- Returns
- true if str ends with suffix, false otherwise
◆ FloatToString()
| std::string nnl::utl::string::FloatToString |
( |
float | value, |
|
|
int | n = 6 ) |
Converts a float value to a string with fixed precision.
- Parameters
-
| value | Float value to convert |
| n | Number of decimal places |
- Returns
- String representation
◆ IntToHex()
template<typename T>
| std::string nnl::utl::string::IntToHex |
( |
T | i, |
|
|
bool | prefix = false, |
|
|
bool | prepend = true ) |
Converts an integer to a hexadecimal string.
- Template Parameters
-
- Parameters
-
| i | Integer to convert |
| prefix | Whether to add "0x" prefix |
| prepend | Whether to prepend the number with leading 0's |
- Returns
- Hexadecimal string representation
◆ Join()
| std::string nnl::utl::string::Join |
( |
const std::vector< std::string > & | strings, |
|
|
std::string | delim = "," ) |
Joins a container of strings into one string using a delimiter.
- Parameters
-
| strings | Container of strings to join |
| delim | Delimiter character |
- Returns
- Joined string
◆ PrependZero()
template<typename T>
| std::string nnl::utl::string::PrependZero |
( |
T | num, |
|
|
std::size_t | digits = 2 ) |
Converts a number to a string padded with zero's.
- Template Parameters
-
- Parameters
-
| num | The number to convert |
| digits | Total desired length including zero padding |
- Returns
- String with zero-padded number
◆ Split()
| std::vector< std::string > nnl::utl::string::Split |
( |
std::string_view | str, |
|
|
std::string | delim = "," ) |
Splits a string by delimiter.
- Parameters
-
| str | String to split |
| delim | Delimiter character |
- Returns
- Vector of substrings
◆ StartsWith()
| bool nnl::utl::string::StartsWith |
( |
std::string_view | str, |
|
|
std::string_view | prefix ) |
Checks if a string starts with a specific prefix.
- Parameters
-
| str | The string to check |
| prefix | The prefix to look for |
- Returns
- true if str starts with prefix, false otherwise
◆ ToLower()
| std::string nnl::utl::string::ToLower |
( |
std::string_view | str | ) |
|
Converts a string to lowercase.
- Parameters
-
- Returns
- Lowercase string
- Note
- This method processes only the ASCII subset of UTF-8 characters. Non-ASCII characters remain unchanged.
◆ Truncate()
| std::string nnl::utl::string::Truncate |
( |
std::string_view | str, |
|
|
std::size_t | n ) |
Truncates a string to specified length.
- Parameters
-
| str | String to truncate |
| n | Maximum length |
- Returns
- Truncated string