tgbotxx  1.1.6.9
Telegram Bot C++ Library
tgbotxx::StringUtils Namespace Reference

Namespace contains useful string related utility functions. More...

Functions

template<typename T , typename D >
static std::string join (const std::span< T > &con, const D &delim)
 Form a string from a container with a delimiter. More...
 
template<typename T , typename D >
static std::string join (const std::vector< T > &con, const D &delim)
 
static std::vector< std::string > split (const std::string &str, char delim)
 Split a string by delimiter. More...
 
static std::string toLowerCopy (std::string str)
 Lowercase a string. More...
 
static void toLower (std::string &str)
 Lowercase original string str. More...
 
static std::string toUpperCopy (std::string str)
 Uppercase a string. More...
 
static void toUpper (std::string &str)
 Uppercase original string str. More...
 
static void ltrim (std::string &str)
 Left trim a string from start (in place) More...
 
static void rtrim (std::string &str)
 Right trim a string from end (in place) More...
 
static void trim (std::string &str)
 Left and right trim a string (from beginning and end) (in place) More...
 
static std::string ltrimCopy (std::string s)
 Left trim a string from start (copy) More...
 
static std::string rtrimCopy (std::string s)
 Right trim a string from end (copy) More...
 
static std::string trimCopy (std::string s)
 Left and Right trim a string from start and end (copy) More...
 
static bool startsWith (const std::string &str, const std::string &prefix, bool ignoreCase=false)
 Returns true if str starts with prefix. More...
 
static bool endsWith (const std::string &str, const std::string &suffix, bool ignoreCase=false)
 Returns true if str ends with suffix. More...
 
static void replace (std::string &str, const std::string &search, const std::string &replace)
 
static std::string replaceCopy (std::string str, const std::string &search, const std::string &replace)
 
template<typename T >
static T to (const std::string &str)
 
static std::string random (std::size_t length)
 Returns a random string of length characters. More...
 

Detailed Description

Namespace contains useful string related utility functions.

Function Documentation

◆ endsWith()

static bool tgbotxx::StringUtils::endsWith ( const std::string &  str,
const std::string &  suffix,
bool  ignoreCase = false 
)
static

Returns true if str ends with suffix.

Parameters
strstring to check
suffixsuffix to check if str ends with it
ignoreCaseCase sensitivity, default: false
Returns
true if str ends with suffix

Definition at line 141 of file StringUtils.hpp.

◆ join() [1/2]

template<typename T , typename D >
static std::string tgbotxx::StringUtils::join ( const std::span< T > &  con,
const D &  delim 
)
static

Form a string from a container with a delimiter.

Parameters
conContainer of T elements
delimText to put between each element T Example: array = [1,2,3] StringUtils::join(array, ",") -> "1,2,3"

Definition at line 18 of file StringUtils.hpp.

◆ join() [2/2]

template<typename T , typename D >
static std::string tgbotxx::StringUtils::join ( const std::vector< T > &  con,
const D &  delim 
)
static

Definition at line 29 of file StringUtils.hpp.

◆ ltrim()

static void tgbotxx::StringUtils::ltrim ( std::string &  str)
static

Left trim a string from start (in place)

Parameters
strstring to trim from the left

Definition at line 76 of file StringUtils.hpp.

◆ ltrimCopy()

static std::string tgbotxx::StringUtils::ltrimCopy ( std::string  s)
static

Left trim a string from start (copy)

Parameters
strstring to trim from the left
Returns
Copy of left trimmed string

Definition at line 102 of file StringUtils.hpp.

◆ random()

static std::string tgbotxx::StringUtils::random ( std::size_t  length)
static

Returns a random string of length characters.

Definition at line 191 of file StringUtils.hpp.

◆ replace()

static void tgbotxx::StringUtils::replace ( std::string &  str,
const std::string &  search,
const std::string &  replace 
)
static

Replaces a token within a string with another string

Parameters
strString that contains tokens to replace
searchToken to replace
replaceNew value to replace token with

Definition at line 153 of file StringUtils.hpp.

◆ replaceCopy()

static std::string tgbotxx::StringUtils::replaceCopy ( std::string  str,
const std::string &  search,
const std::string &  replace 
)
static

Replaces a token within a string with another string and return a new copy

Parameters
strString that contains tokens to replace
searchToken to replace
replaceNew value to replace token with
Returns
new replaced tokens string

Definition at line 168 of file StringUtils.hpp.

◆ rtrim()

static void tgbotxx::StringUtils::rtrim ( std::string &  str)
static

Right trim a string from end (in place)

Parameters
strstring to trim from the right

Definition at line 84 of file StringUtils.hpp.

◆ rtrimCopy()

static std::string tgbotxx::StringUtils::rtrimCopy ( std::string  s)
static

Right trim a string from end (copy)

Parameters
strstring to trim from the right
Returns
Copy of right trimmed string

Definition at line 110 of file StringUtils.hpp.

◆ split()

static std::vector<std::string> tgbotxx::StringUtils::split ( const std::string &  str,
char  delim 
)
static

Split a string by delimiter.

Parameters
strString to split
delimSplit by delimiter
Returns
std::vector of chunks

Definition at line 37 of file StringUtils.hpp.

◆ startsWith()

static bool tgbotxx::StringUtils::startsWith ( const std::string &  str,
const std::string &  prefix,
bool  ignoreCase = false 
)
static

Returns true if str starts with prefix.

Parameters
strstring to check
prefixprefix to check if str starts with it
ignoreCaseCase sensitivity, default: false
Returns
true if str starts with prefix

Definition at line 128 of file StringUtils.hpp.

◆ to()

template<typename T >
static T tgbotxx::StringUtils::to ( const std::string &  str)
static

Convert a string to T type

Template Parameters
Tdesired type
Parameters
strstring to convert
Returns
converted string to T

Definition at line 183 of file StringUtils.hpp.

◆ toLower()

static void tgbotxx::StringUtils::toLower ( std::string &  str)
static

Lowercase original string str.

Parameters
strstring to lowercase

Definition at line 56 of file StringUtils.hpp.

◆ toLowerCopy()

static std::string tgbotxx::StringUtils::toLowerCopy ( std::string  str)
static

Lowercase a string.

Parameters
strstring to lowercase
Returns
Lowercase copy of str

Definition at line 49 of file StringUtils.hpp.

◆ toUpper()

static void tgbotxx::StringUtils::toUpper ( std::string &  str)
static

Uppercase original string str.

Parameters
strstring to uppercase

Definition at line 70 of file StringUtils.hpp.

◆ toUpperCopy()

static std::string tgbotxx::StringUtils::toUpperCopy ( std::string  str)
static

Uppercase a string.

Parameters
strstring to uppercase
Returns
Uppercase copy of str

Definition at line 63 of file StringUtils.hpp.

◆ trim()

static void tgbotxx::StringUtils::trim ( std::string &  str)
static

Left and right trim a string (from beginning and end) (in place)

Parameters
strstring to trim from the left and right

Definition at line 94 of file StringUtils.hpp.

◆ trimCopy()

static std::string tgbotxx::StringUtils::trimCopy ( std::string  s)
static

Left and Right trim a string from start and end (copy)

Parameters
strstring to trim from the left and right
Returns
Copy of trimmed string

Definition at line 118 of file StringUtils.hpp.