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

UTF8 String tools class. More...

#include <minitscript/utilities/UTF8StringTools.h>

Collaboration diagram for UTF8StringTools:
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 string &what, const string &by, int64_t beginIndex=0, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Replace string with another string. More...
 
static int64_t indexOf (const string &str, const string &what, int64_t beginIndex=0, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Finds first index of given string. More...
 
static int64_t firstIndexOf (const string &str, const string &what, int64_t beginIndex=0, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Finds first index of given string. More...
 
static int64_t lastIndexOf (const string &str, const string &what, int64_t endIndex=string::npos, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Finds last index of given string. More...
 
static int64_t firstIndexOfChars (const string &str, const string &what, int64_t beginIndex=0, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *srcCache=nullptr, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *whatCache=nullptr)
 Finds first index of characters provided within given string. More...
 
static int64_t lastIndexOfChars (const string &str, const string &what, int64_t endIndex=string::npos, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *srcCache=nullptr, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *whatCache=nullptr)
 Finds last index of characters provided within given string. More...
 
static const string substring (const string &str, int64_t beginIndex, int64_t endIndex=string::npos, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *srcCache=nullptr, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 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, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Returns substring of given string from begin index to end index. More...
 
static bool equalsIgnoreCase (const string &string1, const string &string2, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *string1Cache=nullptr, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *string2Cache=nullptr)
 Checks if strings equal ignoring case. More...
 
static const string trim (const string &str, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Trim string. More...
 
static const string_view viewTrim (const string_view &str, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Trim string. More...
 
static const string toLowerCase (const string &str, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Transform string to lower case. More...
 
static const string toUpperCase (const string &str, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 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 toLength, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Pad a string left. More...
 
static const string padRight (const string &str, const string &by, int64_t toLength, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 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 getLength (const string &str, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Get UTF8 string length. More...
 
static const string getCharAt (const string &str, int64_t index, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Get UTF8 character at given index. More...
 
static uint32_t getCodePointAt (const string &str, int64_t index, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Get UTF8 code point at given index. More...
 
static int64_t getUTF8BinaryIndex (const string &str, int64_t charIdx, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
 Get UTF8 binary buffer index. More...
 

Detailed Description

UTF8 String tools class.

Author
Andreas Drewke

Definition at line 21 of file UTF8StringTools.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 30 of file UTF8StringTools.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 40 of file UTF8StringTools.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 50 of file UTF8StringTools.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 62 of file UTF8StringTools.h.

◆ replace()

const string replace ( const string &  str,
const string &  what,
const string &  by,
int64_t  beginIndex = 0,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Replace string with another string.

Parameters
strstring
whatwhat to replace
byto replace by
beginIndexindex to begin with
cachestr UTF8 position cache
Returns
replace result

Definition at line 26 of file UTF8StringTools.cpp.

◆ indexOf()

static int64_t indexOf ( const string &  str,
const string &  what,
int64_t  beginIndex = 0,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
inlinestatic

Finds first index of given string.

Parameters
strstring
whatwhat
beginIndexbegin index
cachestr UTF8 position cache
Returns
index or string::npos if not found

Definition at line 93 of file UTF8StringTools.h.

◆ firstIndexOf()

int64_t firstIndexOf ( const string &  str,
const string &  what,
int64_t  beginIndex = 0,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Finds first index of given string.

Parameters
strstring
whatwhat
beginIndexbegin index
cachestr UTF8 position cache
Returns
index or string::npos if not found

Definition at line 44 of file UTF8StringTools.cpp.

◆ lastIndexOf()

int64_t lastIndexOf ( const string &  str,
const string &  what,
int64_t  endIndex = string::npos,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Finds last index of given string.

Parameters
strstring
whatwhat
endIndexend index or string::npos
cachestr UTF8 position cache
Returns
index or string::npos if not found

Definition at line 63 of file UTF8StringTools.cpp.

◆ firstIndexOfChars()

int64_t firstIndexOfChars ( const string &  str,
const string &  what,
int64_t  beginIndex = 0,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache srcCache = nullptr,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache whatCache = nullptr 
)
static

Finds first index of characters provided within given string.

Parameters
strstring
whatwhat
beginIndexbegin index
srcCachestr UTF8 position cache
whatCachewhat UTF8 position cache
Returns
index or string::npos if not found

Definition at line 93 of file UTF8StringTools.cpp.

◆ lastIndexOfChars()

int64_t lastIndexOfChars ( const string &  str,
const string &  what,
int64_t  endIndex = string::npos,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache srcCache = nullptr,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache whatCache = nullptr 
)
static

Finds last index of characters provided within given string.

Parameters
strstring
whatwhat
endIndexend index or string::npos
srcCachestr UTF8 position cache
whatCachewhat UTF8 position cache
Returns
index or string::npos if not found

Definition at line 111 of file UTF8StringTools.cpp.

◆ substring()

static const string substring ( const string &  str,
int64_t  beginIndex,
int64_t  endIndex = string::npos,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache srcCache = nullptr,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
inlinestatic

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

Parameters
strstring
beginIndexbegin index
endIndexend index or string::npos
cachestr UTF8 position cache
Returns
substring result

Definition at line 162 of file UTF8StringTools.h.

◆ viewSubstring()

const string_view viewSubstring ( const string_view &  str,
int64_t  beginIndex,
int64_t  endIndex,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

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

Parameters
strstring
beginIndexbegin index
endIndexend index or string::npos
cachestr UTF8 position cache
Returns
substring result

Definition at line 140 of file UTF8StringTools.cpp.

◆ equalsIgnoreCase()

bool equalsIgnoreCase ( const string &  string1,
const string &  string2,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache string1Cache = nullptr,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache string2Cache = nullptr 
)
static

Checks if strings equal ignoring case.

Parameters
string1string 1
string2string 2
string1Cachestring1 UTF8 position cache
string2Cachestring2 UTF8 position cache
Returns
equality

Definition at line 156 of file UTF8StringTools.cpp.

◆ trim()

const string trim ( const string &  str,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Trim string.

Parameters
strstring
cacheUTF8 position cache
Returns
trimmed string

Definition at line 180 of file UTF8StringTools.cpp.

◆ viewTrim()

const string_view viewTrim ( const string_view &  str,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Trim string.

Parameters
strstring
cacheUTF8 position cache
Returns
trimmed string

Definition at line 185 of file UTF8StringTools.cpp.

◆ toLowerCase()

const string toLowerCase ( const string &  str,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Transform string to lower case.

Parameters
strstring
cacheUTF8 position cache
Returns
lowercase string

Definition at line 204 of file UTF8StringTools.cpp.

◆ toUpperCase()

const string toUpperCase ( const string &  str,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Transform string to upper case.

Parameters
strstring
cacheUTF8 position cache
Returns
uppercase string

Definition at line 214 of file UTF8StringTools.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 224 of file UTF8StringTools.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 232 of file UTF8StringTools.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 240 of file UTF8StringTools.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 244 of file UTF8StringTools.cpp.

◆ padLeft()

const string padLeft ( const string &  str,
const string &  by,
int64_t  toLength,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Pad a string left.

Parameters
strstring
byby
toLengthto length
cachestr UTF8 position cache
Returns
padded string

Definition at line 250 of file UTF8StringTools.cpp.

◆ padRight()

const string padRight ( const string &  str,
const string &  by,
int64_t  toLength,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Pad a string right.

Parameters
strstring
byby
toLengthto length
cachestr UTF8 position cache
Returns
padded string

Definition at line 256 of file UTF8StringTools.cpp.

◆ 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 287 of file UTF8StringTools.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 299 of file UTF8StringTools.h.

◆ getLength()

int64_t getLength ( const string &  str,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Get UTF8 string length.

Parameters
strstring
cacheUTF8 position cache
Returns
UTF8 string length

Definition at line 264 of file UTF8StringTools.cpp.

◆ getCharAt()

const string getCharAt ( const string &  str,
int64_t  index,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Get UTF8 character at given index.

Parameters
strstring
indexindex
cacheUTF8 position cache
Returns
character as string

Definition at line 270 of file UTF8StringTools.cpp.

◆ getCodePointAt()

uint32_t getCodePointAt ( const string &  str,
int64_t  index,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Get UTF8 code point at given index.

Parameters
strstring
indexindex
cacheUTF8 position cache
Returns
character as codepoint

Definition at line 278 of file UTF8StringTools.cpp.

◆ getUTF8BinaryIndex()

int64_t getUTF8BinaryIndex ( const string &  str,
int64_t  charIdx,
::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache cache = nullptr 
)
static

Get UTF8 binary buffer index.

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

Definition at line 286 of file UTF8StringTools.cpp.


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