MinitScript  0.9.31 PRE-BETA
Static Public Member Functions | List of all members
StringTools Class Referencefinal

String tools class. More...

#include <minitscript/utilities/StringTools.h>

Collaboration diagram for StringTools:
Collaboration graph

Static Public Member Functions

static const bool startsWith (const string &str, const string &prefix)
 Checks if string starts with prefix. More...
 
static const bool viewStartsWith (const string_view &str, const string_view &prefix)
 Checks if string starts with prefix. More...
 
static const bool endsWith (const string &str, const string &suffix)
 Checks if string ends with suffix. More...
 
static const bool viewEndsWith (const string_view &str, const string_view &suffix)
 Checks if string ends with suffix. More...
 
static const string replace (const string &str, const char what, const char by, int64_t beginIndex=0)
 Replace char with another char. More...
 
static const string replace (const string &str, const string &what, const string &by, int64_t beginIndex=0)
 Replace string with another string. More...
 
static int64_t indexOf (const string &str, char what, int64_t beginIndex=0)
 Finds first index of given character. More...
 
static int64_t indexOf (const string &str, const string &what, int64_t beginIndex=0)
 Finds first index of given string. More...
 
static int64_t firstIndexOf (const string &str, char what, int64_t beginIndex=0)
 Finds first index of given character. More...
 
static int64_t firstIndexOf (const string &str, const string &what, int64_t beginIndex=0)
 Finds first index of given string. More...
 
static int64_t lastIndexOf (const string &str, const char what, int64_t endIndex=string::npos)
 Finds last index of given character. More...
 
static int64_t lastIndexOf (const string &str, const string &what, int64_t endIndex=string::npos)
 Finds last index of given string. More...
 
static int64_t firstIndexOfChar (const string &str, char what, int64_t beginIndex=0)
 Finds first index of character provided within given string. More...
 
static int64_t firstIndexOfChars (const string &str, const string &what, int64_t beginIndex=0)
 Finds first index of characters provided within given string. More...
 
static int64_t lastIndexOfChar (const string &str, char what, int64_t endIndex=string::npos)
 Finds last index of character provided within given string. More...
 
static int64_t lastIndexOfChars (const string &str, const string &what, int64_t endIndex=string::npos)
 Finds last index of characters provided within given string. More...
 
static const string substring (const string &str, int64_t beginIndex)
 Returns substring of given string from begin index. More...
 
static const string_view viewSubstring (const string_view &str, int64_t beginIndex)
 Returns substring of given string from begin index. More...
 
static const string substring (const string &str, int64_t beginIndex, int64_t endIndex)
 Returns substring of given string from begin index to end index. More...
 
static const string_view viewSubstring (const string_view &str, int64_t beginIndex, int64_t endIndex)
 Returns substring of given string from begin index to end index. More...
 
static bool equalsIgnoreCase (const string &string1, const string &string2)
 Checks if strings equal ignoring case. More...
 
static const string trim (const string &str)
 Trim string. More...
 
static const string_view viewTrim (const string_view &str)
 Trim string. More...
 
static const string toLowerCase (const string &str)
 Transform string to lower case. More...
 
static const string toUpperCase (const string &str)
 Transform string to upper case. More...
 
static bool regexMatch (const string &str, const string &pattern, smatch *matches=nullptr)
 Check if pattern matches whole string. More...
 
static bool regexSearch (const string &str, const string &pattern, smatch *matches=nullptr)
 Do regex pattern search. More...
 
static const string regexReplace (const string &str, const string &pattern, const string &by)
 Replace regex pattern with given string. More...
 
static const vector< string > tokenize (const string &str, const string &delimiters, bool emptyTokens=false)
 Tokenize. More...
 
static const string padLeft (const string &str, const string &by, int64_t toSize)
 Pad a string left. More...
 
static const string padRight (const string &str, const string &by, int64_t toSize)
 Pad a string right. More...
 
static const string indent (const string &str, const string &with, int64_t count)
 Indent a string. More...
 
static const string generate (const string &what, int64_t count=1)
 Generate a string. More...
 
static int64_t getUTF8Length (const string &str)
 Get UTF8 string length. More...
 
static const string getUTF8CharAt (const string &str, int64_t index)
 Get UTF8 character at given index. More...
 
static int64_t getUTF8BinaryIndex (const string &str, int64_t charIdx)
 Get UTF8 binary buffer index. More...
 

Detailed Description

String tools class.

Author
Andreas Drewke

Definition at line 20 of file StringTools.h.

Member Function Documentation

◆ startsWith()

static const bool startsWith ( const string &  str,
const string &  prefix 
)
inlinestatic

Checks if string starts with prefix.

Parameters
strstring
prefixprefix string
Returns
if string starts with prefix

Definition at line 29 of file StringTools.h.

◆ viewStartsWith()

static const bool viewStartsWith ( const string_view &  str,
const string_view &  prefix 
)
inlinestatic

Checks if string starts with prefix.

Parameters
strstring
prefixprefix string
Returns
if string starts with prefix

Definition at line 39 of file StringTools.h.

◆ endsWith()

static const bool endsWith ( const string &  str,
const string &  suffix 
)
inlinestatic

Checks if string ends with suffix.

Parameters
strstring
suffixsuffix string
Returns
if string ends with suffix

Definition at line 49 of file StringTools.h.

◆ viewEndsWith()

static const bool viewEndsWith ( const string_view &  str,
const string_view &  suffix 
)
inlinestatic

Checks if string ends with suffix.

Parameters
strstring
suffixsuffix string
Returns
if string ends with suffix

Definition at line 61 of file StringTools.h.

◆ replace() [1/2]

const string replace ( const string &  str,
const char  what,
const char  by,
int64_t  beginIndex = 0 
)
static

Replace char with another char.

Parameters
strstring
whatwhat to replace
byto replace by
beginIndexindex to begin with
Returns
replace result

Definition at line 33 of file StringTools.cpp.

◆ replace() [2/2]

const string replace ( const string &  str,
const string &  what,
const string &  by,
int64_t  beginIndex = 0 
)
static

Replace string with another string.

Parameters
strstring
whatwhat to replace
byto replace by
beginIndexindex to begin with
Returns
replace result

Definition at line 39 of file StringTools.cpp.

◆ indexOf() [1/2]

static int64_t indexOf ( const string &  str,
char  what,
int64_t  beginIndex = 0 
)
inlinestatic

Finds first index of given character.

Parameters
strstring
whatwhat
beginIndexbegin index
Returns
index or string::npos if not found

Definition at line 94 of file StringTools.h.

◆ indexOf() [2/2]

static int64_t indexOf ( const string &  str,
const string &  what,
int64_t  beginIndex = 0 
)
inlinestatic

Finds first index of given string.

Parameters
strstring
whatwhat
beginIndexbegin index
Returns
index or string::npos if not found

Definition at line 105 of file StringTools.h.

◆ firstIndexOf() [1/2]

static int64_t firstIndexOf ( const string &  str,
char  what,
int64_t  beginIndex = 0 
)
inlinestatic

Finds first index of given character.

Parameters
strstring
whatwhat
beginIndexbegin index
Returns
index or string::npos if not found

Definition at line 116 of file StringTools.h.

◆ firstIndexOf() [2/2]

static int64_t firstIndexOf ( const string &  str,
const string &  what,
int64_t  beginIndex = 0 
)
inlinestatic

Finds first index of given string.

Parameters
strstring
whatwhat
beginIndexbegin index
Returns
index or string::npos if not found

Definition at line 127 of file StringTools.h.

◆ lastIndexOf() [1/2]

static int64_t lastIndexOf ( const string &  str,
const char  what,
int64_t  endIndex = string::npos 
)
inlinestatic

Finds last index of given character.

Parameters
strstring
whatwhat
endIndexend index or string::npos
Returns
index or string::npos if not found

Definition at line 138 of file StringTools.h.

◆ lastIndexOf() [2/2]

static int64_t lastIndexOf ( const string &  str,
const string &  what,
int64_t  endIndex = string::npos 
)
inlinestatic

Finds last index of given string.

Parameters
strstring
whatwhat
endIndexend index or string::npos
Returns
index or string::npos if not found

Definition at line 149 of file StringTools.h.

◆ firstIndexOfChar()

static int64_t firstIndexOfChar ( const string &  str,
char  what,
int64_t  beginIndex = 0 
)
inlinestatic

Finds first index of character provided within given string.

Parameters
strstring
whatwhat
beginIndexbegin index
Returns
index or string::npos if not found

Definition at line 160 of file StringTools.h.

◆ firstIndexOfChars()

static int64_t firstIndexOfChars ( const string &  str,
const string &  what,
int64_t  beginIndex = 0 
)
inlinestatic

Finds first index of characters provided within given string.

Parameters
strstring
whatwhat
beginIndexbegin index
Returns
index or string::npos if not found

Definition at line 171 of file StringTools.h.

◆ lastIndexOfChar()

static int64_t lastIndexOfChar ( const string &  str,
char  what,
int64_t  endIndex = string::npos 
)
inlinestatic

Finds last index of character provided within given string.

Parameters
strstring
whatwhat
endIndexend index or string::npos
Returns
index or string::npos if not found

Definition at line 182 of file StringTools.h.

◆ lastIndexOfChars()

static int64_t lastIndexOfChars ( const string &  str,
const string &  what,
int64_t  endIndex = string::npos 
)
inlinestatic

Finds last index of characters provided within given string.

Parameters
strstring
whatwhat
endIndexend index or string::npos
Returns
index or string::npos if not found

Definition at line 193 of file StringTools.h.

◆ substring() [1/2]

static const string substring ( const string &  str,
int64_t  beginIndex 
)
inlinestatic

Returns substring of given string from begin index.

Parameters
strstring
beginIndexbegin index
Returns
substring result

Definition at line 203 of file StringTools.h.

◆ viewSubstring() [1/2]

static const string_view viewSubstring ( const string_view &  str,
int64_t  beginIndex 
)
inlinestatic

Returns substring of given string from begin index.

Parameters
strstring
beginIndexbegin index
Returns
substring result

Definition at line 213 of file StringTools.h.

◆ substring() [2/2]

static const string substring ( const string &  str,
int64_t  beginIndex,
int64_t  endIndex 
)
inlinestatic

Returns substring of given string from begin index to end index.

Parameters
strstring
beginIndexbegin index
endIndexend index
Returns
substring result

Definition at line 224 of file StringTools.h.

◆ viewSubstring() [2/2]

static const string_view viewSubstring ( const string_view &  str,
int64_t  beginIndex,
int64_t  endIndex 
)
inlinestatic

Returns substring of given string from begin index to end index.

Parameters
strstring
beginIndexbegin index
endIndexend index
Returns
substring result

Definition at line 235 of file StringTools.h.

◆ equalsIgnoreCase()

bool equalsIgnoreCase ( const string &  string1,
const string &  string2 
)
static

Checks if strings equal ignoring case.

Parameters
string1string 1
string2string 2
Returns
equality

Definition at line 49 of file StringTools.cpp.

◆ trim()

const string trim ( const string &  str)
static

Trim string.

Parameters
strstring
Returns
trimmed string

Definition at line 57 of file StringTools.cpp.

◆ viewTrim()

const string_view viewTrim ( const string_view &  str)
static

Trim string.

Parameters
strstring
Returns
trimmed string

Definition at line 82 of file StringTools.cpp.

◆ toLowerCase()

const string toLowerCase ( const string &  str)
static

Transform string to lower case.

Parameters
strstring
Returns
lowercase string

Definition at line 94 of file StringTools.cpp.

◆ toUpperCase()

const string toUpperCase ( const string &  str)
static

Transform string to upper case.

Parameters
strstring
Returns
uppercase string

Definition at line 100 of file StringTools.cpp.

◆ regexMatch()

bool regexMatch ( const string &  str,
const string &  pattern,
smatch *  matches = nullptr 
)
static

Check if pattern matches whole string.

Parameters
strstring
patternpattern
matchesmatches
Returns
if pattern matches whole string

Definition at line 106 of file StringTools.cpp.

◆ regexSearch()

bool regexSearch ( const string &  str,
const string &  pattern,
smatch *  matches = nullptr 
)
static

Do regex pattern search.

Parameters
strstring
patternpattern
matchesmatches
Returns
if search was successful

Definition at line 114 of file StringTools.cpp.

◆ regexReplace()

const string regexReplace ( const string &  str,
const string &  pattern,
const string &  by 
)
static

Replace regex pattern with given string.

Parameters
strstring
patternpattern
byreplace string
Returns
replace result

Definition at line 122 of file StringTools.cpp.

◆ tokenize()

const vector< string > tokenize ( const string &  str,
const string &  delimiters,
bool  emptyTokens = false 
)
static

Tokenize.

Parameters
strstring
delimitersdelimiters
emptyTokensinclude empty tokens
Returns
tokens

Definition at line 126 of file StringTools.cpp.

◆ padLeft()

static const string padLeft ( const string &  str,
const string &  by,
int64_t  toSize 
)
inlinestatic

Pad a string left.

Parameters
strstring
byby
toSizeto size
Returns
padded string

Definition at line 318 of file StringTools.h.

◆ padRight()

static const string padRight ( const string &  str,
const string &  by,
int64_t  toSize 
)
inlinestatic

Pad a string right.

Parameters
strstring
byby
toSizeto size
Returns
padded string

Definition at line 331 of file StringTools.h.

◆ indent()

static const string indent ( const string &  str,
const string &  with,
int64_t  count 
)
inlinestatic

Indent a string.

Parameters
strstring
withwith
countcount
Returns
resulting string

Definition at line 344 of file StringTools.h.

◆ generate()

static const string generate ( const string &  what,
int64_t  count = 1 
)
inlinestatic

Generate a string.

Parameters
whatwhat
countcount
Returns
resulting string

Definition at line 356 of file StringTools.h.

◆ getUTF8Length()

int64_t getUTF8Length ( const string &  str)
static

Get UTF8 string length.

Parameters
strstring
Returns
UTF8 string length

Definition at line 132 of file StringTools.cpp.

◆ getUTF8CharAt()

const string getUTF8CharAt ( const string &  str,
int64_t  index 
)
static

Get UTF8 character at given index.

Parameters
strstring
indexindex
cacheUTF8 position cache

Definition at line 138 of file StringTools.cpp.

◆ getUTF8BinaryIndex()

int64_t getUTF8BinaryIndex ( const string &  str,
int64_t  charIdx 
)
static

Get UTF8 binary buffer index.

Parameters
strstring
charIdxcharacter index
Returns
UTF binary buffer position from given character/code point index

Definition at line 146 of file StringTools.cpp.


The documentation for this class was generated from the following files: