NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches
String

Contains various utility functions for working with strings. More...

Functions

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.

Detailed Description

Contains various utility functions for working with strings.

Function Documentation

◆ 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
aFirst string
bSecond 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
strThe string to check
suffixThe 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
valueFloat value to convert
nNumber 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
TIntegral type
Parameters
iInteger to convert
prefixWhether to add "0x" prefix
prependWhether 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
stringsContainer of strings to join
delimDelimiter 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
TIntegral type
Parameters
numThe number to convert
digitsTotal 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
strString to split
delimDelimiter 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
strThe string to check
prefixThe 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
strString to convert
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
strString to truncate
nMaximum length
Returns
Truncated string