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

Edits given texts
This is used to revise the respective strings and to get them in the desired format. More...

Functions

static void kodi::tools::StringUtils::ToUpper (std::string &str)
 Convert a string to uppercase.
 
static void kodi::tools::StringUtils::ToUpper (std::wstring &str)
 Convert a 16bit wide string to uppercase.
 
static void kodi::tools::StringUtils::ToLower (std::string &str)
 Convert a string to lowercase.
 
static void kodi::tools::StringUtils::ToLower (std::wstring &str)
 Convert a 16bit wide string to lowercase.
 
static int kodi::tools::StringUtils::ReturnDigits (const std::string &str)
 Combine all numerical digits and give it as integer value.
 
static std::string kodi::tools::StringUtils::Left (const std::string &str, size_t count)
 Returns a string from start with givent count.
 
static std::string kodi::tools::StringUtils::Mid (const std::string &str, size_t first, size_t count=std::string::npos)
 Get substring from mid of given string.
 
static std::string kodi::tools::StringUtils::Right (const std::string &str, size_t count)
 Returns a string from end with givent count.
 
static std::string & kodi::tools::StringUtils::Trim (std::string &str)
 Trim a string with remove of not wanted spaces at begin and end of string.
 
static std::string & kodi::tools::StringUtils::Trim (std::string &str, const char *const chars)
 Trim a string with remove of not wanted characters at begin and end of string.
 
static std::string & kodi::tools::StringUtils::TrimLeft (std::string &str)
 Trim a string with remove of not wanted spaces at begin of string.
 
static std::string & kodi::tools::StringUtils::TrimLeft (std::string &str, const char *const chars)
 Trim a string with remove of not wanted characters at begin of string.
 
static std::string & kodi::tools::StringUtils::TrimRight (std::string &str)
 Trim a string with remove of not wanted spaces at end of string.
 
static std::string & kodi::tools::StringUtils::TrimRight (std::string &str, const char *const chars)
 Trim a string with remove of not wanted characters at end of string.
 
static std::string & kodi::tools::StringUtils::RemoveDuplicatedSpacesAndTabs (std::string &str)
 Cleanup string by remove of duplicates of spaces and tabs.
 
static int kodi::tools::StringUtils::Replace (std::string &str, char oldChar, char newChar)
 Replace a character with another inside text string.
 
static int kodi::tools::StringUtils::Replace (std::string &str, const std::string &oldStr, const std::string &newStr)
 Replace a complete text with another inside text string.
 
static int kodi::tools::StringUtils::Replace (std::wstring &str, const std::wstring &oldStr, const std::wstring &newStr)
 Replace a complete text with another inside 16bit wide text string.
 
static std::string kodi::tools::StringUtils::MakeSafeUrl (const std::string &str)
 Transform characters to create a safe URL.
 
static std::string kodi::tools::StringUtils::MakeSafeString (const std::string &str)
 Transform characters to create a safe, printable string.
 
static std::string kodi::tools::StringUtils::RemoveMACAddress (const std::string &str)
 Removes a MAC address from a given string.
 
static void kodi::tools::StringUtils::RemoveCRLF (std::string &strLine)
 Remove carriage return and line feeds on string ends.
 
static void kodi::tools::StringUtils::WordToDigits (std::string &word)
 Convert a word to a digit numerical string.
 
static std::string kodi::tools::StringUtils::Paramify (const std::string &param)
 Escapes the given string to be able to be used as a parameter.
 

Detailed Description

Edits given texts
This is used to revise the respective strings and to get them in the desired format.

Function Documentation

◆ Left()

static std::string kodi::tools::StringUtils::Left ( const std::string & str,
size_t count )
inlinestatic

Returns a string from start with givent count.

Parameters
[in]strString to use
[in]countAmount of characters to go from left
Returns
The left part string in amount of given count or complete if it was higher.

Example:

std::string refstr, varstr;
std::string origstr = "test";
refstr = "";
varstr = kodi::tools::StringUtils::Left(origstr, 0);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
refstr = "te";
varstr = kodi::tools::StringUtils::Left(origstr, 2);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
refstr = "test";
varstr = kodi::tools::StringUtils::Left(origstr, 10);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
static std::string Left(const std::string &str, size_t count)
Returns a string from start with givent count.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:978

◆ MakeSafeString()

static std::string kodi::tools::StringUtils::MakeSafeString ( const std::string & str)
inlinestatic

Transform characters to create a safe, printable string.

Parameters
[in]strThe string to transform
Returns
The transformed string, with unsafe characters replaced by " "

Unsafe characters are defined as the non-printable ASCII characters (character code 0-31).

◆ MakeSafeUrl()

static std::string kodi::tools::StringUtils::MakeSafeUrl ( const std::string & str)
inlinestatic

Transform characters to create a safe URL.

Parameters
[in]strThe string to transform
Returns
The transformed string, with unsafe characters replaced by "_"

Safe URLs are composed of the unreserved characters defined in RFC 3986 section 2.3:

ALPHA / DIGIT / "-" / "." / "_" / "~"

Characters outside of this set will be replaced by "_".

◆ Mid()

static std::string kodi::tools::StringUtils::Mid ( const std::string & str,
size_t first,
size_t count = std::string::npos )
inlinestatic

Get substring from mid of given string.

Parameters
[in]strString to get substring from
[in]firstPosition from where to start
[in]count[opt] length of position to get after start, default is complete to end
Returns
The substring taken from middle of input string

Example:

std::string refstr, varstr;
std::string origstr = "test";
refstr = "";
varstr = kodi::tools::StringUtils::Mid(origstr, 0, 0);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
refstr = "te";
varstr = kodi::tools::StringUtils::Mid(origstr, 0, 2);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
refstr = "test";
varstr = kodi::tools::StringUtils::Mid(origstr, 0, 10);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
refstr = "st";
varstr = kodi::tools::StringUtils::Mid(origstr, 2);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
refstr = "st";
varstr = kodi::tools::StringUtils::Mid(origstr, 2, 2);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
refstr = "es";
varstr = kodi::tools::StringUtils::Mid(origstr, 1, 2);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
static std::string Mid(const std::string &str, size_t first, size_t count=std::string::npos)
Get substring from mid of given string.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1028

◆ Paramify()

static std::string kodi::tools::StringUtils::Paramify ( const std::string & param)
inlinestatic

Escapes the given string to be able to be used as a parameter.

Escapes backslashes and double-quotes with an additional backslash and adds double-quotes around the whole string.

Parameters
[in]paramString to escape/paramify
Returns
Escaped/Paramified string

Example:

const char *input = "some, very \\ odd \"string\"";
const char *ref = "\"some, very \\\\ odd \\\"string\\\"\"";
std::string result = kodi::tools::StringUtils::Paramify(input);
EXPECT_STREQ(ref, result.c_str());
static std::string Paramify(const std::string &param)
Escapes the given string to be able to be used as a parameter.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1518

◆ RemoveCRLF()

static void kodi::tools::StringUtils::RemoveCRLF ( std::string & strLine)
inlinestatic

Remove carriage return and line feeds on string ends.

Parameters
[in,out]strString where CR and LF becomes removed on end

Example:

std::string refstr, varstr;
refstr = "test\r\nstring\nblah blah";
varstr = "test\r\nstring\nblah blah\n";
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
static void RemoveCRLF(std::string &strLine)
Remove carriage return and line feeds on string ends.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1456

◆ RemoveDuplicatedSpacesAndTabs()

static std::string & kodi::tools::StringUtils::RemoveDuplicatedSpacesAndTabs ( std::string & str)
inlinestatic

Cleanup string by remove of duplicates of spaces and tabs.

Parameters
[in,out]strString to remove duplicates, becomes also changed and given further on return
Returns
The changed string

◆ RemoveMACAddress()

static std::string kodi::tools::StringUtils::RemoveMACAddress ( const std::string & str)
inlinestatic

Removes a MAC address from a given string.

Parameters
[in]strThe string containing a MAC address
Returns
The string without the MAC address (for chaining)

◆ Replace() [1/3]

static int kodi::tools::StringUtils::Replace ( std::string & str,
char oldChar,
char newChar )
inlinestatic

Replace a character with another inside text string.

Parameters
[in]strString to replace within
[in]oldCharCharacter to search for replacement
[in]newCharNew character to use for replacement
Returns
Amount of replaced characters

Example:

std::string refstr = "text text";
std::string varstr = "test test";
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
EXPECT_EQ(dateTime1.GetHour(), 12)
static int Replace(std::string &str, char oldChar, char newChar)
Replace a character with another inside text string.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1274

◆ Replace() [2/3]

static int kodi::tools::StringUtils::Replace ( std::string & str,
const std::string & oldStr,
const std::string & newStr )
inlinestatic

Replace a complete text with another inside text string.

Parameters
[in]strString to replace within
[in]oldStrString to search for replacement
[in]newStrNew string to use for replacement
Returns
Amount of replaced text fields

Example:

std::string refstr = "text text";
std::string varstr = "test test";
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
EXPECT_STREQ(refstr.c_str(), varstr.c_str());

◆ Replace() [3/3]

static int kodi::tools::StringUtils::Replace ( std::wstring & str,
const std::wstring & oldStr,
const std::wstring & newStr )
inlinestatic

Replace a complete text with another inside 16bit wide text string.

Parameters
[in]strString to replace within
[in]oldStrString to search for replacement
[in]newStrNew string to use for replacement
Returns
Amount of replaced text fields

◆ ReturnDigits()

static int kodi::tools::StringUtils::ReturnDigits ( const std::string & str)
inlinestatic

Combine all numerical digits and give it as integer value.

Parameters
[in,out]strString to check for digits
Returns
All numerical digits fit together as integer value

◆ Right()

static std::string kodi::tools::StringUtils::Right ( const std::string & str,
size_t count )
inlinestatic

Returns a string from end with givent count.

Parameters
[in]strString to use
[in]countAmount of characters to go from right
Returns
The right part string in amount of given count or complete if it was higher.

Example:

std::string refstr, varstr;
std::string origstr = "test";
refstr = "";
varstr = kodi::tools::StringUtils::Right(origstr, 0);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
refstr = "st";
varstr = kodi::tools::StringUtils::Right(origstr, 2);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
refstr = "test";
varstr = kodi::tools::StringUtils::Right(origstr, 10);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
static std::string Right(const std::string &str, size_t count)
Returns a string from end with givent count.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1074

◆ ToLower() [1/2]

static void kodi::tools::StringUtils::ToLower ( std::string & str)
inlinestatic

Convert a string to lowercase.

Parameters
[in,out]strString to convert

Example:

std::string refstr = "test";
std::string varstr = "TeSt";
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
static void ToLower(std::string &str)
Convert a string to lowercase.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:913

◆ ToLower() [2/2]

static void kodi::tools::StringUtils::ToLower ( std::wstring & str)
inlinestatic

Convert a 16bit wide string to lowercase.

Parameters
[in,out]strString to convert

◆ ToUpper() [1/2]

static void kodi::tools::StringUtils::ToUpper ( std::string & str)
inlinestatic

Convert a string to uppercase.

Parameters
[in,out]strString to convert

Example:

std::string refstr = "TEST";
std::string varstr = "TeSt";
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
static void ToUpper(std::string &str)
Convert a string to uppercase.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:878

◆ ToUpper() [2/2]

static void kodi::tools::StringUtils::ToUpper ( std::wstring & str)
inlinestatic

Convert a 16bit wide string to uppercase.

Parameters
[in,out]strString to convert

◆ Trim() [1/2]

static std::string & kodi::tools::StringUtils::Trim ( std::string & str)
inlinestatic

Trim a string with remove of not wanted spaces at begin and end of string.

Parameters
[in,out]strString to trim, becomes also changed and given on return
Returns
The changed string

Example:

std::string refstr = "test test";
std::string varstr = " test test ";
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
static std::string & Trim(std::string &str)
Trim a string with remove of not wanted spaces at begin and end of string.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1102

◆ Trim() [2/2]

static std::string & kodi::tools::StringUtils::Trim ( std::string & str,
const char *const chars )
inlinestatic

Trim a string with remove of not wanted characters at begin and end of string.

Parameters
[in,out]strString to trim, becomes also changed and given on return
[in]charsCharacters to use for trim
Returns
The changed string

◆ TrimLeft() [1/2]

static std::string & kodi::tools::StringUtils::TrimLeft ( std::string & str)
inlinestatic

Trim a string with remove of not wanted spaces at begin of string.

Parameters
[in,out]strString to trim, becomes also changed and given on return
Returns
The changed string

Example:

std::string refstr = "test test ";
std::string varstr = " test test ";
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
static std::string & TrimLeft(std::string &str)
Trim a string with remove of not wanted spaces at begin of string.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1145

◆ TrimLeft() [2/2]

static std::string & kodi::tools::StringUtils::TrimLeft ( std::string & str,
const char *const chars )
inlinestatic

Trim a string with remove of not wanted characters at begin of string.

Parameters
[in,out]strString to trim, becomes also changed and given on return
[in]charsCharacters to use for trim
Returns
The changed string

◆ TrimRight() [1/2]

static std::string & kodi::tools::StringUtils::TrimRight ( std::string & str)
inlinestatic

Trim a string with remove of not wanted spaces at end of string.

Parameters
[in,out]strString to trim, becomes also changed and given on return
Returns
The changed string

Example:

std::string refstr = " test test";
std::string varstr = " test test ";
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
static std::string & TrimRight(std::string &str)
Trim a string with remove of not wanted spaces at end of string.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1190

◆ TrimRight() [2/2]

static std::string & kodi::tools::StringUtils::TrimRight ( std::string & str,
const char *const chars )
inlinestatic

Trim a string with remove of not wanted characters at end of string.

Parameters
[in,out]strString to trim, becomes also changed and given on return
[in]charsCharacters to use for trim
Returns
The changed string

◆ WordToDigits()

static void kodi::tools::StringUtils::WordToDigits ( std::string & word)
inlinestatic

Convert a word to a digit numerical string.

Parameters
[in]strString to convert

Example:

std::string ref, var;
ref = "8378 787464";
var = "test string";
EXPECT_STREQ(ref.c_str(), var.c_str());
static void WordToDigits(std::string &word)
Convert a word to a digit numerical string.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1479