Kodi Development  20.0
for Binary and Script based Add-Ons

Detailed Description

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

Function Documentation

◆ ToUpper() [1/2]

static void ToUpper ( std::string &  str)
inlinestatic

Convert a string to uppercase.

Parameters
[in,out]strString to convert

Example:

#include <kodi/tools/StringUtils.h>
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: StringUtils.h:878

◆ ToUpper() [2/2]

static void ToUpper ( std::wstring &  str)
inlinestatic

Convert a 16bit wide string to uppercase.

Parameters
[in,out]strString to convert

◆ ToLower() [1/2]

static void ToLower ( std::string &  str)
inlinestatic

Convert a string to lowercase.

Parameters
[in,out]strString to convert

Example:

#include <kodi/tools/StringUtils.h>
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: StringUtils.h:913

◆ ToLower() [2/2]

static void ToLower ( std::wstring &  str)
inlinestatic

Convert a 16bit wide string to lowercase.

Parameters
[in,out]strString to convert

◆ ReturnDigits()

static int 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

◆ Left()

static std::string 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:

#include <kodi/tools/StringUtils.h>
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: StringUtils.h:978

◆ Mid()

static std::string 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:

#include <kodi/tools/StringUtils.h>
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: StringUtils.h:1028

◆ Right()

static std::string 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:

#include <kodi/tools/StringUtils.h>
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: StringUtils.h:1074

◆ Trim() [1/2]

static std::string& 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:

#include <kodi/tools/StringUtils.h>
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: StringUtils.h:1102

◆ Trim() [2/2]

static std::string& 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& 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:

#include <kodi/tools/StringUtils.h>
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: StringUtils.h:1145

◆ TrimLeft() [2/2]

static std::string& 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& 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:

#include <kodi/tools/StringUtils.h>
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: StringUtils.h:1190

◆ TrimRight() [2/2]

static std::string& 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

◆ RemoveDuplicatedSpacesAndTabs()

static std::string& 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

◆ Replace() [1/3]

static int 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:

#include <kodi/tools/StringUtils.h>
std::string refstr = "text text";
std::string varstr = "test test";
EXPECT_EQ(kodi::tools::StringUtils::Replace(varstr, 's', 'x'), 2);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
EXPECT_EQ(kodi::tools::StringUtils::Replace(varstr, 's', 'x'), 0);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
static int Replace(std::string &str, char oldChar, char newChar)
Replace a character with another inside text string.
Definition: StringUtils.h:1274

◆ Replace() [2/3]

static int 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:

#include <kodi/tools/StringUtils.h>
std::string refstr = "text text";
std::string varstr = "test test";
EXPECT_EQ(kodi::tools::StringUtils::Replace(varstr, "s", "x"), 2);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());
EXPECT_EQ(kodi::tools::StringUtils::Replace(varstr, "s", "x"), 0);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());

◆ Replace() [3/3]

static int 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

◆ MakeSafeUrl()

static std::string 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 "_".

◆ MakeSafeString()

static std::string 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).

◆ RemoveMACAddress()

static std::string 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)

◆ RemoveCRLF()

static void 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:

#include <kodi/tools/StringUtils.h>
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: StringUtils.h:1452

◆ WordToDigits()

static void 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: StringUtils.h:1472

◆ Paramify()

static std::string 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: StringUtils.h:1511