cppassist  1.0.0.f4fab4f962ff
C++ sanctuary for small but powerful and frequently required, stand alone features.
Functions
cppassist::string Namespace Reference

Functions

template<class Iterable >
std::string join (const Iterable &iterable, const std::string &separator)
 Join all values of a container in a single string. More...
 
CPPASSIST_API std::string trim (const std::string &string, bool removeAllWhitespace=false)
 Trim string by removing whitespace. More...
 
CPPASSIST_API std::string padLeft (const std::string &string, size_t length, char c=' ')
 Pad string with character (add to the left until the given size is reached) More...
 
CPPASSIST_API std::string padRight (const std::string &string, size_t length, char c=' ')
 Pad string with character (add to the right until the given size is reached) More...
 
CPPASSIST_API std::string stripped (const std::string &string, const std::set< char > &blacklist)
 Remove all occurences of provided characters from the string. More...
 
CPPASSIST_API std::vector< std::string > parseArray (const std::string &string, size_t size)
 Split string into substrings. More...
 
CPPASSIST_API std::vector< std::string > split (const std::string &string, char delimiter, bool keepEmptyParts=true)
 Split string into substrings. More...
 
CPPASSIST_API bool contains (const std::string &string, const std::string &containsstring)
 Check if a string contains a substring. More...
 
CPPASSIST_API bool hasPrefix (const std::string &string, const std::string &prefix)
 Check if a string starts with a given prefix. More...
 
CPPASSIST_API bool hasSuffix (const std::string &string, const std::string &suffix)
 Check if a string ends with a given suffix. More...
 
CPPASSIST_API bool matchesRegex (const std::string &string, const std::string &regex)
 Check if a regex matches a given string. More...
 
CPPASSIST_API std::vector< std::string > extract (const std::string &string, const std::string &regex)
 Extract substrings matched by a regex. More...
 
CPPASSIST_API std::string::const_iterator extractNext (std::string::const_iterator begin, std::string::const_iterator end, const std::string &regex, std::string &match)
 Extract next string matched by a regex. More...
 
CPPASSIST_API const char * extractNext (const char *begin, const char *end, const std::string &regex, std::string &match)
 Extract next string matched by a regex. More...
 
template<typename Type >
Type fromString (const std::string &string)
 Convert from std::string to Type. More...
 
template<>
CPPASSIST_API char fromString< char > (const std::string &string)
 
template<>
CPPASSIST_API unsigned char fromString< unsigned char > (const std::string &string)
 
template<>
CPPASSIST_API bool fromString< bool > (const std::string &string)
 
template<>
CPPASSIST_API int fromString< int > (const std::string &string)
 
template<typename Type >
std::string toString (const Type &value)
 Convert from Type to std::string. More...
 
template<>
CPPASSIST_API std::string toString< char > (const char &value)
 
template<>
CPPASSIST_API std::string toString< unsigned char > (const unsigned char &value)
 
template<>
CPPASSIST_API std::string toString< bool > (const bool &value)
 
CPPASSIST_API std::u32string encode (const std::string &input, Encoding encoding)
 Encode string to UTF-32. More...
 
CPPASSIST_API std::u32string encode (const std::wstring &input, Encoding encoding)
 
CPPASSIST_API std::u32string encode (const std::u16string &input, Encoding encoding)
 
CPPASSIST_API std::u32string encode (const char *input, const size_t size, Encoding encoding)
 
CPPASSIST_API void decode (const std::u32string &input, std::string &output, Encoding encoding)
 
CPPASSIST_API void decode (const std::u32string &input, std::wstring &output, Encoding encoding)
 
CPPASSIST_API void decode (const std::u32string &input, std::u16string &output, Encoding encoding)
 
CPPASSIST_API void decode (const std::u32string &input, char *&output, std::size_t &size, Encoding encoding)
 
CPPASSIST_API std::string toLower (const std::string &input)
 Create lowercase string from input. More...
 
CPPASSIST_API std::string toLower (std::string &&input)
 
CPPASSIST_API std::string toUpper (const std::string &input)
 Create uppercase string from input. More...
 
CPPASSIST_API std::string toUpper (std::string &&input)
 

Function Documentation

◆ fromString()

template<typename Type >
Type cppassist::string::fromString ( const std::string &  string)

Convert from std::string to Type.

Parameters
[in]stringString representation
Returns
Primitive type value

◆ fromString< char >()

template<>
CPPASSIST_API char cppassist::string::fromString< char > ( const std::string &  string)

◆ fromString< unsigned char >()

template<>
CPPASSIST_API unsigned char cppassist::string::fromString< unsigned char > ( const std::string &  string)

◆ fromString< bool >()

template<>
CPPASSIST_API bool cppassist::string::fromString< bool > ( const std::string &  string)

◆ fromString< int >()

template<>
CPPASSIST_API int cppassist::string::fromString< int > ( const std::string &  string)

◆ toString()

template<typename Type >
std::string cppassist::string::toString ( const Type &  value)

Convert from Type to std::string.

Parameters
[in]valuePrimitive type value
Returns
String representation

◆ toString< char >()

template<>
CPPASSIST_API std::string cppassist::string::toString< char > ( const char &  value)

◆ toString< unsigned char >()

template<>
CPPASSIST_API std::string cppassist::string::toString< unsigned char > ( const unsigned char &  value)

◆ toString< bool >()

template<>
CPPASSIST_API std::string cppassist::string::toString< bool > ( const bool &  value)

◆ encode() [1/4]

CPPASSIST_API std::u32string cppassist::string::encode ( const std::string &  input,
Encoding  encoding 
)

Encode string to UTF-32.

Parameters
[in]inputInput string
[in]encodingEncoding of the input string
Returns
UTF-32 encoded string

◆ encode() [2/4]

CPPASSIST_API std::u32string cppassist::string::encode ( const std::wstring &  input,
Encoding  encoding 
)

◆ encode() [3/4]

CPPASSIST_API std::u32string cppassist::string::encode ( const std::u16string &  input,
Encoding  encoding 
)

◆ encode() [4/4]

CPPASSIST_API std::u32string cppassist::string::encode ( const char *  input,
const size_t  size,
Encoding  encoding 
)

◆ decode() [1/4]

CPPASSIST_API void cppassist::string::decode ( const std::u32string &  input,
std::string &  output,
Encoding  encoding 
)

◆ decode() [2/4]

CPPASSIST_API void cppassist::string::decode ( const std::u32string &  input,
std::wstring &  output,
Encoding  encoding 
)

◆ decode() [3/4]

CPPASSIST_API void cppassist::string::decode ( const std::u32string &  input,
std::u16string &  output,
Encoding  encoding 
)

◆ decode() [4/4]

CPPASSIST_API void cppassist::string::decode ( const std::u32string &  input,
char *&  output,
std::size_t &  size,
Encoding  encoding 
)

◆ toLower() [1/2]

CPPASSIST_API std::string cppassist::string::toLower ( const std::string &  input)

Create lowercase string from input.

Parameters
[in]inputInput string
Returns
String in lower-case

◆ toLower() [2/2]

CPPASSIST_API std::string cppassist::string::toLower ( std::string &&  input)

◆ toUpper() [1/2]

CPPASSIST_API std::string cppassist::string::toUpper ( const std::string &  input)

Create uppercase string from input.

Parameters
[in]inputInput string
Returns
String in upper-case

◆ toUpper() [2/2]

CPPASSIST_API std::string cppassist::string::toUpper ( std::string &&  input)

◆ join()

template<class Iterable >
std::string cppassist::string::join ( const Iterable &  iterable,
const std::string &  separator 
)

Join all values of a container in a single string.

Parameters
[in]iterableContainer
[in]separatorString separator
Returns
Joined string

◆ trim()

CPPASSIST_API std::string cppassist::string::trim ( const std::string &  string,
bool  removeAllWhitespace = false 
)

Trim string by removing whitespace.

Parameters
[in]stringString
[in]removeAllWhitespacetrue: remove whitespace everywhere in the string, false: remove whitespace at the beginning and the end of the string
Returns
Trimmed string

◆ padLeft()

CPPASSIST_API std::string cppassist::string::padLeft ( const std::string &  string,
size_t  length,
char  c = ' ' 
)

Pad string with character (add to the left until the given size is reached)

Parameters
[in]stringString
[in]lengthDesired string length
[in]cCharacter that is used to pad the string
Returns
Padded string

◆ padRight()

CPPASSIST_API std::string cppassist::string::padRight ( const std::string &  string,
size_t  length,
char  c = ' ' 
)

Pad string with character (add to the right until the given size is reached)

Parameters
[in]stringString
[in]lengthDesired string length
[in]cCharacter that is used to pad the string
Returns
Padded string

◆ stripped()

CPPASSIST_API std::string cppassist::string::stripped ( const std::string &  string,
const std::set< char > &  blacklist 
)

Remove all occurences of provided characters from the string.

Parameters
[in]stringInput string that is to be processed.
[in]blacklistSet of single characters that are to be removed.
Returns
New string with the characters beeing removed.

◆ parseArray()

CPPASSIST_API std::vector<std::string> cppassist::string::parseArray ( const std::string &  string,
size_t  size 
)

Split string into substrings.

Parameters
[in]sizeNumber of elements
[in]stringInput string of the form "(<value>,<value>,<value>...)"
Returns
List of strings

◆ split()

CPPASSIST_API std::vector<std::string> cppassist::string::split ( const std::string &  string,
char  delimiter,
bool  keepEmptyParts = true 
)

Split string into substrings.

Parameters
[in]stringInput string
[in]delimiterCharacter that marks the next element
[in]keepEmptyPartsFlag to signal if empty parts are part of the result or skipped
Returns
List of strings

◆ contains()

CPPASSIST_API bool cppassist::string::contains ( const std::string &  string,
const std::string &  containsstring 
)

Check if a string contains a substring.

Parameters
[in]stringInput string
[in]containsstringString that is checked if contained in first param string
Returns
true if string contains containsstring, false otherwise

◆ hasPrefix()

CPPASSIST_API bool cppassist::string::hasPrefix ( const std::string &  string,
const std::string &  prefix 
)

Check if a string starts with a given prefix.

Parameters
[in]stringInput string
[in]prefixPrefix to be checked
Returns
true if string starts with prefix, false otherwise

◆ hasSuffix()

CPPASSIST_API bool cppassist::string::hasSuffix ( const std::string &  string,
const std::string &  suffix 
)

Check if a string ends with a given suffix.

Parameters
[in]stringInput string
[in]suffixSuffix to be checked
Returns
true if string ends with suffix, false otherwise

◆ matchesRegex()

CPPASSIST_API bool cppassist::string::matchesRegex ( const std::string &  string,
const std::string &  regex 
)

Check if a regex matches a given string.

Parameters
[in]stringInput string
[in]regexRegular expression
Returns
true if regex matches the string, else false

◆ extract()

CPPASSIST_API std::vector<std::string> cppassist::string::extract ( const std::string &  string,
const std::string &  regex 
)

Extract substrings matched by a regex.

Parameters
[in]stringInput string
[in]regexRegular expression
Returns
List of results that match the regex

◆ extractNext() [1/2]

CPPASSIST_API std::string::const_iterator cppassist::string::extractNext ( std::string::const_iterator  begin,
std::string::const_iterator  end,
const std::string &  regex,
std::string &  match 
)

Extract next string matched by a regex.

Parameters
[in]beginBegin iterator of string range
[in]endEnd iterator of string range
[in]regexRegular expression
[out]matchThe resulting match
Returns
The iterator to the character after the match or begin if regex does not match

◆ extractNext() [2/2]

CPPASSIST_API const char* cppassist::string::extractNext ( const char *  begin,
const char *  end,
const std::string &  regex,
std::string &  match 
)

Extract next string matched by a regex.

Parameters
[in]beginBegin pointer of string range
[in]endEnd pointer of string range
[in]regexRegular expression
[out]matchThe resulting match
Returns
The pointer to the character after the match or begin if regex does not match