KVIrc 5.2.0
Developer APIs
KviQString.h
Go to the documentation of this file.
1#ifndef _KVI_QSTRING_H_
2#define _KVI_QSTRING_H_
3//=============================================================================
4//
5// File : KviQString.h
6// Creation date : Mon Aug 04 2003 13:36:33 CEST by Szymon Stefanek
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 2003-2010 Szymon Stefanek (pragma at kvirc dot net)
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//=============================================================================
26
33#include "kvi_settings.h"
34#include "kvi_inttypes.h"
35#include "kvi_stdarg.h"
36
37#include <QByteArray>
38#include <QChar>
39#include <QString>
40
48namespace KviQString
49{
62
66 extern KVILIB_API const QString Empty;
67
75 extern KVILIB_API QString makeSizeReadable(quint64 size);
76
85 extern KVILIB_API bool equalCS(const QString & sz1, const QString & sz2);
86
95 extern KVILIB_API bool equalCS(const QString & sz1, const char * pc2);
96
105 extern KVILIB_API bool equalCI(const QString & sz1, const QString & sz2);
106
115 extern KVILIB_API bool equalCI(const QString & sz1, const char * pc2);
116
126 extern KVILIB_API bool equalCI(const QString & sz1, const QChar * pC2);
127
137 extern KVILIB_API bool equalCSN(const QString & sz1, const QString & sz2, unsigned int uLen);
138
148 extern KVILIB_API bool equalCSN(const QString & sz1, const char * pc2, unsigned int uLen);
149
159 extern KVILIB_API bool equalCIN(const QString & sz1, const QString & sz2, unsigned int uLen);
160
170 extern KVILIB_API bool equalCIN(const QString & sz1, const char * pc2, unsigned int uLen);
171
182 extern KVILIB_API bool equalCIN(const QString & sz1, const QChar * pC2, unsigned int uLen);
183
196 extern KVILIB_API int cmpCI(const QString & sz1, const QString & sz2, bool bNonAlphaGreater = false);
197 // sz1.compare(sz2,Qt::CaseInsensitive)
198
211 extern KVILIB_API int cmpCIN(const QString & sz1, const QString & sz2, unsigned int uLen);
212
221 extern KVILIB_API void ensureLastCharIs(QString & szSrc, const QChar & c);
222
229 extern KVILIB_API bool matchWildExpressions(const QString & szM1, const QString & szM2);
230
240 extern KVILIB_API bool matchString(const QString & szExp, const QString & szStr, bool bIsRegExp = false, bool bExact = false, bool bCs = false);
241
249 extern KVILIB_API void vsprintf(QString & szSrc, const QString & szFmt, kvi_va_list list);
250
256 extern KVILIB_API void stripRightWhiteSpace(QString & szSrc);
257
264 extern KVILIB_API void stripLeft(QString & szSrc, const QChar & c);
265
272 extern KVILIB_API void stripRight(QString & szSrc, const QChar & c);
273
281 extern KVILIB_API void appendFormatted(QString & szSrc, QString szFmt, ...);
282
289 extern KVILIB_API void appendNumber(QString & szSrc, double dReal);
290
297 extern KVILIB_API void appendNumber(QString & szSrc, kvi_i64_t iInteger);
298
305 extern KVILIB_API void appendNumber(QString & szSrc, int iInteger);
306
313 extern KVILIB_API void appendNumber(QString & szSrc, unsigned int uInteger);
314
321 extern KVILIB_API void appendNumber(QString & szSrc, kvi_u64_t uInteger);
322
332 extern KVILIB_API void cutFromFirst(QString & szSrc, const QChar & c, bool bIncluded = true);
333
343 extern KVILIB_API void cutFromFirst(QString & szSrc, const QString & szFind, bool bIncluded = true);
344
354 extern KVILIB_API void cutFromLast(QString & szSrc, const QChar & c, bool bIncluded = true);
355
365 extern KVILIB_API void cutFromLast(QString & szSrc, const QString & szFind, bool bIncluded = true);
366
377 extern KVILIB_API void cutToFirst(QString & szSrc, const QChar & c, bool bIncluded = true, bool bClearIfNotFound = false);
378
389 extern KVILIB_API void cutToFirst(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bClearIfNotFound = false);
390
401 extern KVILIB_API void cutToLast(QString & szSrc, const QChar & c, bool bIncluded = true, bool bClearIfNotFound = false);
402
413 extern KVILIB_API void cutToLast(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bClearIfNotFound = false);
414
427 extern KVILIB_API QString leftToFirst(QString & szSrc, const QChar & c, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
428
441 extern KVILIB_API QString leftToFirst(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
442
455 extern KVILIB_API QString leftToLast(QString & szSrc, const QChar & c, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
456
469 extern KVILIB_API QString leftToLast(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
470
476 extern KVILIB_API QString upperISO88591(const QString & szSrc);
477
483 extern KVILIB_API QString lowerISO88591(const QString & szSrc);
484
491 extern KVILIB_API QString getToken(QString & szSrc, const QChar & sep);
492
500 extern KVILIB_API void transliterate(QString & szSrc, const QString & szToFind, const QString & szReplacement);
501
508 extern KVILIB_API void bufferToHex(QString & szRetBuffer, const unsigned char * pcBuffer, unsigned int uLen);
509
516 extern KVILIB_API void escapeKvs(QString * szData, uint uFlags = 0);
517
523 extern KVILIB_API QString toHtmlEscaped(QString szData);
524
531 inline kvi_i64_t toI64(QString & szNumber, bool * bOk)
532 {
533#if SYSTEM_SIZE_OF_LONG_INT == 8
534 return szNumber.toLong(bOk);
535#else
536 return szNumber.toLongLong(bOk);
537#endif
538 }
539
546 inline kvi_u64_t toU64(QString & szNumber, bool * bOk)
547 {
548#if SYSTEM_SIZE_OF_LONG_INT == 8
549 return szNumber.toULong(bOk);
550#else
551 return szNumber.toULongLong(bOk);
552#endif
553 }
554}
555
556#endif //_KVI_QSTRING_H_
long long int kvi_i64_t
SYSTEM_SIZE_OF_SHORT_INT.
Definition kvi_inttypes.h:65
unsigned long long int kvi_u64_t
Definition kvi_inttypes.h:66
This file contains compile time settings.
#define KVILIB_API
Definition kvi_settings.h:124
#define kvi_va_list
Definition kvi_stdarg.h:30
A namespace for QString helper functions.
Definition KviQString.cpp:45
void ensureLastCharIs(QString &szSrc, const QChar &c)
Ensures the last char of a string is the given char.
Definition KviQString.cpp:483
kvi_u64_t toU64(QString &szNumber, bool *bOk)
Return the string converted to an unsigned long.
Definition KviQString.h:546
QString toHtmlEscaped(QString szData)
Escapes any html special character from a string (wrapper to QString::toHtmlEscaped)
Definition KviQString.cpp:1339
void stripLeft(QString &szSrc, const QChar &c)
Trims all c chars at the start of the given string.
Definition KviQString.cpp:571
void escapeKvs(QString *szData, uint uFlags)
Escapes any kvs special character from a string.
Definition KviQString.cpp:1314
QString getToken(QString &szSrc, const QChar &sep)
Returns a token from a string.
Definition KviQString.cpp:491
kvi_i64_t toI64(QString &szNumber, bool *bOk)
Return the string converted to a long.
Definition KviQString.h:531
void vsprintf(QString &szSrc, const QString &szFmt, kvi_va_list list)
Writes to the character string.
Definition KviQString.cpp:632
int cmpCI(const QString &sz1, const QString &sz2, bool bNonAlphaGreater)
Compares two strings with case insensitive.
Definition KviQString.cpp:383
void bufferToHex(QString &szRetBuffer, const unsigned char *pcBuffer, unsigned int uLen)
Returns an hexadecimal converted string starting from a buffer.
Definition KviQString.cpp:1300
void cutFromLast(QString &szSrc, const QChar &c, bool bIncluded)
Cuts the string after the last occurrence of the given char.
Definition KviQString.cpp:1129
QString upperISO88591(const QString &szSrc)
Returns an ISO-8859-1 upper case string.
Definition KviQString.cpp:1226
QString makeSizeReadable(quint64 bytes)
Returns a readable size in byte's multiples.
Definition KviQString.cpp:223
void cutToLast(QString &szSrc, const QChar &c, bool bIncluded, bool bClearIfNotFound)
Cuts the string until the last occurrence of the given char is found.
Definition KviQString.cpp:1170
bool matchString(const QString &szExp, const QString &szStr, bool bIsRegExp, bool bExact, bool bCs)
Matches two string containging wildcards (* and ?) or regular expressions.
Definition KviQString.cpp:1071
int cmpCIN(const QString &sz1, const QString &sz2, unsigned int uLen)
Compares two strings with case insensitive up to N chars.
Definition KviQString.cpp:445
void cutFromFirst(QString &szSrc, const QChar &c, bool bIncluded)
Cuts the string after the first occurrence of the given char.
Definition KviQString.cpp:1112
EscapeKVSFlags
Holds the flags to escape KVS.
Definition KviQString.h:55
@ EscapeSpace
Definition KviQString.h:56
@ PermitVariables
Definition KviQString.h:57
@ EscapeParenthesis
Definition KviQString.h:60
@ PermitMultiLine
Definition KviQString.h:59
@ PermitFunctions
Definition KviQString.h:58
void appendFormatted(QString &szSrc, QString szFmt,...)
Appends a formatted string.
Definition KviQString.cpp:929
void stripRight(QString &szSrc, const QChar &c)
Trims all c chars at the end of the given string.
Definition KviQString.cpp:551
const QString Empty
A global empty string (note that this is ALSO NULL under Qt 3.x)
Definition KviQString.cpp:47
void appendNumber(QString &szSrc, double dReal)
Appends the given number to the source string.
Definition KviQString.cpp:591
bool matchWildExpressions(const QString &szM1, const QString &szM2)
Matches two strings containging wildcards (* and ?)
Definition KviQString.cpp:940
bool equalCSN(const QString &sz1, const QString &sz2, unsigned int uLen)
Compares two strings with case sensitive up to N chars.
Definition KviQString.cpp:51
bool equalCS(const QString &sz1, const QString &sz2)
Compares two strings with case sensitive.
Definition KviQString.cpp:255
QString leftToLast(QString &szSrc, const QChar &c, bool bIncluded, bool bReturnFullStringIfNotFound)
Returns the string up to the last occurrence of the given char.
Definition KviQString.cpp:1210
void stripRightWhiteSpace(QString &szSrc)
Trims all the whitespaces at the end of the given string.
Definition KviQString.cpp:531
void cutToFirst(QString &szSrc, const QChar &c, bool bIncluded, bool bClearIfNotFound)
Cuts the string until the first occurrence of the given char is found.
Definition KviQString.cpp:1146
void transliterate(QString &szSrc, const QString &szToFind, const QString &szReplacement)
Replaces a string with another.
Definition KviQString.cpp:1280
bool equalCI(const QString &sz1, const QString &sz2)
Compares two strings with case insensitive.
Definition KviQString.cpp:283
QString lowerISO88591(const QString &szSrc)
Returns an ISO-8859-1 lower case string.
Definition KviQString.cpp:1252
QString leftToFirst(QString &szSrc, const QChar &c, bool bIncluded, bool bReturnFullStringIfNotFound)
Returns the string up to the the first occurrence of the given char.
Definition KviQString.cpp:1194
bool equalCIN(const QString &sz1, const QString &sz2, unsigned int uLen)
Compares two strings with case insensitive up to N chars.
Definition KviQString.cpp:84