libnick 2025.9.1
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
Nickvision::Helpers::StringHelpers Namespace Reference

Concepts

concept  StringImplicitlyConstructible
 

Functions

std::vector< std::byte > decode (const std::string &base64) noexcept
 Converts a base64 encoded string into a list of bytes.
 
std::string encode (const std::vector< std::byte > &bytes) noexcept
 Converts a list of bytes into a base64 encoded string.
 
bool isValidUrl (const std::string &s) noexcept
 Gets whether or not the provided string is a valid url.
 
std::string join (const std::vector< std::string > &values, const std::string &separator, bool separateLast=false) noexcept
 Concatenates the elements of a string list using the specified separator between each element.
 
std::string lower (std::string s) noexcept
 Gets a fully lowercase string from the provided string.
 
std::string newUuid () noexcept
 Generates a new uuid value.
 
std::string newGuid () noexcept
 Generates a new guid value.
 
std::string normalizeForFilename (const std::string &s, bool windowsOnly=false) noexcept
 Normalizes a string for use in a filename.
 
std::string quote (const std::string &s) noexcept
 Quotes a string for use in a command line.
 
std::string replace (std::string s, const std::string &toReplace, const std::string &replace) noexcept
 Replaces a substring within a string with a new string.
 
std::string replace (std::string s, char toReplace, char replace) noexcept
 Replaces a character within a string with a new character.
 
std::vector< std::string > splitArgs (std::string s) noexcept
 Splits a string based on argument delimiters.
 
std::string str (const std::wstring &s) noexcept
 Converts the wstring to a string.
 
unsigned int stoui (const std::string &s, size_t *idx=nullptr, int base=10) noexcept
 Converts a string to an unsigned int.
 
std::string trim (const std::string &s) noexcept
 Trims whitespace form the beginning and end of a string.
 
std::string trim (const std::string &s, char delimiter) noexcept
 Trims the delimiter character form the beginning and end of a string.
 
std::string upper (std::string s) noexcept
 Gets a fully uppercase string from the provided string.
 
std::wstring wstr (const std::string &s) noexcept
 Converts the string to a wstring.
 
template<StringImplicitlyConstructible T = std::string>
std::vector< T > split (const std::string &s, const std::string &delimiter, bool includeEmpty=true) noexcept
 Splits a string based on a delimiter.
 
template<StringImplicitlyConstructible T = std::string>
std::vector< T > split (const std::string &s, char delimiter, bool includeEmpty=true) noexcept
 Splits a string based on a delimiter.
 

Function Documentation

◆ decode()

std::vector< std::byte > Nickvision::Helpers::StringHelpers::decode ( const std::string & base64)
noexcept

Converts a base64 encoded string into a list of bytes.

Parameters
base64The base64 encoded string
Returns
The bytes list from the base64 encoded string, empty list if error

◆ encode()

std::string Nickvision::Helpers::StringHelpers::encode ( const std::vector< std::byte > & bytes)
noexcept

Converts a list of bytes into a base64 encoded string.

Parameters
bytesThe list of bytes
Returns
The base64 encoded string of the bytes list

◆ isValidUrl()

bool Nickvision::Helpers::StringHelpers::isValidUrl ( const std::string & s)
noexcept

Gets whether or not the provided string is a valid url.

Parameters
sThe string to check
Returns
True if the string is a valid url, else false

◆ join()

std::string Nickvision::Helpers::StringHelpers::join ( const std::vector< std::string > & values,
const std::string & separator,
bool separateLast = false )
noexcept

Concatenates the elements of a string list using the specified separator between each element.

Parameters
valuesThe list of strings to join
separatorThe string to use as a separator between each element
separateLastWhether or not to include the separator for the last joined element
Returns
A single string that consists of all elements of the string list separated by the delimiter

◆ lower()

std::string Nickvision::Helpers::StringHelpers::lower ( std::string s)
noexcept

Gets a fully lowercase string from the provided string.

Parameters
sThe string to get lowercase
Returns
The new lowercase string

◆ newGuid()

std::string Nickvision::Helpers::StringHelpers::newGuid ( )
noexcept

Generates a new guid value.

This function simple calls newUuid() and returns the result.

Returns
The guid value

◆ newUuid()

std::string Nickvision::Helpers::StringHelpers::newUuid ( )
noexcept

Generates a new uuid value.

Returns
The uuid value

◆ normalizeForFilename()

std::string Nickvision::Helpers::StringHelpers::normalizeForFilename ( const std::string & s,
bool windowsOnly = false )
noexcept

Normalizes a string for use in a filename.

Parameters
sThe string to normalize
windowsOnlyWhether or not to normalize strictly for Windows
Returns
The new normalized string

◆ quote()

std::string Nickvision::Helpers::StringHelpers::quote ( const std::string & s)
noexcept

Quotes a string for use in a command line.

Parameters
sThe string to quote
Returns
The quoted string

◆ replace() [1/2]

std::string Nickvision::Helpers::StringHelpers::replace ( std::string s,
char toReplace,
char replace )
noexcept

Replaces a character within a string with a new character.

Parameters
sThe string to work on
toReplaceThe character to be replaced
replaceThe new character to replace with
Returns
The new replaced string

◆ replace() [2/2]

std::string Nickvision::Helpers::StringHelpers::replace ( std::string s,
const std::string & toReplace,
const std::string & replace )
noexcept

Replaces a substring within a string with a new string.

Parameters
sThe string to work on
toReplaceThe substring to be replaced
replaceThe new string to replace with
Returns
The new replaced string

◆ split() [1/2]

template<StringImplicitlyConstructible T = std::string>
std::vector< T > Nickvision::Helpers::StringHelpers::split ( const std::string & s,
char delimiter,
bool includeEmpty = true )
noexcept

Splits a string based on a delimiter.

Template Parameters
TThe type of the resulting splits (must be a type that can be implicitly converted to string)
Parameters
sThe string to split
delimiterThe delimiter to split the string on
includeEmptyWhether or not to include empty tokens
Returns
The splits of the string

◆ split() [2/2]

template<StringImplicitlyConstructible T = std::string>
std::vector< T > Nickvision::Helpers::StringHelpers::split ( const std::string & s,
const std::string & delimiter,
bool includeEmpty = true )
noexcept

Splits a string based on a delimiter.

Template Parameters
TThe type of the resulting splits (must be a type that can be implicitly converted to string)
Parameters
sThe string to split
delimiterThe delimiter to split the string on
includeEmptyWhether or not to include empty tokens
Returns
The splits of the string

◆ splitArgs()

std::vector< std::string > Nickvision::Helpers::StringHelpers::splitArgs ( std::string s)
noexcept

Splits a string based on argument delimiters.

Parameters
sThe string to split
Returns
The splits of the argument string

◆ stoui()

unsigned int Nickvision::Helpers::StringHelpers::stoui ( const std::string & s,
size_t * idx = nullptr,
int base = 10 )
noexcept

Converts a string to an unsigned int.

Parameters
sThe string to convert
idxThe address of a size_t to store the number of characters processed
baseThe number base
Returns
The unsigned int version of the string
UINT_MAX if the converted string is too long
0 if error

◆ str()

std::string Nickvision::Helpers::StringHelpers::str ( const std::wstring & s)
noexcept

Converts the wstring to a string.

Parameters
sThe wstring to convert
Returns
The string version of the wstring

◆ trim() [1/2]

std::string Nickvision::Helpers::StringHelpers::trim ( const std::string & s)
noexcept

Trims whitespace form the beginning and end of a string.

Parameters
sThe string to trim (unmodified)
Returns
The new trimmed string

◆ trim() [2/2]

std::string Nickvision::Helpers::StringHelpers::trim ( const std::string & s,
char delimiter )
noexcept

Trims the delimiter character form the beginning and end of a string.

Parameters
sThe string to trim (unmodified)
delimiterThe character to trim
Returns
The new trimmed string

◆ upper()

std::string Nickvision::Helpers::StringHelpers::upper ( std::string s)
noexcept

Gets a fully uppercase string from the provided string.

Parameters
sThe string to get uppercase
Returns
The new uppercase string

◆ wstr()

std::wstring Nickvision::Helpers::StringHelpers::wstr ( const std::string & s)
noexcept

Converts the string to a wstring.

Parameters
sThe string to convert
Returns
The wstring version of the string