ZNC
trunk
|
String class that is used inside ZNC. More...
#include <ZNCString.h>
Public Types | |
enum | EEscape { EASCII, EURL, EHTML, ESQL, ENAMEDFMT, EDEBUG } |
Public Member Functions | |
CString (bool b) | |
CString (char c) | |
CString (unsigned char c) | |
CString (short i) | |
CString (unsigned short i) | |
CString (int i) | |
CString (unsigned int i) | |
CString (long i) | |
CString (unsigned long i) | |
CString (long long i) | |
CString (unsigned long long i) | |
CString (double i, int precision=2) | |
CString (float i, int precision=2) | |
CString () | |
CString (const char *c) | |
CString (const char *c, size_t l) | |
CString (const std::string &s) | |
CString (size_t n, char c) | |
~CString () | |
template<typename T > | |
bool | Convert (T *target) const |
Casts a CString to another type. More... | |
template<typename Iterator > | |
CString | Join (Iterator i_start, const Iterator &i_end) const |
Joins a collection of objects together, using 'this' as a delimiter. More... | |
int | CaseCmp (const CString &s, CString::size_type uLen=CString::npos) const |
Compare this string caselessly to some other string. More... | |
int | StrCmp (const CString &s, CString::size_type uLen=CString::npos) const |
Compare this string case sensitively to some other string. More... | |
bool | Equals (const CString &s, bool bCaseSensitive=false, CString::size_type uLen=CString::npos) const |
Check if this string is equal to some other string. More... | |
bool | WildCmp (const CString &sWild) const |
Do a wild compare on this string. More... | |
CString & | MakeUpper () |
Turn all characters in this string into their upper-case equivalent. More... | |
CString & | MakeLower () |
Turn all characters in this string into their lower-case equivalent. More... | |
CString | AsUpper () const |
Return a copy of this string with all characters turned into upper-case. More... | |
CString | AsLower () const |
Return a copy of this string with all characters turned into lower-case. More... | |
CString | Escape_n (EEscape eFrom, EEscape eTo) const |
CString | Escape_n (EEscape eTo) const |
CString & | Escape (EEscape eFrom, EEscape eTo) |
CString & | Escape (EEscape eTo) |
CString | Replace_n (const CString &sReplace, const CString &sWith, const CString &sLeft="", const CString &sRight="", bool bRemoveDelims=false) const |
Replace all occurrences in the current string. More... | |
unsigned int | Replace (const CString &sReplace, const CString &sWith, const CString &sLeft="", const CString &sRight="", bool bRemoveDelims=false) |
Replace all occurrences in the current string. More... | |
CString | Ellipsize (unsigned int uLen) const |
Ellipsize the current string. More... | |
CString | Left (size_type uCount) const |
Return the left part of the string. More... | |
CString | Right (size_type uCount) const |
Return the right part of the string. More... | |
CString | FirstLine () const |
Get the first line of this string. More... | |
CString | Token (size_t uPos, bool bRest=false, const CString &sSep=" ", bool bAllowEmpty=false) const |
Get a token out of this string. More... | |
CString | Token (size_t uPos, bool bRest, const CString &sSep, bool bAllowEmpty, const CString &sLeft, const CString &sRight, bool bTrimQuotes=true) const |
Get a token out of this string. More... | |
size_type | URLSplit (MCString &msRet) const |
size_type | OptionSplit (MCString &msRet, bool bUpperKeys=false) const |
size_type | QuoteSplit (VCString &vsRet) const |
size_type | Split (const CString &sDelim, VCString &vsRet, bool bAllowEmpty=true, const CString &sLeft="", const CString &sRight="", bool bTrimQuotes=true, bool bTrimWhiteSpace=false) const |
Split up this string into tokens. More... | |
size_type | Split (const CString &sDelim, SCString &ssRet, bool bAllowEmpty=true, const CString &sLeft="", const CString &sRight="", bool bTrimQuotes=true, bool bTrimWhiteSpace=false) const |
Split up this string into tokens. More... | |
CString | MD5 () const |
CString | SHA256 () const |
unsigned long | Base64Decode (CString &sRet) const |
Treat this string as base64-encoded data and decode it. More... | |
unsigned long | Base64Decode () |
Treat this string as base64-encoded data and decode it. More... | |
CString | Base64Decode_n () const |
Treat this string as base64-encoded data and decode it. More... | |
bool | Base64Encode (CString &sRet, unsigned int uWrap=0) const |
Base64-encode the current string. More... | |
bool | Base64Encode (unsigned int uWrap=0) |
Base64-encode the current string. More... | |
CString | Base64Encode_n (unsigned int uWrap=0) const |
Base64-encode the current string. More... | |
CString | Encrypt_n (const CString &sPass, const CString &sIvec="") const |
CString | Decrypt_n (const CString &sPass, const CString &sIvec="") const |
void | Encrypt (const CString &sPass, const CString &sIvec="") |
void | Decrypt (const CString &sPass, const CString &sIvec="") |
void | Crypt (const CString &sPass, bool bEncrypt, const CString &sIvec="") |
bool | ToBool () const |
short | ToShort () const |
unsigned short | ToUShort () const |
int | ToInt () const |
long | ToLong () const |
unsigned int | ToUInt () const |
unsigned long | ToULong () const |
unsigned long long | ToULongLong () const |
long long | ToLongLong () const |
double | ToDouble () const |
bool | Trim (const CString &s=" \t\r\n") |
Trim this string. More... | |
bool | TrimLeft (const CString &s=" \t\r\n") |
Trim this string. More... | |
bool | TrimRight (const CString &s=" \t\r\n") |
Trim this string. More... | |
CString | Trim_n (const CString &s=" \t\r\n") const |
Trim this string. More... | |
CString | TrimLeft_n (const CString &s=" \t\r\n") const |
Trim this string. More... | |
CString | TrimRight_n (const CString &s=" \t\r\n") const |
Trim this string. More... | |
bool | TrimPrefix (const CString &sPrefix=":") |
Trim a given prefix. More... | |
bool | TrimSuffix (const CString &sSuffix) |
Trim a given suffix. More... | |
CString | TrimPrefix_n (const CString &sPrefix=":") const |
Trim a given prefix. More... | |
CString | TrimSuffix_n (const CString &sSuffix) const |
Trim a given suffix. More... | |
bool | StartsWith (const CString &sPrefix) const |
Check whether the string starts with a given prefix. More... | |
bool | EndsWith (const CString &sSuffix) const |
Check whether the string ends with a given suffix. More... | |
bool | LeftChomp (size_type uLen=1) |
Remove characters from the beginning of this string. More... | |
bool | RightChomp (size_type uLen=1) |
Remove characters from the end of this string. More... | |
CString | LeftChomp_n (size_type uLen=1) const |
Remove characters from the beginning of this string. More... | |
CString | RightChomp_n (size_type uLen=1) const |
Remove characters from the end of this string. More... | |
CString & | StripControls () |
Remove controls characters from this string. More... | |
CString | StripControls_n () const |
Remove controls characters from this string. More... | |
Static Public Member Functions | |
static bool | WildCmp (const CString &sWild, const CString &sString) |
Do a wildcard comparision between two strings. More... | |
static EEscape | ToEscape (const CString &sEsc) |
static unsigned int | Replace (CString &sStr, const CString &sReplace, const CString &sWith, const CString &sLeft="", const CString &sRight="", bool bRemoveDelims=false) |
Replace all occurrences in a string. More... | |
static CString | NamedFormat (const CString &sFormat, const MCString &msValues) |
Build a string from a format string, replacing values from a map. More... | |
static CString | RandomString (unsigned int uLength) |
Produces a random string. More... | |
static CString | ToPercent (double d) |
Pretty-print a percent value. More... | |
static CString | ToByteStr (unsigned long long d) |
Pretty-print a number of bytes. More... | |
static CString | ToTimeStr (unsigned long s) |
Pretty-print a time span. More... | |
Protected Member Functions | |
unsigned char * | strnchr (const unsigned char *src, unsigned char c, unsigned int iMaxBytes, unsigned char *pFill=NULL, unsigned int *piCount=NULL) const |
String class that is used inside ZNC.
All strings that are used in ZNC and its modules should use instances of this class. It provides helpful functions for parsing input like Token() and Split().
enum CString::EEscape |
|
inlineexplicit |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
inline |
Referenced by Join().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
CString CString::AsLower | ( | ) | const |
Return a copy of this string with all characters turned into lower-case.
CString CString::AsUpper | ( | ) | const |
Return a copy of this string with all characters turned into upper-case.
unsigned long CString::Base64Decode | ( | CString & | sRet | ) | const |
Treat this string as base64-encoded data and decode it.
sRet | String to which the result of the decode is safed. |
unsigned long CString::Base64Decode | ( | ) |
Treat this string as base64-encoded data and decode it.
The result is saved in this CString instance.
CString CString::Base64Decode_n | ( | ) | const |
Treat this string as base64-encoded data and decode it.
bool CString::Base64Encode | ( | CString & | sRet, |
unsigned int | uWrap = 0 |
||
) | const |
bool CString::Base64Encode | ( | unsigned int | uWrap = 0 | ) |
Base64-encode the current string.
This string is overwritten with the result of the encode.
CString CString::Base64Encode_n | ( | unsigned int | uWrap = 0 | ) | const |
Base64-encode the current string.
int CString::CaseCmp | ( | const CString & | s, |
CString::size_type | uLen = CString::npos |
||
) | const |
Compare this string caselessly to some other string.
s | The string to compare to. |
uLen | The number of characters to compare. |
|
inline |
Casts a CString to another type.
Implemented via std::stringstream, you use this for any class that has an operator<<(std::ostream, YourClass).
target | The object to cast into. If the cast fails, its state is unspecified. |
CString CString::Ellipsize | ( | unsigned int | uLen | ) | const |
Ellipsize the current string.
For example, ellipsizing "Hello, I'm Bob" to the length 9 would result in "Hello,...".
uLen | The length to ellipsize to. |
bool CString::EndsWith | ( | const CString & | sSuffix | ) | const |
Check whether the string ends with a given suffix.
sSuffix | The suffix. |
bool CString::Equals | ( | const CString & | s, |
bool | bCaseSensitive = false , |
||
CString::size_type | uLen = CString::npos |
||
) | const |
Check if this string is equal to some other string.
s | The string to compare to. |
bCaseSensitive | True if you want the comparision to be case sensitive. |
uLen | Number of characters to consider. |
|
inline |
|
inline |
Joins a collection of objects together, using 'this' as a delimiter.
You can pass either pointers to arrays, or iterators to collections.
i_begin | An iterator pointing to the beginning of a group of objects. |
i_end | An iterator pointing past the end of a group of objects. |
References CString().
CString CString::Left | ( | size_type | uCount | ) | const |
Return the left part of the string.
uCount | The number of characters to keep. |
bool CString::LeftChomp | ( | size_type | uLen = 1 | ) |
Remove characters from the beginning of this string.
uLen | The number of characters to remove. |
CString CString::LeftChomp_n | ( | size_type | uLen = 1 | ) | const |
Remove characters from the beginning of this string.
This string object isn't modified.
uLen | The number of characters to remove. |
CString& CString::MakeLower | ( | ) |
Turn all characters in this string into their lower-case equivalent.
CString& CString::MakeUpper | ( | ) |
Turn all characters in this string into their upper-case equivalent.
CString CString::MD5 | ( | ) | const |
Build a string from a format string, replacing values from a map.
The format specification can contain simple named parameters that match keys in the given map. For example in the string "a {b} c", the key "b" is looked up in the map, and inserted for "{b}".
sFormat | The format specification. |
msValues | A map of named parameters to their values. |
size_type CString::OptionSplit | ( | MCString & | msRet, |
bool | bUpperKeys = false |
||
) | const |
size_type CString::QuoteSplit | ( | VCString & | vsRet | ) | const |
|
static |
Produces a random string.
uLength | The length of the resulting string. |
|
static |
Replace all occurrences in a string.
You can specify a "safe zone" via sLeft and sRight. Anything inside of such a zone will not be replaced. This does not do recursion, so e.g. with Replace("(a()a)", "a", "b", "(", ")", true)
you would get "a(b)" as result. The second opening brace and the second closing brace would not be seen as a delimitered and thus wouldn't be removed. The first a is inside a "safe zone" and thus is left alone, too.
sStr | The string to do the replacing on. This will also contain the result when this function returns. |
sReplace | The string that should be replaced. |
sWith | The replacement to use. |
sLeft | The string that marks the begin of the "safe zone". |
sRight | The string that marks the end of the "safe zone". |
bRemoveDelims | If this is true, all matches for sLeft and sRight are removed. |
unsigned int CString::Replace | ( | const CString & | sReplace, |
const CString & | sWith, | ||
const CString & | sLeft = "" , |
||
const CString & | sRight = "" , |
||
bool | bRemoveDelims = false |
||
) |
Replace all occurrences in the current string.
sReplace | The string to look for. |
sWith | The replacement to use. |
sLeft | The delimiter at the beginning of a safe zone. |
sRight | The delimiter at the end of a safe zone. |
bRemoveDelims | If true, all matching delimiters are removed. |
CString CString::Replace_n | ( | const CString & | sReplace, |
const CString & | sWith, | ||
const CString & | sLeft = "" , |
||
const CString & | sRight = "" , |
||
bool | bRemoveDelims = false |
||
) | const |
Replace all occurrences in the current string.
sReplace | The string to look for. |
sWith | The replacement to use. |
sLeft | The delimiter at the beginning of a safe zone. |
sRight | The delimiter at the end of a safe zone. |
bRemoveDelims | If true, all matching delimiters are removed. |
CString CString::Right | ( | size_type | uCount | ) | const |
Return the right part of the string.
uCount | The number of characters to keep. |
bool CString::RightChomp | ( | size_type | uLen = 1 | ) |
Remove characters from the end of this string.
uLen | The number of characters to remove. |
CString CString::RightChomp_n | ( | size_type | uLen = 1 | ) | const |
Remove characters from the end of this string.
This string object isn't modified.
uLen | The number of characters to remove. |
CString CString::SHA256 | ( | ) | const |
size_type CString::Split | ( | const CString & | sDelim, |
VCString & | vsRet, | ||
bool | bAllowEmpty = true , |
||
const CString & | sLeft = "" , |
||
const CString & | sRight = "" , |
||
bool | bTrimQuotes = true , |
||
bool | bTrimWhiteSpace = false |
||
) | const |
Split up this string into tokens.
Via sLeft and sRight you can define "markers" like with Replace(). Anything in such a marked section is treated as a single token. All occurences of sDelim in such a block are ignored.
sDelim | Delimiter between tokens. |
vsRet | Vector for returning the result. |
bAllowEmpty | Do empty tokens count as a valid token? |
sLeft | Left delimiter like with Replace(). |
sRight | Right delimiter like with Replace(). |
bTrimQuotes | Should sLeft and sRight be removed from the token they mark? |
bTrimWhiteSpace | If this is true, CString::Trim() is called on each token. |
size_type CString::Split | ( | const CString & | sDelim, |
SCString & | ssRet, | ||
bool | bAllowEmpty = true , |
||
const CString & | sLeft = "" , |
||
const CString & | sRight = "" , |
||
bool | bTrimQuotes = true , |
||
bool | bTrimWhiteSpace = false |
||
) | const |
Split up this string into tokens.
This function is identical to the other CString::Split(), except that the result is returned as a SCString instead of a VCString.
bool CString::StartsWith | ( | const CString & | sPrefix | ) | const |
Check whether the string starts with a given prefix.
sPrefix | The prefix. |
int CString::StrCmp | ( | const CString & | s, |
CString::size_type | uLen = CString::npos |
||
) | const |
Compare this string case sensitively to some other string.
s | The string to compare to. |
uLen | The number of characters to compare. |
CString& CString::StripControls | ( | ) |
Remove controls characters from this string.
Controls characters are color codes, and those in C0 set See https://en.wikipedia.org/wiki/C0_and_C1_control_codes
CString CString::StripControls_n | ( | ) | const |
Remove controls characters from this string.
Controls characters are color codes, and those in C0 set See https://en.wikipedia.org/wiki/C0_and_C1_control_codes This string object isn't modified.
|
protected |
bool CString::ToBool | ( | ) | const |
Referenced by CConfig::FindBoolEntry().
|
static |
Pretty-print a number of bytes.
d | The number of bytes. |
double CString::ToDouble | ( | ) | const |
Referenced by CConfig::FindDoubleEntry(), and PString::GetSV().
int CString::ToInt | ( | ) | const |
CString CString::Token | ( | size_t | uPos, |
bool | bRest = false , |
||
const CString & | sSep = " " , |
||
bool | bAllowEmpty = false |
||
) | const |
Get a token out of this string.
For example in the string "a bc d e", each of "a", "bc", "d" and "e" are tokens.
uPos | The number of the token you are interested. The first token has a position of 0. |
bRest | If false, only the token you asked for is returned. Else you get the substring starting from the beginning of your token. |
sSep | Seperator between tokens. |
bAllowEmpty | If this is true, empty tokens are allowed. In the example from above this means that there is a token "" before the "e" token. |
Referenced by FirstLine().
long CString::ToLong | ( | ) | const |
long long CString::ToLongLong | ( | ) | const |
Referenced by PString::GetSV().
|
static |
Pretty-print a percent value.
d | The percent value. This should be in range 0-100. |
short CString::ToShort | ( | ) | const |
|
static |
Pretty-print a time span.
s | Number of seconds to print. |
unsigned int CString::ToUInt | ( | ) | const |
Referenced by CConfig::FindUIntEntry().
unsigned long CString::ToULong | ( | ) | const |
unsigned long long CString::ToULongLong | ( | ) | const |
Referenced by PString::GetSV().
unsigned short CString::ToUShort | ( | ) | const |
Referenced by CConfig::FindUShortEntry().
bool CString::Trim | ( | const CString & | s = " \t\r\n" | ) |
Trim this string.
All leading/trailing occurences of characters from s are removed.
s | A list of characters that should be trimmed. |
Trim this string.
All leading/trailing occurences of characters from s are removed. This CString instance is not modified.
s | A list of characters that should be trimmed. |
bool CString::TrimLeft | ( | const CString & | s = " \t\r\n" | ) |
Trim this string.
All leading occurences of characters from s are removed.
s | A list of characters that should be trimmed. |
Trim this string.
All leading occurences of characters from s are removed. This CString instance is not modified.
s | A list of characters that should be trimmed. |
bool CString::TrimPrefix | ( | const CString & | sPrefix = ":" | ) |
Trim a given prefix.
sPrefix | The prefix that should be removed. |
Trim a given prefix.
sPrefix | The prefix that should be removed. |
bool CString::TrimRight | ( | const CString & | s = " \t\r\n" | ) |
Trim this string.
All trailing occurences of characters from s are removed.
s | A list of characters that should be trimmed. |
Trim this string.
All trailing occurences of characters from s are removed. This CString instance is not modified.
s | A list of characters that should be trimmed. |
bool CString::TrimSuffix | ( | const CString & | sSuffix | ) |
Trim a given suffix.
sSuffix | The suffix that should be removed. |
Trim a given suffix.
sSuffix | The suffix that should be removed. |
Referenced by CDir::FillByWildcard().
size_type CString::URLSplit | ( | MCString & | msRet | ) | const |
Do a wildcard comparision between two strings.
For example, the following returns true: WildCmp("*!?bar@foo", "I_am!~bar@foo");
sWild | The wildcards used for the comparison. |
sString | The string that is used for comparing. |
Referenced by CDir::FillByWildcard().
bool CString::WildCmp | ( | const CString & | sWild | ) | const |
Do a wild compare on this string.
sWild | The wildcards used to for the comparison. |
this->WildCmp(sWild, *this);
.