Kodi Development 22.0
for Binary and Script based Add-Ons
 
All Classes Functions Variables Typedefs Enumerations Enumerator Modules Pages
Loading...
Searching...
No Matches

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

◆ EqualsNoCase() [1/3]

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

#include <kodi/tools/StringUtils.h>
std::string refstr = "TeSt";
EXPECT_TRUE(kodi::tools::StringUtils::EqualsNoCase(refstr, "TeSt"));
EXPECT_TRUE(kodi::tools::StringUtils::EqualsNoCase(refstr, "tEsT"));
static bool EqualsNoCase(const std::string &str1, const std::string &str2)
Compare two strings with ignore of lower-/uppercase.
Definition StringUtils.h:1561

◆ EqualsNoCase() [2/3]

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

◆ CompareNoCase() [1/2]

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

◆ CompareNoCase() [2/2]

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

◆ StartsWith() [1/3]

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

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

◆ StartsWith() [2/3]

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

◆ StartsWithNoCase() [1/3]

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

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

◆ StartsWithNoCase() [2/3]

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

◆ EndsWith() [1/2]

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

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

◆ EndsWith() [2/2]

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

◆ EndsWithNoCase() [1/2]

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

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

◆ EndsWithNoCase() [2/2]

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

◆ AlphaNumericCompare()

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

#include <kodi/tools/StringUtils.h>
int64_t ref, var;
ref = 0;
EXPECT_LT(var, ref);
static int64_t AlphaNumericCompare(const wchar_t *left, const wchar_t *right)
Compare two strings by his calculated alpha numeric values.
Definition StringUtils.h:1936

◆ Utf8StringLength()

static size_t 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.

◆ IsSpace()

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

◆ IsNaturalNumber()

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

#include <kodi/tools/StringUtils.h>
static bool IsNaturalNumber(const std::string &str)
Check whether a string is a natural number.
Definition StringUtils.h:2100

◆ IsInteger()

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

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

◆ IsAasciiDigit()

static bool IsAasciiDigit ( char chr)
inlinestatic

Checks a character is ascii number.

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

◆ IsAsciiXDigit()

static bool IsAsciiXDigit ( char chr)
inlinestatic

Checks a character is ascii hexadecimal number.

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

◆ AsciiDigitValue()

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

◆ IsAsciiUppercaseLetter()

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

◆ IsAsciiLowercaseLetter()

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

◆ IsAsciiAlphaNum()

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

◆ ContainsKeyword()

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