libnick 2024.12.0
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)
 Converts a base64 encoded string into a list of bytes.
 
std::string encode (const std::vector< std::byte > &bytes)
 Converts a list of bytes into a base64 encoded string.
 
bool isValidUrl (const std::string &s)
 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)
 Concatenates the elements of a string list using the specified separator between each element.
 
std::string lower (std::string s)
 Gets a fully lowercase string from the provided string.
 
std::string newUuid ()
 Generates a new uuid value.
 
std::string newGuid ()
 Generates a new guid value.
 
std::string normalizeForFilename (const std::string &s, bool windowsOnly=false)
 Normalizes a string for use in a filename.
 
std::string replace (std::string s, const std::string &toReplace, const std::string &replace)
 Replaces a substring within a string with a new string.
 
std::string replace (std::string s, char toReplace, char replace)
 Replaces a character within a string with a new character.
 
template<StringImplicitlyConstructible T = std::string>
std::vector< T > split (std::string s, const std::string &delimiter)
 Splits a string based on a delimiter.
 
std::vector< std::string > splitArgs (std::string s)
 Splits a string based on argument delimiters.
 
std::string str (const std::wstring &s)
 Converts the wstring to a string.
 
unsigned int stoui (const std::string &s, size_t *idx=nullptr, int base=10)
 Converts a string to an unsigned int.
 
std::string trim (const std::string &s)
 Trims whitespace form the beginning and end of a string.
 
std::string trim (const std::string &s, char delimiter)
 Trims the delimiter character form the beginning and end of a string.
 
std::string upper (std::string s)
 Gets a fully uppercase string from the provided string.
 
std::wstring wstr (const std::string &s)
 Converts the string to a wstring.
 

Function Documentation

◆ decode()

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

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)

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)

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 )

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)

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 ( )

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 ( )

Generates a new uuid value.

Returns
The uuid value

◆ normalizeForFilename()

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

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

◆ replace() [1/2]

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

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 )

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()

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

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
Returns
The splits of the string

◆ splitArgs()

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

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 )

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)

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)

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 )

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)

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)

Converts the string to a wstring.

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