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

Check strings for the desired state
With this, texts can be checked to see that they correspond to a required format. More...

Functions

static bool kodi::tools::StringUtils::EqualsNoCase (const std::string &str1, const std::string &str2)
 Compare two strings with ignore of lower-/uppercase.
 
static bool kodi::tools::StringUtils::EqualsNoCase (const std::string &str1, const char *s2)
 Compare two strings with ignore of lower-/uppercase.
 
static bool kodi::tools::StringUtils::EqualsNoCase (const char *s1, const char *s2)
 Compare two strings with ignore of lower-/uppercase.
 
static int kodi::tools::StringUtils::CompareNoCase (const std::string &str1, const std::string &str2, size_t n=0)
 Compare two strings with ignore of lower-/uppercase with given size.
 
static int kodi::tools::StringUtils::CompareNoCase (const char *s1, const char *s2, size_t n=0)
 Compare two strings with ignore of lower-/uppercase with given size.
 
static bool kodi::tools::StringUtils::StartsWith (const std::string &str1, const std::string &str2)
 Checks a string for the begin of another string.
 
static bool kodi::tools::StringUtils::StartsWith (const std::string &str1, const char *s2)
 Checks a string for the begin of another string.
 
static bool kodi::tools::StringUtils::StartsWith (const char *s1, const char *s2)
 Checks a string for the begin of another string.
 
static bool kodi::tools::StringUtils::StartsWithNoCase (const std::string &str1, const std::string &str2)
 Checks a string for the begin of another string by ignore of upper-/lowercase.
 
static bool kodi::tools::StringUtils::StartsWithNoCase (const std::string &str1, const char *s2)
 Checks a string for the begin of another string by ignore of upper-/lowercase.
 
static bool kodi::tools::StringUtils::StartsWithNoCase (const char *s1, const char *s2)
 Checks a string for the begin of another string by ignore of upper-/lowercase.
 
static bool kodi::tools::StringUtils::EndsWith (const std::string &str1, const std::string &str2)
 Checks a string for the ending of another string.
 
static bool kodi::tools::StringUtils::EndsWith (const std::string &str1, const char *s2)
 Checks a string for the ending of another string.
 
static bool kodi::tools::StringUtils::EndsWithNoCase (const std::string &str1, const std::string &str2)
 Checks a string for the ending of another string by ignore of upper-/lowercase.
 
static bool kodi::tools::StringUtils::EndsWithNoCase (const std::string &str1, const char *s2)
 Checks a string for the ending of another string by ignore of upper-/lowercase.
 
static int64_t kodi::tools::StringUtils::AlphaNumericCompare (const wchar_t *left, const wchar_t *right)
 Compare two strings by his calculated alpha numeric values.
 
static size_t kodi::tools::StringUtils::Utf8StringLength (const char *s)
 UTF8 version of strlen.
 
static int kodi::tools::StringUtils::IsSpace (char c)
 Check given character is a space.
 
static int kodi::tools::StringUtils::IsUTF8Letter (const unsigned char *str)
 Checks given pointer in string is a UTF8 letter.
 
static bool kodi::tools::StringUtils::IsNaturalNumber (const std::string &str)
 Check whether a string is a natural number.
 
static bool kodi::tools::StringUtils::IsInteger (const std::string &str)
 Check whether a string is an integer.
 
static bool kodi::tools::StringUtils::IsAasciiDigit (char chr)
 Checks a character is ascii number.
 
static bool kodi::tools::StringUtils::IsAsciiXDigit (char chr)
 Checks a character is ascii hexadecimal number.
 
static int kodi::tools::StringUtils::AsciiDigitValue (char chr)
 Translate a character where defined as a numerical value (0-9) string to right integer.
 
static int kodi::tools::StringUtils::AsciiXDigitValue (char chr)
 Translate a character where defined as a hexadecimal value string to right integer.
 
static bool kodi::tools::StringUtils::IsAsciiUppercaseLetter (char chr)
 Checks a character is ascii alphabetic lowercase.
 
static bool kodi::tools::StringUtils::IsAsciiLowercaseLetter (char chr)
 Checks a character is ascii alphabetic lowercase.
 
static bool kodi::tools::StringUtils::IsAsciiAlphaNum (char chr)
 Checks a character is within ascii alphabetic and numerical fields.
 
static bool kodi::tools::StringUtils::ContainsKeyword (const std::string &str, const std::vector< std::string > &keywords)
 Check a string for another text.
 

Detailed Description

Check strings for the desired state
With this, texts can be checked to see that they correspond to a required format.

Function Documentation

◆ AlphaNumericCompare()

static int64_t kodi::tools::StringUtils::AlphaNumericCompare ( const wchar_t * left,
const wchar_t * right )
inlinestatic

Compare two strings by his calculated alpha numeric values.

Parameters
[in]leftLeft string to compare with right
[in]rightRight string to compare with left
Returns
Return about compare
  • 0 if left and right the same
  • -1 if right is longer
  • 1 if left is longer
  • < 0 if less equal
  • > 0 if more equal

Example:

int64_t ref, var;
ref = 0;
EXPECT_LT(var, ref);
typedef int64_t(ATTR_APIENTRYP PFN_KODI_ADDON_AUDIODECODER_SEEK_V1)(const KODI_ADDON_AUDIODECODER_HDL hdl
static int64_t AlphaNumericCompare(const wchar_t *left, const wchar_t *right)
Compare two strings by his calculated alpha numeric values.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1936

◆ AsciiDigitValue()

static int kodi::tools::StringUtils::AsciiDigitValue ( char chr)
inlinestatic

Translate a character where defined as a numerical value (0-9) string to right integer.

Parameters
[in]chrSingle character to translate
Returns

◆ AsciiXDigitValue()

static int kodi::tools::StringUtils::AsciiXDigitValue ( char chr)
inlinestatic

Translate a character where defined as a hexadecimal value string to right integer.

Parameters
[in]chrSingle character to translate
Returns
Corresponding integer value, e.g. character is "A" becomes returned as a integer with 10.

◆ CompareNoCase() [1/2]

static int kodi::tools::StringUtils::CompareNoCase ( const char * s1,
const char * s2,
size_t n = 0 )
inlinestatic

Compare two strings with ignore of lower-/uppercase with given size.

Equal to EqualsNoCase only that size can defined and on return the difference between compared character becomes given.

Parameters
[in]s1C string to compare
[in]s2C string to compare
[in]n[opt] Length to check, 0 as default to make complete
Returns
0 if equal, otherwise difference of failed character in string to other ("a" - "b" = -1)

◆ CompareNoCase() [2/2]

static int kodi::tools::StringUtils::CompareNoCase ( const std::string & str1,
const std::string & str2,
size_t n = 0 )
inlinestatic

Compare two strings with ignore of lower-/uppercase with given size.

Equal to EqualsNoCase only that size can defined and on return the difference between compared character becomes given.

Parameters
[in]str1C++ string to compare
[in]str2C++ string to compare
[in]n[opt] Length to check, 0 as default to make complete
Returns
0 if equal, otherwise difference of failed character in string to other ("a" - "b" = -1)

◆ ContainsKeyword()

static bool kodi::tools::StringUtils::ContainsKeyword ( const std::string & str,
const std::vector< std::string > & keywords )
inlinestatic

Check a string for another text.

Parameters
[in]strString to search for keywords
[in]keywordsList of keywords to search in text
Returns
true if string contains word in list

◆ EndsWith() [1/2]

static bool kodi::tools::StringUtils::EndsWith ( const std::string & str1,
const char * s2 )
inlinestatic

Checks a string for the ending of another string.

Parameters
[in]str1C++ string to be checked
[in]s2C string with which text defined in str1 is checked at the ending
Returns
True if string ended with asked text, false otherwise

◆ EndsWith() [2/2]

static bool kodi::tools::StringUtils::EndsWith ( const std::string & str1,
const std::string & str2 )
inlinestatic

Checks a string for the ending of another string.

Parameters
[in]str1C++ string to be checked
[in]str2C++ string with which text defined in str1 is checked at the ending
Returns
True if string ended with asked text, false otherwise

Example:

bool ret;
std::string refstr = "test";
fprintf(stderr, "Expect true for here and is '%s'\n", ret ? "true" : "false");
fprintf(stderr, "Expect false for here and is '%s'\n", ret ? "true" : "false");
static bool EndsWith(const std::string &str1, const std::string &str2)
Checks a string for the ending of another string.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1818

◆ EndsWithNoCase() [1/2]

static bool kodi::tools::StringUtils::EndsWithNoCase ( const std::string & str1,
const char * s2 )
inlinestatic

Checks a string for the ending of another string by ignore of upper-/lowercase.

Parameters
[in]str1C++ string to be checked
[in]s2C string with which text defined in str1 is checked at the ending
Returns
True if string ended with asked text, false otherwise

◆ EndsWithNoCase() [2/2]

static bool kodi::tools::StringUtils::EndsWithNoCase ( const std::string & str1,
const std::string & str2 )
inlinestatic

Checks a string for the ending of another string by ignore of upper-/lowercase.

Parameters
[in]str1C++ string to be checked
[in]str2C++ string with which text defined in str1 is checked at the ending
Returns
True if string ended with asked text, false otherwise

Example:

bool ret;
std::string refstr = "test";
fprintf(stderr, "Expect true for here and is '%s'\n", ret ? "true" : "false");
fprintf(stderr, "Expect false for here and is '%s'\n", ret ? "true" : "false");
static bool EndsWithNoCase(const std::string &str1, const std::string &str2)
Checks a string for the ending of another string by ignore of upper-/lowercase.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1868

◆ EqualsNoCase() [1/3]

static bool kodi::tools::StringUtils::EqualsNoCase ( const char * s1,
const char * s2 )
inlinestatic

Compare two strings with ignore of lower-/uppercase.

Parameters
[in]s1C string to compare
[in]s2C string to compare
Returns
True if the strings are equal, false otherwise

◆ EqualsNoCase() [2/3]

static bool kodi::tools::StringUtils::EqualsNoCase ( const std::string & str1,
const char * s2 )
inlinestatic

Compare two strings with ignore of lower-/uppercase.

Parameters
[in]str1C++ string to compare
[in]s2C string to compare
Returns
True if the strings are equal, false otherwise

◆ EqualsNoCase() [3/3]

static bool kodi::tools::StringUtils::EqualsNoCase ( const std::string & str1,
const std::string & str2 )
inlinestatic

Compare two strings with ignore of lower-/uppercase.

Parameters
[in]str1C++ string to compare
[in]str2C++ string to compare
Returns
True if the strings are equal, false otherwise

Example:

std::string refstr = "TeSt";
EXPECT_TRUE(dateTime1.SetFromDBTime("12:34"))
static bool EqualsNoCase(const std::string &str1, const std::string &str2)
Compare two strings with ignore of lower-/uppercase.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1561

◆ IsAasciiDigit()

static bool kodi::tools::StringUtils::IsAasciiDigit ( char chr)
inlinestatic

Checks a character is ascii number.

Parameters
[in]chrSingle character to test
Returns
true if yes, false otherwise

◆ IsAsciiAlphaNum()

static bool kodi::tools::StringUtils::IsAsciiAlphaNum ( char chr)
inlinestatic

Checks a character is within ascii alphabetic and numerical fields.

Parameters
[in]chrSingle character to test
Returns
true if alphabetic / numerical ascii value

◆ IsAsciiLowercaseLetter()

static bool kodi::tools::StringUtils::IsAsciiLowercaseLetter ( char chr)
inlinestatic

Checks a character is ascii alphabetic lowercase.

Parameters
[in]chrSingle character to test
Returns
True if ascii lowercase letter, false otherwise

◆ IsAsciiUppercaseLetter()

static bool kodi::tools::StringUtils::IsAsciiUppercaseLetter ( char chr)
inlinestatic

Checks a character is ascii alphabetic lowercase.

Parameters
[in]chrSingle character to test
Returns
True if ascii uppercase letter, false otherwise

◆ IsAsciiXDigit()

static bool kodi::tools::StringUtils::IsAsciiXDigit ( char chr)
inlinestatic

Checks a character is ascii hexadecimal number.

Parameters
[in]chrSingle character to test
Returns
true if yes, false otherwise

◆ IsInteger()

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

Check whether a string is an integer.

Matches [ \t]*[\-]*[0-9]+[ \t]*

Parameters
strThe string to check
Returns
true if the string is an integer, false otherwise.

Example:

EXPECT_FALSE(kodi::tools::StringUtils::IsInteger("120 h"));
static bool IsInteger(const std::string &str)
Check whether a string is an integer.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:2144

◆ IsNaturalNumber()

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

Check whether a string is a natural number.

Matches [ \t]*[0-9]+[ \t]*

Parameters
[in]strThe string to check
Returns
true if the string is a natural number, false otherwise.

Example:

static bool IsNaturalNumber(const std::string &str)
Check whether a string is a natural number.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:2100

◆ IsSpace()

static int kodi::tools::StringUtils::IsSpace ( char c)
inlinestatic

Check given character is a space.

Hack to check only first byte of UTF-8 character without this hack "TrimX" functions failed on Win32 and OS X with UTF-8 strings

Parameters
[in]cCharacter to check
Returns
true if space, false otherwise

◆ IsUTF8Letter()

static int kodi::tools::StringUtils::IsUTF8Letter ( const unsigned char * str)
inlinestatic

Checks given pointer in string is a UTF8 letter.

Parameters
[in]strGiven character values to check, must be minimum array of 2
Returns
return -1 if not, else return the utf8 char length.

◆ StartsWith() [1/3]

static bool kodi::tools::StringUtils::StartsWith ( const char * s1,
const char * s2 )
inlinestatic

Checks a string for the begin of another string.

Parameters
[in]s1C string to be checked
[in]s2C string with which text defined in str1 is checked at the beginning
Returns
True if string started with asked text, false otherwise

◆ StartsWith() [2/3]

static bool kodi::tools::StringUtils::StartsWith ( const std::string & str1,
const char * s2 )
inlinestatic

Checks a string for the begin of another string.

Parameters
[in]str1C++ string to be checked
[in]s2C string with which text defined in str1 is checked at the beginning
Returns
True if string started with asked text, false otherwise

◆ StartsWith() [3/3]

static bool kodi::tools::StringUtils::StartsWith ( const std::string & str1,
const std::string & str2 )
inlinestatic

Checks a string for the begin of another string.

Parameters
[in]str1C++ string to be checked
[in]str2C++ string with which text defined in str1 is checked at the beginning
Returns
True if string started with asked text, false otherwise

Example:

bool ret;
std::string refstr = "test";
fprintf(stderr, "Expect true for here and is '%s'\n", ret ? "true" : "false");
fprintf(stderr, "Expect false for here and is '%s'\n", ret ? "true" : "false");
static bool StartsWith(const std::string &str1, const std::string &str2)
Checks a string for the begin of another string.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1682

◆ StartsWithNoCase() [1/3]

static bool kodi::tools::StringUtils::StartsWithNoCase ( const char * s1,
const char * s2 )
inlinestatic

Checks a string for the begin of another string by ignore of upper-/lowercase.

Parameters
[in]s1C string to be checked
[in]s2C string with which text defined in str1 is checked at the beginning
Returns
True if string started with asked text, false otherwise

◆ StartsWithNoCase() [2/3]

static bool kodi::tools::StringUtils::StartsWithNoCase ( const std::string & str1,
const char * s2 )
inlinestatic

Checks a string for the begin of another string by ignore of upper-/lowercase.

Parameters
[in]str1C++ string to be checked
[in]s2C string with which text defined in str1 is checked at the beginning
Returns
True if string started with asked text, false otherwise

◆ StartsWithNoCase() [3/3]

static bool kodi::tools::StringUtils::StartsWithNoCase ( const std::string & str1,
const std::string & str2 )
inlinestatic

Checks a string for the begin of another string by ignore of upper-/lowercase.

Parameters
[in]str1C++ string to be checked
[in]str2C++ string with which text defined in str1 is checked at the beginning
Returns
True if string started with asked text, false otherwise

Example:

bool ret;
std::string refstr = "test";
fprintf(stderr, "Expect true for here and is '%s'\n", ret ? "true" : "false");
fprintf(stderr, "Expect true for here and is '%s'\n", ret ? "true" : "false");
fprintf(stderr, "Expect false for here and is '%s'\n", ret ? "true" : "false");
static bool StartsWithNoCase(const std::string &str1, const std::string &str2)
Checks a string for the begin of another string by ignore of upper-/lowercase.
Definition addons/kodi-dev-kit/include/kodi/tools/StringUtils.h:1751

◆ Utf8StringLength()

static size_t kodi::tools::StringUtils::Utf8StringLength ( const char * s)
inlinestatic

UTF8 version of strlen.

Skips any non-starting bytes in the count, thus returning the number of utf8 characters.

Parameters
[in]sc-string to find the length of.
Returns
The number of utf8 characters in the string.