Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches

Creating lists using a string
With this, either simple vectors or lists defined by templates can be given for the respective divided text. More...

Functions

template<typename CONTAINER >
static std::string kodi::tools::StringUtils::Join (const CONTAINER &strings, const std::string &delimiter)
 Concatenates the elements of a specified array or the members of a collection and uses the specified separator between each element or member.
 
static std::vector< std::string > kodi::tools::StringUtils::Split (const std::string &input, const std::string &delimiter, unsigned int iMaxStrings=0)
 Splits the given input string using the given delimiter into separate strings.
 
static std::vector< std::string > kodi::tools::StringUtils::Split (const std::string &input, const char delimiter, int iMaxStrings=0)
 Splits the given input string using the given delimiter into separate strings.
 
static std::vector< std::string > kodi::tools::StringUtils::Split (const std::string &input, const std::vector< std::string > &delimiters)
 Splits the given input string using the given delimiter into separate strings.
 
template<typename OutputIt >
static OutputIt kodi::tools::StringUtils::SplitTo (OutputIt d_first, const std::string &input, const std::string &delimiter, unsigned int iMaxStrings=0)
 Splits the given input string using the given delimiter into separate strings.
 
template<typename OutputIt >
static OutputIt kodi::tools::StringUtils::SplitTo (OutputIt d_first, const std::string &input, const char delimiter, int iMaxStrings=0)
 Splits the given input string using the given delimiter into separate strings.
 
template<typename OutputIt >
static OutputIt kodi::tools::StringUtils::SplitTo (OutputIt d_first, const std::string &input, const std::vector< std::string > &delimiters)
 Splits the given input string using the given delimiter into separate strings.
 
static std::vector< std::string > kodi::tools::StringUtils::SplitMulti (const std::vector< std::string > &input, const std::vector< std::string > &delimiters, unsigned int iMaxStrings=0)
 Splits the given input strings using the given delimiters into further separate strings.
 
static std::vector< std::string > kodi::tools::StringUtils::Tokenize (const std::string &input, const std::string &delimiters)
 Split a string by the specified delimiters.
 
static void kodi::tools::StringUtils::Tokenize (const std::string &input, std::vector< std::string > &tokens, const std::string &delimiters)
 Tokenizing a string denotes splitting a string with respect to a delimiter.
 
static std::vector< std::string > kodi::tools::StringUtils::Tokenize (const std::string &input, const char delimiter)
 Tokenizing a string denotes splitting a string with respect to a delimiter.
 
static void kodi::tools::StringUtils::Tokenize (const std::string &input, std::vector< std::string > &tokens, const char delimiter)
 Tokenizing a string denotes splitting a string with respect to a delimiter.
 

Detailed Description

Creating lists using a string
With this, either simple vectors or lists defined by templates can be given for the respective divided text.

Function Documentation

◆ Join()

template<typename CONTAINER >
static std::string kodi::tools::StringUtils::Join ( const CONTAINER & strings,
const std::string & delimiter )
inlinestatic

Concatenates the elements of a specified array or the members of a collection and uses the specified separator between each element or member.

Parameters
[in]stringsAn array of objects whose string representations are concatenated.
[in]delimiterDelimiter to be used to join the input string
Returns
A string consisting of the elements of values, separated by the separator character.

Example:

std::string refstr, varstr;
std::vector<std::string> strarray;
strarray.emplace_back("a");
strarray.emplace_back("b");
strarray.emplace_back("c");
strarray.emplace_back("de");
strarray.emplace_back(",");
strarray.emplace_back("fg");
strarray.emplace_back(",");
refstr = "a,b,c,de,,,fg,,";
varstr = kodi::tools::StringUtils::Join(strarray, ",");
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
static std::string Join(const CONTAINER &strings, const std::string &delimiter)
Concatenates the elements of a specified array or the members of a collection and uses the specified ...
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:2485

◆ Split() [1/3]

static std::vector< std::string > kodi::tools::StringUtils::Split ( const std::string & input,
const char delimiter,
int iMaxStrings = 0 )
inlinestatic

Splits the given input string using the given delimiter into separate strings.

If the given input string is empty the result will be an empty array (not an array containing an empty string).

Parameters
[in]inputInput string to be split
[in]delimiterDelimiter to be used to split the input string
[in]iMaxStrings[opt] Maximum number of resulting split strings
Returns
List of splitted strings

◆ Split() [2/3]

static std::vector< std::string > kodi::tools::StringUtils::Split ( const std::string & input,
const std::string & delimiter,
unsigned int iMaxStrings = 0 )
inlinestatic

Splits the given input string using the given delimiter into separate strings.

If the given input string is empty the result will be an empty array (not an array containing an empty string).

Parameters
[in]inputInput string to be split
[in]delimiterDelimiter to be used to split the input string
[in]iMaxStrings[opt] Maximum number of resulting split strings
Returns
List of splitted strings

Example:

std::vector<std::string> varresults;
varresults = kodi::tools::StringUtils::Split("g,h,ij,k,lm,,n", ",");
EXPECT_STREQ("g", varresults.at(0).c_str());
EXPECT_STREQ("h", varresults.at(1).c_str());
EXPECT_STREQ("ij", varresults.at(2).c_str());
EXPECT_STREQ("k", varresults.at(3).c_str());
EXPECT_STREQ("lm", varresults.at(4).c_str());
EXPECT_STREQ("", varresults.at(5).c_str());
EXPECT_STREQ("n", varresults.at(6).c_str());
static std::vector< std::string > Split(const std::string &input, const std::string &delimiter, unsigned int iMaxStrings=0)
Splits the given input string using the given delimiter into separate strings.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:2527

◆ Split() [3/3]

static std::vector< std::string > kodi::tools::StringUtils::Split ( const std::string & input,
const std::vector< std::string > & delimiters )
inlinestatic

Splits the given input string using the given delimiter into separate strings.

If the given input string is empty the result will be an empty array (not an array containing an empty string).

Parameters
[in]inputInput string to be split
[in]delimitersDelimiter strings to be used to split the input strings
Returns
List of splitted strings

◆ SplitMulti()

static std::vector< std::string > kodi::tools::StringUtils::SplitMulti ( const std::vector< std::string > & input,
const std::vector< std::string > & delimiters,
unsigned int iMaxStrings = 0 )
inlinestatic

Splits the given input strings using the given delimiters into further separate strings.

If the given input string vector is empty the result will be an empty array (not an array containing an empty string).

Delimiter strings are applied in order, so once the (optional) maximum number of items is produced no other delimiters are applied. This produces different results to applying all delimiters at once e.g. "a/b#c/d" becomes "a", "b#c", "d" rather than "a", "b", "c/d"

Parameters
[in]inputInput vector of strings each to be split
[in]delimitersDelimiter strings to be used to split the input strings
[in]iMaxStrings[opt] Maximum number of resulting split strings
Returns
List of splitted strings

◆ SplitTo() [1/3]

template<typename OutputIt >
static OutputIt kodi::tools::StringUtils::SplitTo ( OutputIt d_first,
const std::string & input,
const char delimiter,
int iMaxStrings = 0 )
inlinestatic

Splits the given input string using the given delimiter into separate strings.

If the given input string is empty nothing will be put into the target iterator.

Parameters
[in]d_firstThe beginning of the destination range
[in]inputInput string to be split
[in]delimiterDelimiter to be used to split the input string
[in]iMaxStrings[opt] Maximum number of resulting split strings
Returns
Output iterator to the element in the destination range, one past the last element that was put there

◆ SplitTo() [2/3]

template<typename OutputIt >
static OutputIt kodi::tools::StringUtils::SplitTo ( OutputIt d_first,
const std::string & input,
const std::string & delimiter,
unsigned int iMaxStrings = 0 )
inlinestatic

Splits the given input string using the given delimiter into separate strings.

If the given input string is empty nothing will be put into the target iterator.

Parameters
[in]d_firstThe beginning of the destination range
[in]inputInput string to be split
[in]delimiterDelimiter to be used to split the input string
[in]iMaxStrings[opt] Maximum number of resulting split strings
Returns
Output iterator to the element in the destination range, one past the last element that was put there

◆ SplitTo() [3/3]

template<typename OutputIt >
static OutputIt kodi::tools::StringUtils::SplitTo ( OutputIt d_first,
const std::string & input,
const std::vector< std::string > & delimiters )
inlinestatic

Splits the given input string using the given delimiter into separate strings.

If the given input string is empty nothing will be put into the target iterator.

Parameters
[in]d_firstThe beginning of the destination range
[in]inputInput string to be split
[in]delimitersDelimiter strings to be used to split the input strings
Returns
Output iterator to the element in the destination range, one past the last element that was put there

◆ Tokenize() [1/4]

static std::vector< std::string > kodi::tools::StringUtils::Tokenize ( const std::string & input,
const char delimiter )
inlinestatic

Tokenizing a string denotes splitting a string with respect to a delimiter.

Parameters
[in]inputString to split
[in]delimiterDelimiters
Returns
A vector of tokens

◆ Tokenize() [2/4]

static std::vector< std::string > kodi::tools::StringUtils::Tokenize ( const std::string & input,
const std::string & delimiters )
inlinestatic

Split a string by the specified delimiters.

Splits a string using one or more delimiting characters, ignoring empty tokens.

Differs from Split() in two ways:

  1. The delimiters are treated as individual characters, rather than a single delimiting string.
  2. Empty tokens are ignored.
Parameters
[in]inputString to split
[in]delimitersDelimiters
Returns
A vector of tokens

◆ Tokenize() [3/4]

static void kodi::tools::StringUtils::Tokenize ( const std::string & input,
std::vector< std::string > & tokens,
const char delimiter )
inlinestatic

Tokenizing a string denotes splitting a string with respect to a delimiter.

Parameters
[in]inputString to split
[out]tokensList of
[in]delimiterDelimiters

◆ Tokenize() [4/4]

static void kodi::tools::StringUtils::Tokenize ( const std::string & input,
std::vector< std::string > & tokens,
const std::string & delimiters )
inlinestatic

Tokenizing a string denotes splitting a string with respect to a delimiter.

Parameters
[in]inputString to split
[out]tokensA vector of tokens
[in]delimitersDelimiters