Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches

Detailed Description

To search a string
Various functions are defined in here which allow you to search through a text in different ways.

Function Documentation

◆ FindWords()

static size_t FindWords ( const char * str,
const char * wordLowerCase )
inlinestatic

Search for a single word within a text.

Parameters
[in]strString to search within
[in]wordLowerCaseWord as lowercase to search
Returns
Position in string where word is found, -1 (std::string::npos) if not found

Example:

#include <kodi/tools/StringUtils.h>
size_t ref, var;
// The name "string" is alone within text and becomes found on position 5
ref = 5;
var = kodi::tools::StringUtils::FindWords("test string", "string");
EXPECT_EQ(ref, var);
// The 12 is included inside another word and then not found as it should alone (-1 return)
ref = -1;
var = kodi::tools::StringUtils::FindWords("apple2012", "12");
EXPECT_EQ(ref, var);
static size_t FindWords(const char *str, const char *wordLowerCase)
Search for a single word within a text.
Definition StringUtils.h:2318

◆ FindEndBracket()

static size_t FindEndBracket ( const std::string & str,
char opener,
char closer,
size_t startPos = 0 )
inlinestatic

Search a string for a given bracket and give its end position.

Parameters
[in]strString to search within
[in]openerBegin character to start search
[in]closerEnd character to end search
[in]startPos[opt] Position to start search in string, 0 as default to start from begin
Returns
End position where found, -1 if failed

Example:

#include <kodi/tools/StringUtils.h>
int ref, var;
ref = 11;
var = kodi::tools::StringUtils::FindEndBracket("atest testbb test", 'a', 'b');
EXPECT_EQ(ref, var);
static size_t FindEndBracket(const std::string &str, char opener, char closer, size_t startPos=0)
Search a string for a given bracket and give its end position.
Definition StringUtils.h:2389

◆ FindNumber()

static int FindNumber ( const std::string & strInput,
const std::string & strFind )
inlinestatic

Search a text and return the number of parts found as a number.

Parameters
[in]strInputInput string to search for
[in]strFindString to search in input
Returns
Amount how much the string is found

Example:

#include <kodi/tools/StringUtils.h>
EXPECT_EQ(3, kodi::tools::StringUtils::FindNumber("aabcaadeaa", "aa"));
EXPECT_EQ(1, kodi::tools::StringUtils::FindNumber("aabcaadeaa", "b"));
static int FindNumber(const std::string &strInput, const std::string &strFind)
Search a text and return the number of parts found as a number.
Definition StringUtils.h:2428