20 #include <znc/zncconfig.h> 26 #include <sys/types.h> 27 #include <initializer_list> 29 #define _SQL(s) CString("'" + CString(s).Escape_n(CString::ESQL) + "'") 30 #define _URL(s) CString(s).Escape_n(CString::EURL) 31 #define _HTML(s) CString(s).Escape_n(CString::EHTML) 32 #define _NAMEDFMT(s) CString(s).Escape_n(CString::ENAMEDFMT) 39 typedef std::vector<std::pair<CString, CString>>
VPair;
41 static const unsigned char XX = 0xff;
42 static const unsigned char base64_table[256] = {
43 XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
44 XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
45 XX, XX, XX, XX, XX, 62, XX, XX, XX, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60,
46 61, XX, XX, XX, XX, XX, XX, XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
47 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, XX, XX, XX, XX,
48 XX, XX, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
49 43, 44, 45, 46, 47, 48, 49, 50, 51, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
50 XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
51 XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
52 XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
53 XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
54 XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
55 XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
56 XX, XX, XX, XX, XX, XX, XX, XX, XX,
85 explicit CString(
bool b) :
std::string(b ?
"true" :
"false") {}
87 explicit CString(
unsigned char c);
89 explicit CString(
unsigned short i);
91 explicit CString(
unsigned int i);
93 explicit CString(
unsigned long i);
95 explicit CString(
unsigned long long i);
96 explicit CString(
double i,
int precision = 2);
97 explicit CString(
float i,
int precision = 2);
104 CString(std::initializer_list<char> list) :
std::string(list) {}
113 template <
typename T>
115 std::stringstream ss(*
this);
127 template <
typename Iterator>
129 if (i_start == i_end)
return CString(
"");
130 std::ostringstream output;
134 if (i_start == i_end)
return CString(output.str());
148 CString::size_type uLen = CString::npos)
const;
156 int StrCmp(
const CString& s, CString::size_type uLen = CString::npos)
const;
169 CString::size_type uLen = CString::npos)
const;
246 bool bRemoveDelims =
false);
260 bool bRemoveDelims =
false)
const;
272 bool bRemoveDelims =
false);
312 bool bAllowEmpty =
false)
const;
320 bool bTrimQuotes =
true)
const;
342 bool bAllowEmpty =
true,
const CString& sLeft =
"",
343 const CString& sRight =
"",
bool bTrimQuotes =
true,
344 bool bTrimWhiteSpace =
false)
const;
351 bool bAllowEmpty =
true,
const CString& sLeft =
"",
352 const CString& sRight =
"",
bool bTrimQuotes =
true,
353 bool bTrimWhiteSpace =
false)
const;
446 unsigned int ToUInt()
const;
583 unsigned char*
strnchr(
const unsigned char* src,
unsigned char c,
584 unsigned int iMaxBytes,
585 unsigned char* pFill =
nullptr,
586 unsigned int* piCount =
nullptr)
const;
595 class MCString :
public std::map<CString, CString> {
600 MCString(std::initializer_list<std::pair<const CString, CString>> list)
676 : m_sFormat(sFormat) {}
678 : m_sFormat(
std::move(sFormat)) {}
680 template <
typename... Args>
683 apply(values, 1, args...);
688 template <
typename Arg,
typename... Rest>
689 void apply(
MCString& values,
int index,
const Arg& arg,
690 const Rest&... rest)
const {
692 apply(values, index + 1, rest...);
695 void apply(
MCString& values,
int index)
const {}
702 inline void PrintTo(
const CString& s, std::ostream* os) {
707 #endif // !ZNCSTRING_H bool Convert(T *target) const
Casts a CString to another type.
Definition: ZNCString.h:114
CString Token(size_t uPos, bool bRest=false, const CString &sSep=" ", bool bAllowEmpty=false) const
Get a token out of this string.
void Crypt(const CString &sPass, bool bEncrypt, const CString &sIvec="")
CString Base64Encode_n(unsigned int uWrap=0) const
Base64-encode the current string.
CString TrimPrefix_n(const CString &sPrefix=":") const
Trim a given prefix.
CString Join(Iterator i_start, const Iterator &i_end) const
Joins a collection of objects together, using 'this' as a delimiter.
Definition: ZNCString.h:128
virtual bool ReadFilter(CString &sKey, CString &sValue) const
Filter used while reading this map.
Definition: ZNCString.h:654
size_type QuoteSplit(VCString &vsRet) const
bool LeftChomp(size_type uLen=1)
Remove characters from the beginning of this string.
CString Escape_n(EEscape eFrom, EEscape eTo) const
virtual CString & Encode(CString &sValue) const
Encode a value so that it can safely be parsed by ReadFromDisk().
int StrCmp(const CString &s, CString::size_type uLen=CString::npos) const
Compare this string case sensitively to some other string.
CString(const char *c, size_t l)
Definition: ZNCString.h:101
bool TrimRight(const CString &s=" \\)
Trim this string.
Writing to the file failed.
Definition: ZNCString.h:616
MCString(std::initializer_list< std::pair< const CString, CString >> list)
Construct a MCString using an initializer list eg.
Definition: ZNCString.h:600
void Decrypt(const CString &sPass, const CString &sIvec="")
Definition: ZNCString.h:75
bool Equals(const CString &s, CaseSensitivity cs=CaseInsensitive) const
Check if this string is equal to some other string.
CString()
Definition: ZNCString.h:99
bool TrimSuffix(const CString &sSuffix)
Trim a given suffix.
CString & MakeUpper()
Turn all characters in this string into their upper-case equivalent.
status_t
Status codes that can be returned by WriteToDisk() and ReadFromDisk().
Definition: ZNCString.h:610
CString(bool b)
Definition: ZNCString.h:85
~CString()
Definition: ZNCString.h:105
CString Left(size_type uCount) const
Return the left part of the string.
Definition: ZNCString.h:73
CString(std::initializer_list< char > list)
Definition: ZNCString.h:104
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.
ReadFilter() failed.
Definition: ZNCString.h:620
CString(const std::string &s)
Definition: ZNCString.h:102
CString Right(size_type uCount) const
Return the right part of the string.
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.
CString Decrypt_n(const CString &sPass, const CString &sIvec="") const
CString Base64Decode_n() const
Treat this string as base64-encoded data and decode it.
virtual bool WriteFilter(CString &sKey, CString &sValue) const
Filter used while writing this map.
Definition: ZNCString.h:644
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.
std::set< CString > SCString
Definition: ZNCString.h:35
Definition: ZNCString.h:76
Definition: ZNCString.h:71
MCString()
Construct an empty MCString.
Definition: ZNCString.h:598
EEscape
Definition: ZNCString.h:70
Definition: ZNCString.h:74
CString AsUpper() const
Return a copy of this string with all characters turned into upper-case.
Opening the file failed.
Definition: ZNCString.h:614
size_type URLSplit(MCString &msRet) const
CString FirstLine() const
Get the first line of this string.
Definition: ZNCString.h:294
CaseSensitivity
Definition: ZNCString.h:59
size_type OptionSplit(MCString &msRet, bool bUpperKeys=false) const
unsigned char * strnchr(const unsigned char *src, unsigned char c, unsigned int iMaxBytes, unsigned char *pFill=nullptr, unsigned int *piCount=nullptr) const
CString LeftChomp_n(size_type uLen=1) const
Remove characters from the beginning of this string.
std::vector< CString > VCString
Definition: ZNCString.h:38
CString Ellipsize(unsigned int uLen) const
Ellipsize the current string.
No errors.
Definition: ZNCString.h:612
unsigned int ToUInt() const
String class that is used inside ZNC.
Definition: ZNCString.h:68
static CString ToPercent(double d)
Pretty-print a percent value.
CString StripControls_n() const
Remove controls characters from this string.
WriteFilter() failed.
Definition: ZNCString.h:618
static const CaseSensitivity CaseSensitive
Definition: ZNCString.h:81
static EEscape ToEscape(const CString &sEsc)
static bool WildCmp(const CString &sWild, const CString &sString, CaseSensitivity cs=CaseSensitive)
Do a wildcard comparison between two strings.
Definition: ZNCString.h:72
bool Base64Encode(CString &sRet, unsigned int uWrap=0) const
Base64-encode the current string.
bool RightChomp(size_type uLen=1)
Remove characters from the end of this string.
bool TrimLeft(const CString &s=" \\)
Trim this string.
unsigned long Base64Decode()
Treat this string as base64-encoded data and decode it.
static const MCString EmptyMap
A static instance of an empty map.
Definition: ZNCString.h:606
enum status_t ReadFromDisk(const CString &sPath)
Read a map from a file.
CString Encrypt_n(const CString &sPass, const CString &sIvec="") const
void Encrypt(const CString &sPass, const CString &sIvec="")
long long ToLongLong() const
size_t Find(const CString &s, CaseSensitivity cs=CaseInsensitive) const
Find the position of the given substring.
unsigned long ToULong() const
bool Contains(const CString &s, CaseSensitivity cs=CaseInsensitive) const
Check whether the string contains a given string.
A dictionary for strings.
Definition: ZNCString.h:595
CString & Escape(EEscape eFrom, EEscape eTo)
static CString ToByteStr(unsigned long long d)
Pretty-print a number of bytes.
unsigned long long ToULongLong() const
static CString RandomString(unsigned int uLength)
Produces a random string.
bool StartsWith(const CString &sPrefix, CaseSensitivity cs=CaseInsensitive) const
Check whether the string starts with a given prefix.
unsigned short ToUShort() const
CString & MakeLower()
Turn all characters in this string into their lower-case equivalent.
std::vector< std::pair< CString, CString > > VPair
Definition: ZNCString.h:39
Definition: ZNCString.h:77
bool Trim(const CString &s=" \\)
Trim this string.
virtual CString & Decode(CString &sValue) const
Undo the effects of Encode().
CString TrimSuffix_n(const CString &sSuffix) const
Trim a given suffix.
CString(const char *c)
Definition: ZNCString.h:100
virtual ~MCString()
Destruct this MCString.
Definition: ZNCString.h:603
static CString ToTimeStr(unsigned long s)
Pretty-print a time span.
CString TrimRight_n(const CString &s=" \\) const
Trim this string.
int CaseCmp(const CString &s, CString::size_type uLen=CString::npos) const
Compare this string caselessly to some other string.
CString TrimLeft_n(const CString &s=" \\) const
Trim this string.
CString & StripControls()
Remove controls characters from this string.
CString AsLower() const
Return a copy of this string with all characters turned into lower-case.
static CString NamedFormat(const CString &sFormat, const MCString &msValues)
Build a string from a format string, replacing values from a map.
bool TrimPrefix(const CString &sPrefix=":")
Trim a given prefix.
static const CaseSensitivity CaseInsensitive
Definition: ZNCString.h:82
enum status_t WriteToDisk(const CString &sPath, mode_t iMode=0644) const
Write this map to a file.
bool EndsWith(const CString &sSuffix, CaseSensitivity cs=CaseInsensitive) const
Check whether the string ends with a given suffix.
CString(size_t n, char c)
Definition: ZNCString.h:103
CString RightChomp_n(size_type uLen=1) const
Remove characters from the end of this string.
Definition: ZNCString.h:78
CString Trim_n(const CString &s=" \\) const
Trim this string.