KVIrc  4.9.2
DeveloperAPIs
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 <QString>
38 #include <QByteArray>
39 
47 namespace KviQString
48 {
54  {
60  };
61 
65  extern KVILIB_API const QString Empty;
66 
74  extern KVILIB_API QString makeSizeReadable(quint64 size);
75 
84  extern KVILIB_API bool equalCS(const QString & sz1, const QString & sz2);
85 
94  extern KVILIB_API bool equalCS(const QString & sz1, const char * pc2);
95 
104  extern KVILIB_API bool equalCI(const QString & sz1, const QString & sz2);
105 
114  extern KVILIB_API bool equalCI(const QString & sz1, const char * pc2);
115 
125  extern KVILIB_API bool equalCI(const QString & sz1, const QChar * pC2);
126 
136  extern KVILIB_API bool equalCSN(const QString & sz1, const QString & sz2, unsigned int uLen);
137 
147  extern KVILIB_API bool equalCSN(const QString & sz1, const char * pc2, unsigned int uLen);
148 
158  extern KVILIB_API bool equalCIN(const QString & sz1, const QString & sz2, unsigned int uLen);
159 
169  extern KVILIB_API bool equalCIN(const QString & sz1, const char * pc2, unsigned int uLen);
170 
181  extern KVILIB_API bool equalCIN(const QString & sz1, const QChar * pC2, unsigned int uLen);
182 
195  extern KVILIB_API int cmpCI(const QString & sz1, const QString & sz2, bool bNonAlphaGreater = false);
196  // sz1.compare(sz2,Qt::CaseInsensitive)
197 
210  extern KVILIB_API int cmpCIN(const QString & sz1, const QString & sz2, unsigned int uLen);
211 
220  extern KVILIB_API void ensureLastCharIs(QString & szSrc, const QChar & c);
221 
228  extern KVILIB_API bool matchWildExpressions(const QString & szM1, const QString & szM2);
229 
239  extern KVILIB_API bool matchString(const QString & szExp, const QString & szStr, bool bIsRegExp = false, bool bExact = false, bool bCs = false);
240 
248  extern KVILIB_API void vsprintf(QString & szSrc, const QString & szFmt, kvi_va_list list);
249 
255  extern KVILIB_API void stripRightWhiteSpace(QString & szSrc);
256 
263  extern KVILIB_API void stripLeft(QString & szSrc, const QChar & c);
264 
271  extern KVILIB_API void stripRight(QString & szSrc, const QChar & c);
272 
280  extern KVILIB_API void appendFormatted(QString & szSrc, QString szFmt, ...);
281 
288  extern KVILIB_API void appendNumber(QString & szSrc, double dReal);
289 
296  extern KVILIB_API void appendNumber(QString & szSrc, kvi_i64_t iInteger);
297 
304  extern KVILIB_API void appendNumber(QString & szSrc, int iInteger);
305 
312  extern KVILIB_API void appendNumber(QString & szSrc, unsigned int uInteger);
313 
320  extern KVILIB_API void appendNumber(QString & szSrc, kvi_u64_t uInteger);
321 
331  extern KVILIB_API void cutFromFirst(QString & szSrc, const QChar & c, bool bIncluded = true);
332 
342  extern KVILIB_API void cutFromFirst(QString & szSrc, const QString & szFind, bool bIncluded = true);
343 
353  extern KVILIB_API void cutFromLast(QString & szSrc, const QChar & c, bool bIncluded = true);
354 
364  extern KVILIB_API void cutFromLast(QString & szSrc, const QString & szFind, bool bIncluded = true);
365 
376  extern KVILIB_API void cutToFirst(QString & szSrc, const QChar & c, bool bIncluded = true, bool bClearIfNotFound = false);
377 
388  extern KVILIB_API void cutToFirst(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bClearIfNotFound = false);
389 
400  extern KVILIB_API void cutToLast(QString & szSrc, const QChar & c, bool bIncluded = true, bool bClearIfNotFound = false);
401 
412  extern KVILIB_API void cutToLast(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bClearIfNotFound = false);
413 
426  extern KVILIB_API QString leftToFirst(QString & szSrc, const QChar & c, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
427 
440  extern KVILIB_API QString leftToFirst(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
441 
454  extern KVILIB_API QString leftToLast(QString & szSrc, const QChar & c, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
455 
468  extern KVILIB_API QString leftToLast(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
469 
475  extern KVILIB_API QString upperISO88591(const QString & szSrc);
476 
482  extern KVILIB_API QString lowerISO88591(const QString & szSrc);
483 
490  extern KVILIB_API QString getToken(QString & szSrc, const QChar & sep);
491 
499  extern KVILIB_API void transliterate(QString & szSrc, const QString & szToFind, const QString & szReplacement);
500 
507  extern KVILIB_API void bufferToHex(QString & szRetBuffer, const unsigned char * pcBuffer, unsigned int uLen);
508 
515  extern KVILIB_API void escapeKvs(QString * szData, uint uFlags = 0);
516 
522  extern KVILIB_API QString toHtmlEscaped(QString szData);
523 
530  inline kvi_i64_t toI64(QString & szNumber, bool * bOk)
531  {
532 #if SYSTEM_SIZE_OF_LONG_INT == 8
533  return szNumber.toLong(bOk);
534 #else
535  return szNumber.toLongLong(bOk);
536 #endif
537  }
538 
545  inline kvi_u64_t toU64(QString & szNumber, bool * bOk)
546  {
547 #if SYSTEM_SIZE_OF_LONG_INT == 8
548  return szNumber.toULong(bOk);
549 #else
550  return szNumber.toULongLong(bOk);
551 #endif
552  }
553 }
554 
555 #endif //_KVI_QSTRING_H_
bool matchWildExpressions(const QString &szM1, const QString &szM2)
Matches two strings containging wildcards (* and ?)
Definition: KviQString.cpp:942
Definition: KviQString.h:56
char s char s char s s s s s char char c s *s c s s s d c s *s d c d d d d c
Definition: KviIrcNumericCodes.h:391
Definition: KviQString.h:58
void appendFormatted(QString &szSrc, QString szFmt,...)
Appends a formatted string.
Definition: KviQString.cpp:931
kvi_u64_t toU64(QString &szNumber, bool *bOk)
Return the string converted to an unsigned long.
Definition: KviQString.h:545
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:1073
void stripRight(QString &szSrc, const QChar &c)
Trims all c chars at the end of the given string.
Definition: KviQString.cpp:553
void appendNumber(QString &szSrc, double dReal)
Appends the given number to the source string.
Definition: KviQString.cpp:593
void escapeKvs(QString *szData, uint uFlags)
Escapes any kvs special character from a string.
Definition: KviQString.cpp:1316
EscapeKVSFlags
Holds the flags to escape KVS.
Definition: KviQString.h:53
QString makeSizeReadable(quint64 bytes)
Returns a readable size in byte's multiples.
Definition: KviQString.cpp:225
#define kvi_va_list
Definition: kvi_stdarg.h:31
kvi_i64_t toI64(QString &szNumber, bool *bOk)
Return the string converted to a long.
Definition: KviQString.h:530
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:1172
bool equalCIN(const QString &sz1, const QString &sz2, unsigned int uLen)
Compares two strings with case insensitive up to N chars.
Definition: KviQString.cpp:86
void vsprintf(QString &szSrc, const QString &szFmt, kvi_va_list list)
Writes to the character string.
Definition: KviQString.cpp:634
QString lowerISO88591(const QString &szSrc)
Returns an ISO-8859-1 lower case string.
Definition: KviQString.cpp:1254
int cmpCIN(const QString &sz1, const QString &sz2, unsigned int uLen)
Compares two strings with case insensitive up to N chars.
Definition: KviQString.cpp:447
void stripRightWhiteSpace(QString &szSrc)
Trims all the whitespaces at the end of the given string.
Definition: KviQString.cpp:533
void transliterate(QString &szSrc, const QString &szToFind, const QString &szReplacement)
Replaces a string with another.
Definition: KviQString.cpp:1282
unsigned long long int kvi_u64_t
Definition: kvi_inttypes.h:66
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:1148
const QString Empty
A global empty string (note that this is ALSO NULL under Qt 3.x)
Definition: KviQString.cpp:49
void cutFromFirst(QString &szSrc, const QChar &c, bool bIncluded)
Cuts the string after the first occurrence of the given char.
Definition: KviQString.cpp:1114
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:1196
void stripLeft(QString &szSrc, const QChar &c)
Trims all c chars at the start of the given string.
Definition: KviQString.cpp:573
bool equalCSN(const QString &sz1, const QString &sz2, unsigned int uLen)
Compares two strings with case sensitive up to N chars.
Definition: KviQString.cpp:53
void bufferToHex(QString &szRetBuffer, const unsigned char *pcBuffer, unsigned int uLen)
Returns an hexadecimal converted string starting from a buffer.
Definition: KviQString.cpp:1302
Definition: KviQString.h:59
Definition: KviQString.h:55
QString getToken(QString &szSrc, const QChar &sep)
Returns a token from a string.
Definition: KviQString.cpp:493
int cmpCI(const QString &sz1, const QString &sz2, bool bNonAlphaGreater)
Compares two strings with case insensitive.
Definition: KviQString.cpp:385
QString toHtmlEscaped(QString szData)
Escapes any html special character from a string (wrapper to QString::toHtmlEscaped) ...
Definition: KviQString.cpp:1341
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:1212
long long int kvi_i64_t
SYSTEM_SIZE_OF_SHORT_INT.
Definition: kvi_inttypes.h:65
void cutFromLast(QString &szSrc, const QChar &c, bool bIncluded)
Cuts the string after the last occurrence of the given char.
Definition: KviQString.cpp:1131
bool equalCI(const QString &sz1, const QString &sz2)
Compares two strings with case insensitive.
Definition: KviQString.cpp:285
Definition: KviQString.h:57
This file contains compile time settings.
QString upperISO88591(const QString &szSrc)
Returns an ISO-8859-1 upper case string.
Definition: KviQString.cpp:1228
bool equalCS(const QString &sz1, const QString &sz2)
Compares two strings with case sensitive.
Definition: KviQString.cpp:257
void ensureLastCharIs(QString &szSrc, const QChar &c)
Ensures the last char of a string is the given char.
Definition: KviQString.cpp:485
#define KVILIB_API
Definition: kvi_settings.h:125