KVIrc  4.9.2
DeveloperAPIs
KviCString.h
Go to the documentation of this file.
1 #ifndef _KVI_STRING_H_
2 #define _KVI_STRING_H_
3 //=============================================================================
4 //
5 // File : KviCString.h
6 // Creation date : Fri Mar 19 1999 03:06:26 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 1999-2008 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 
27 #include "kvi_settings.h"
28 
29 #include <stdio.h>
30 #include <string.h>
31 #include <ctype.h>
32 
33 #ifdef HAVE_STRINGS_H
34 #include <strings.h> // useless ?
35 #endif
36 
37 #include <QtGlobal>
38 #include <QString>
39 #include <QByteArray>
40 
41 #include "kvi_inttypes.h"
42 #include "KviHeapObject.h"
43 #include "kvi_stdarg.h"
44 
45 //
46 // sigh...
47 // IRC is not UNICODE ...(yet) :(
48 //
49 
50 #undef __KVI_EXTERN
51 #ifdef _KVI_STRING_CPP_
52 #define __KVI_EXTERN
53 #else
54 #define __KVI_EXTERN extern
55 #endif
56 
57 __KVI_EXTERN KVILIB_API bool kvi_qstringEqualCI(const QString & s1, const QString & s2);
58 
59 // Include inlined assembly implementations if required
60 
61 // Returns true if the string str1 is equal to str2. case sensitive.
62 __KVI_EXTERN KVILIB_API bool kvi_strEqualCS(const char * str1, const char * str2);
63 // Returns true if the forst len characters of string str1 are equal to str2.
64 // case sensitive.
65 // Note that if str1 or str2 are shorter than len characters then are considered as NOT equal!
66 __KVI_EXTERN KVILIB_API bool kvi_strEqualCSN(const char * str1, const char * str2, int len);
67 // no such tricks in non-asm
68 #define kvi_strEqualNoLocaleCI(str1, str2) kvi_strEqualCI(str1, str2)
69 #define kvi_strEqualNoLocaleCIN(str1, str2, len) kvi_strEqualCIN(str1, str2, len)
70 #define kvi_strLen(str) strlen(str)
71 
72 // Returns true if the string str1 is equal to str2.
73 // case insensitive.
74 __KVI_EXTERN KVILIB_API bool kvi_strEqualCI(const char * str1, const char * str2);
75 // Returns true if the forst len characters of string str1 are equal to str2.
76 // case insensitive.
77 // Note that if str1 or str2 are shorter than len characters then are considered as NOT equal!
78 __KVI_EXTERN KVILIB_API bool kvi_strEqualCIN(const char * str1, const char * str2, int len);
79 // My own implementations of strcmp and strncasecmp
80 // Once I wrote it, I KNOW what they do : ALWAYS :)
81 // Note that greater here means that comes AFTER in the alphabetic order.
82 __KVI_EXTERN KVILIB_API int kvi_strcmpCI(const char * str1, const char * str2);
83 //__KVI_EXTERN KVILIB_API int kvi_strcmpCIN(const char *str1,const char *str2,int len);
84 __KVI_EXTERN KVILIB_API int kvi_strcmpCS(const char * str1, const char * str2);
85 
86 // some wide char stuff
87 typedef kvi_u16_t kvi_wchar_t;
88 typedef kvi_u32_t kvi_wslen_t;
89 
91 __KVI_EXTERN KVILIB_API int kvi_wvsnprintcf(kvi_wchar_t * buffer, kvi_wslen_t len, const char * fmt, kvi_va_list list);
93 
94 //=============================================================================
95 //
96 // A simple string class.<br>
97 // -No data sharing.<br>
98 // -Not UNICODE.<br>
99 // -Has ALWAYS NON-NULL DATA.<br>
100 // -(Maybe)Unsafe :)<br>
101 // WARNING : Handle with care and use at own risk :)<br>
102 //
103 //=============================================================================
104 
106 {
107 public:
108  // No particular reason for these two names...
109  // It is just because I like it :)
110 
112  {
114  Sprintf
115  };
116 
117  //=============================================================================
118  // Constructors
119  //=============================================================================
120 
121  // Empty string == "", len = 0, 1 byte allocated
122  KviCString();
123 
124  // Deep copy of the NULL TERMINATED string (NULL str SAFE)
125  KviCString(const char * str);
126 
127  // Copy len characters from string str (NOT NULL str SAFE, str MUST be at least len chars long)
128  KviCString(const char * str, int len);
129 
130  // bg and end are pointers to a SINGLE string.<br>
131  // A string is extracted starting from bg and ending at end (not included).<br>
132  KviCString(const char * bg, const char * end);
133 
134  // Format constructor.<br>
135  // tag is....yes....a dummy number used to resolve ambiguities.<br>
136  // It is SAFE: will fail only if we run out of memory,<br>
137  // but can handle only %s %d %u and %c.
138  KviCString(KviFormatConstructorTag tag, const char * fmt, ...);
139 
140  // Carbon copy :)...fast
141  KviCString(const KviCString & str);
142 
143  // Compat with QT...<br>
144  // WARNING : With QT2.x it WILL loose UNICODE data.<br>
145  // Safe even if the QString is null.
146  KviCString(const QString & str);
147 
148  KviCString(const QByteArray & str);
149 
150  // Fill sonstructor.
151  // Creates a string long fillLen characters filled with character c.<br>
152  KviCString(char c, int fillLen = 1);
153 
154  KviCString(const kvi_wchar_t * unicode);
155 
156  KviCString(const kvi_wchar_t * unicode, int len);
157 
158  // just free(m_ptr)
159  ~KviCString();
160 
161 public:
162  //yes...public..but think it as private...:)
163  char * m_ptr; // pointer to allocated buffer, do not change this!
164  int m_len; // string data length not including the terminator
165 
166 public:
167  //=============================================================================
168  // Basic const interface (read stuff)
169  //=============================================================================
170 
171  // Internal data buffer
172  char * ptr() const { return m_ptr; };
173  // Length: fast, cached
174  int len() const { return m_len; };
175 
176  // I hate this operator...but sometimes it is really useful
177  // especially in macros (KviOptions.cpp)
178  operator const char *() const { return m_ptr; };
179 
180  bool isEmpty() const { return (m_len == 0); };
181  bool hasData() const { return (m_len != 0); };
182 
183  // this is better than string = "", it does not call strlen
184  void clear();
185 
186  // Returns true if there is something "readable" inside the string
187  bool hasNonWhiteSpaceData() const;
188 
189  // Character at zero-based index : always safe!
190  char & at(int idx) const { return ((idx < m_len) ? m_ptr[idx] : m_ptr[m_len]); };
191 
192  // character checks
193  bool lastCharIs(char ch) const { return (m_len > 0) ? (*(m_ptr + m_len - 1) == ch) : false; };
194  bool firstCharIs(char ch) const { return (*m_ptr == ch); };
195 
196  // upper and lower case copies
197  KviCString upper() const;
198  KviCString lower() const;
199  KviCString upperISO88591() const;
200  KviCString lowerISO88591() const;
201 
202  // left, right & co.
203  // all parameters are safety-checked
204  KviCString left(int maxLen) const;
205  KviCString right(int maxLen) const;
206  KviCString middle(int idx, int maxLen) const;
207 
208  KviCString leftToFirst(char c, bool bIncluded = false) const;
209  KviCString leftToLast(char c, bool bIncluded = false) const;
210  // KviCString leftToFirst(const char * str); const;
211 
212  //=============================================================================
213  // Non-const interface (write stuff)
214  //=============================================================================
215 
216  // Null terminator is NOT included in len
217  KviCString & setLen(int len);
218 
219  // str must not be 0, but len can be anything (it is checked)
220  KviCString & setStr(const char * str, int len = -1);
221  // Like the special constructor that gets the same args.
222  void extractFromString(const char * begin, const char * end);
223 
224  // Safe sprintf. This one will never write past the end of the string
225  // It can handle only %s %d %u and %c format flags.
226  KviCString & sprintf(const char * fmt, ...);
227 
228  KviCString & vsprintf(const char * fmt, kvi_va_list list);
229 
230  // append functions
231  void append(const KviCString & str);
232  void append(const QString & str);
233  void append(char c);
234  void append(const char * str); // str CAN be 0
235  void append(const char * str, int len); // str CAN NOT be 0, and MUST be at least len chars long
236  void append(KviFormatConstructorTag dummy, const char * fmt, ...);
237 
238  // prepend stuff, same as above
239  void prepend(const KviCString & str);
240  void prepend(const char * str); // str CAN be 0
241  void prepend(const char * str, int len); // str CAN NOT be 0, and MUST be at least len chars long
242 
243  // if lastCharIs ch does nothing otherwise appends it
244  void ensureLastCharIs(char ch)
245  {
246  if(!lastCharIs(ch))
247  append(ch);
248  };
249 
250  // Change THIS string to uppercase or lowercase
251  void toUpperISO88591();
252  void toUpper(); // this is LOCALE AWARE (in Turkish it maps i to Ý!)
253  void toLowerISO88591();
254  void toLower();
255 
256  // Assignment
257  KviCString & operator=(const KviCString & str); // deep copy
258  KviCString & operator=(const char * str); // str can be NULL here
259  KviCString & operator=(char c); // 2 bytes allocated,m_len = 1
260  KviCString & operator=(const QString & str);
261  KviCString & operator=(const QByteArray & str);
262 
263  // Append operators
265  {
266  append(str);
267  return (*this);
268  };
269  KviCString & operator+=(const char * str)
270  {
271  append(str);
272  return (*this);
273  };
275  {
276  append(c);
277  return (*this);
278  };
279  KviCString & operator+=(const QString & str)
280  {
281  append(str);
282  return (*this);
283  };
284 
285  // Comparison
286  bool equalsCI(const KviCString & other) const
287  {
288  if(m_len != other.m_len)
289  return false;
290  return kvi_strEqualCI(m_ptr, other.m_ptr);
291  };
292  bool equalsCS(const KviCString & other) const
293  {
294  if(m_len != other.m_len)
295  return false;
296  return kvi_strEqualCS(m_ptr, other.m_ptr);
297  };
298  bool equalsCI(const char * other) const { return kvi_strEqualCI(m_ptr, other); };
299  bool equalsCS(const char * other) const { return kvi_strEqualCS(m_ptr, other); };
300  bool equalsCIN(const char * other, int len) const { return kvi_strEqualCIN(m_ptr, other, len); };
301  bool equalsCSN(const char * other, int len) const { return kvi_strEqualCSN(m_ptr, other, len); };
302 
303  //=============================================================================
304  // HEX and Base64 stuff
305  //=============================================================================
306 
307  // HEX transforms functions
308  void bufferToHex(const char * buffer, int len);
309  // Allocates the needed buffer and returns the allocated length,
310  // returns -1 in case of error (and allocates nothing)
311  // The string MUST contain only hex digits, and the digits MUST be in couples. (len % 2) must equal 0!
312  // So this will fail also if there are leading or trailing spaces!
313  int hexToBuffer(char ** buffer, bool bNullToNewlines = false);
314  // BASE64 stuff
315  void bufferToBase64(const char * buffer, int len);
316  // same as hexToBuffer but obviously transforms base64 notation to binary data (len % 4) must equal 0!
317  int base64ToBuffer(char ** buffer, bool bNullToNewlines = false);
318 
319  // frees a buffer allocated by hexToBuffer or base64ToBuffer
320  static void freeBuffer(char * buffer);
321 
322  //=============================================================================
323  // Splitters
324  //=============================================================================
325 
326  // cut
327  KviCString & cutLeft(int len); // kills the first len characters
328  KviCString & cutRight(int len); // kills the last len characters
329  KviCString & cut(int idx, int len);
330  KviCString & cutToFirst(char c, bool bIncluded = true); // cuts the left part of the string up to the first character c or does nothing if the char c is not in the string
331  KviCString & cutToLast(char c, bool bIncluded = true);
332  KviCString & cutFromFirst(char c, bool bIncluded = true);
333  KviCString & cutFromLast(char c, bool bIncluded = true);
334  KviCString & cutToFirst(const char * c, bool bIncluded = true); // cuts the left part of the string up to the first character c or does nothing if the char c is not in the string
335  KviCString & cutToLast(const char * c, bool bIncluded = true);
336  KviCString & cutFromFirst(const char * c, bool bIncluded = true);
337  KviCString & cutFromLast(const char * c, bool bIncluded = true);
338  // & paste
339  KviCString & insert(int idx, const char * data);
340  KviCString & insert(int idx, char c);
341  //Replaces all occurrences of char c with the string str
342  KviCString & replaceAll(const char c, const char * str);
343  //same as above but with a string
344  KviCString & replaceAll(const char * toFind, const char * str, bool bCaseS = true);
345 
346  KviCString & transliterate(const char * szToFind, const char * szReplacement);
347 
348  // Strips whitespace characters from beginning of this string.
349  KviCString & stripLeftWhiteSpace();
351  // Strips initial and final WHITESPACE characters (see man isspace),<br>
352  // and returns a reference to this string.
353  KviCString & trim();
354 
355  // Strips spaces and tabs only
356  KviCString & stripSpace();
357  // Strips all occurrences of the character c from the beginning of the string.<br>
358  // Note that c can not be '\0' :)
359  KviCString & stripLeft(char c);
360  KviCString & stripRight(char c);
361 
362  // either "truncate to" or "add padding up" to iLen characters.
363  KviCString & padRight(int iLen, const char c = '\0');
364  //=============================================================================
365  // Tokenize
366  //=============================================================================
367 
368  // Extracts (copy to str and remove) a token from this string,<br>
369  // and returns true if there are more tokens to extract<br>
370  // Does not strip initial separators!!<br>
371  // str can NOT be this string.
372  bool getToken(KviCString & str, char sep);
373  // Does not strip initial separators!<br>
374  // Can assign also to this string.
375  KviCString getToken(char sep);
376  // Extracts a line from the string.<br>
377  // Returns false if there was no data to extract
378  bool getLine(KviCString & str);
379 
380  // splits this string in a null-terminated array of strings
381  // separated by sep.
382  KviCString ** splitToArray(char sep, int max, int * realCount) const;
383  //KviCString ** splitToArray(const char * sep,int max,int * realCount) const;
384  static void freeArray(KviCString ** strings);
385  // joins the array to this string
386  // if sep is not 0, it is inserted between the strings
387  // if bLastSep is true and sep is non 0, then sep is also appended at the end
388  // of the buffer (after the last string)
389  void joinFromArray(KviCString ** strings, const char * sep = 0, bool bLastSep = false);
390 
391  //=============================================================================
392  // Utils
393  //=============================================================================
394 
395  // encodes chars that have nonzero in the jumptable
396  // into %HH equivalents
397  KviCString & hexEncodeWithTable(const unsigned char table[256]);
398  KviCString & hexEncodeWhiteSpace();
399  KviCString & hexDecode(const char * pFrom);
400  KviCString & hexDecode() { return hexDecode(m_ptr); };
401 
402  //=============================================================================
403  // Contains / occurrence count
404  //=============================================================================
405 
406  // Returns true if at least one occurrence of str is found
407  bool contains(const char * str, bool caseS = true) const;
408  // Returns true if at least one occurrence of character c is found in this string
409  bool contains(char c, bool caseS = true) const;
410  // Returns the number of occurrences of string str in this string.<br>
411  // Overlapped matches are counted.
412  int occurrences(const char * str, bool caseS = true) const;
413  // Returns the number of occurrences of character c in this string
414  int occurrences(char c, bool caseS = true) const;
415 
416  //=============================================================================
417  // Find
418  //=============================================================================
419 
420  // Finds the first occurrence of the character c in this string,<br>
421  // and returns its zero-based index or -1 if c can not be found.<br>
422  // c can NOT be '\0' here.
423  int findFirstIdx(char c) const;
424  // Finds the first occurrence of the sub-string str in this string,<br>
425  // and returns its zero-based index or -1 if the sub-string can not be found.<br>
426  // str can NOT be 0 here.
427  int findFirstIdx(const char * str, bool caseS = true) const;
428  // Finds the last occurrence of the character c in this string,<br>
429  // and returns its zero-based index or -1 if the character can not be found.
430  int findLastIdx(char c) const;
431  // Finds the last occurrence of the sub-string str in this string,<br>
432  // and returns its zero-based index or -1 if the sub-string can not be found.<br>
433  // str can NOT be 0 here.
434  int findLastIdx(const char * str, bool caseS = true) const;
435 
436  int find(char c, int startIdx) const;
437  int find(const char * str, int startIdx, bool caseS = true) const;
438  int findRev(const char * str, int startIdx, bool caseS = true) const;
439 
440  //=============================================================================
441  // Numbers
442  //=============================================================================
443 
444  // everything in base 10.... no overflow checks here
445  long toLong(bool * bOk = 0) const;
446  unsigned long toULong(bool * bOk = 0) const;
447  long long toLongLong(bool * bOk = 0) const;
448  unsigned long long toULongLong(bool * bOk = 0) const;
449  char toChar(bool * bOk = 0) const { return (char)toLong(bOk); };
450  unsigned char toUChar(bool * bOk = 0) const { return (unsigned char)toULong(bOk); };
451  int toInt(bool * bOk = 0) const { return (int)toLong(bOk); };
452  unsigned int toUInt(bool * bOk = 0) const { return (unsigned int)toULong(bOk); };
453  short toShort(bool * bOk = 0) const { return (short)toLong(bOk); };
454  unsigned short toUShort(bool * bOk = 0) const { return (unsigned short)toLong(bOk); };
455 
456  KviCString & setNum(long num);
457  KviCString & setNum(unsigned long num);
458 
459  KviCString & setNum(int num) { return setNum((long)num); };
460  KviCString & setNum(unsigned int num) { return setNum((unsigned long)num); };
461  KviCString & setNum(short num) { return setNum((long)num); };
462  KviCString & setNum(unsigned short num) { return setNum((unsigned long)num); };
463  KviCString & setNum(char num) { return setNum((long)num); };
464  KviCString & setNum(unsigned char num) { return setNum((unsigned long)num); };
465 
466  // Returns true if the string contains only digits and an optional '-' character
467  // at the beginning.<be>
468  // Space characters are allowed at the begginning and the end.<br>
469  // There is no overflow check!
470  bool isNum() const;
471  bool isUnsignedNum() const;
472 
473  // special functions for multiple bases
474  long toLongExt(bool * bOk = 0, int base = 0);
475  // unsigned long toULongExt(bool *bOk = 0,int base = 0); //never used
476 
477  // returns an empty string...
478  // this if often useful!
479  static KviCString & emptyString();
480 
481  //=============================================================================
482  // Dead interface
483  //=============================================================================
484 
485  // Transform a pointer to a string with all 0 and 1
486  // void pointerToBitString(const void * ptr);
487  // Get a pointer from a string all of 0 and 1 : return 0 if invalid
488  // void * bitStringToPointer();
489 
490  //=============================================================================
491  // "External string" helper functions
492  //=============================================================================
493 
494  // FIXME: Should it be KviCStringExt::contains namespace ?
495  static bool ext_contains(const char * data, const char * item, bool caseS = true);
496 };
497 
498 // FIXME: the functions below should end in the KviCString namespace ???
499 
500 // Cool string parsing function.
501 // It will extract the first found token from the string aux_ptr, and return
502 // a pointer to the beginning of the next token, or end of the string.
503 // It skips the initial sep characters!
504 __KVI_EXTERN KVILIB_API const char * kvi_extractToken(KviCString & str, const char * aux_ptr, char sep = ' ');
505 // Does not skip the beginning separators!
506 // Extracts data from the string up to the next separator character or the end of the string.
507 // and returns a pointer to that separator (or string end).
508 __KVI_EXTERN KVILIB_API const char * kvi_extractUpTo(KviCString & str, const char * aux_ptr, char sep = ' ');
509 // Reduced vsnprintf...
510 // Handles %s,%c,%d,%u (%% are TWO percents here and not one.)
511 // Returns -1 if the formatted string exceeded the buffer length.
512 // Otherwise returns the length of the formatted buffer...(not including '\0')
513 __KVI_EXTERN KVILIB_API int kvi_vsnprintf(char * buffer, int len, const char * fmt, kvi_va_list list);
514 // Reduced vsnprintf: special version for irc.
515 // Handles %s,%c,%d,%u (%% are TWO percents here and not one.)
516 // Writes up to 510 characters and terminates the string with a CRLF
517 // Sets bTruncated if the requested format string was too large to fit in 512 bytes
518 // otherwise sets it to false; The buffer MUST be at least 512 bytes long.
519 // Always returns the length of the formatted buffer...(max 512 - min 2=CRLF)
520 __KVI_EXTERN KVILIB_API int kvi_irc_vsnprintf(char * buffer, const char * fmt, kvi_va_list list, bool * bTruncated);
521 
522 // WILDCARD EXPRESSION MATCHING FUNCTIONS
523 
524 // Returns true if the two regular expressions with wildcards matches
525 __KVI_EXTERN KVILIB_API bool kvi_matchWildExpr(register const char * m1, register const char * m2);
526 // Returns true if the two regular expressions with wildcards matches, case sensitive
527 //__KVI_EXTERN bool kvi_matchWildExprCS(register const char *m1,register const char *m2); // actually unused
528 // Same as kvi_matchWildExpr but with an additional char that acts as string terminator
529 // If there is a match this function returns true and puts the pointers where it stopped in r1 and r2
530 __KVI_EXTERN KVILIB_API bool kvi_matchWildExprWithTerminator(register const char * m1, register const char * m2, char terminator,
531  const char ** r1, const char ** r2);
532 
533 // Returns true if the wildcard expression exp matches the string str
534 __KVI_EXTERN KVILIB_API bool kvi_matchStringCI(register const char * exp, register const char * str);
535 #define kvi_matchString kvi_matchStringCI
536 __KVI_EXTERN KVILIB_API bool kvi_matchStringCS(register const char * exp, register const char * str);
537 __KVI_EXTERN KVILIB_API bool kvi_matchStringWithTerminator(register const char * exp, register const char * str, char terminator, const char ** r1, const char ** r2);
538 
539 // This function works like a particular case of strncmp.
540 // It evaluates if str2 is the terminal part of str1.
541 // example: if str1 is "this is an experiment" and str2 is "xperiment"
542 // return 0.
543 // With the index parameter, the match start on str1 from the specified
544 // index. For example:
545 // if str1 is "this is an experiment" and str2 is "an" we have return !0
546 // but "this is an experiment"
547 // 012345678901234567890
548 // if we call kvi_strsubRevCS("this is an experiment","an", 9) we got a match.
549 __KVI_EXTERN KVILIB_API int kvi_strMatchRevCS(const char * str1, const char * str2, int index = -1);
550 
551 // KviCString comparison non-member operators
552 __KVI_EXTERN inline bool operator==(const KviCString & left, const KviCString & right)
553 {
554  return (left.m_len == right.m_len) ? kvi_strEqualCS(left.m_ptr, right.m_ptr) : false;
555 }
556 __KVI_EXTERN inline bool operator==(const KviCString & left, const char * right)
557 {
558  return kvi_strEqualCS(left.m_ptr, right);
559 }
560 __KVI_EXTERN inline bool operator==(const char * left, const KviCString & right)
561 {
562  return kvi_strEqualCS(left, right.m_ptr);
563 }
564 __KVI_EXTERN inline bool operator!=(const KviCString & left, const KviCString & right)
565 {
566  return !kvi_strEqualCS(left.m_ptr, right.m_ptr);
567 }
568 __KVI_EXTERN inline bool operator!=(const KviCString & left, const char * right)
569 {
570  return !kvi_strEqualCS(left.m_ptr, right);
571 }
572 __KVI_EXTERN inline bool operator!=(const char * left, const KviCString & right)
573 {
574  return !kvi_strEqualCS(left, right.m_ptr);
575 }
576 
577 __KVI_EXTERN inline KviCString operator+(const KviCString & left, const KviCString & right)
578 {
579  KviCString ret(left);
580  ret += right;
581  return ret;
582 }
583 __KVI_EXTERN inline KviCString operator+(const KviCString & left, const char * right)
584 {
585  KviCString ret(left);
586  ret += right;
587  return ret;
588 }
589 __KVI_EXTERN inline KviCString operator+(const char * left, const KviCString & right)
590 {
591  KviCString ret(left);
592  ret += right;
593  return ret;
594 }
595 __KVI_EXTERN inline KviCString operator+(const KviCString & left, char right)
596 {
597  KviCString ret(left);
598  ret += right;
599  return ret;
600 }
601 __KVI_EXTERN inline KviCString operator+(char left, const KviCString & right)
602 {
603  KviCString ret(left);
604  ret += right;
605  return ret;
606 }
607 
608 inline int kvi_compare(const KviCString * p1, const KviCString * p2)
609 {
610  return kvi_strcmpCI(p1->ptr(), p2->ptr());
611 }
612 
613 #endif //_KVI_STRING_H_
__KVI_EXTERN KVILIB_API int kvi_strMatchRevCS(const char *str1, const char *str2, int index=-1)
Definition: KviCString.cpp:932
__KVI_EXTERN bool operator==(const KviCString &left, const KviCString &right)
Definition: KviCString.h:552
__KVI_EXTERN KVILIB_API bool kvi_matchWildExpr(register const char *m1, register const char *m2)
Definition: KviHeapObject.h:124
__KVI_EXTERN KVILIB_API int kvi_strcmpCI(const char *str1, const char *str2)
Definition: KviCString.cpp:891
Definition: KviCString.h:105
int toInt(bool *bOk=0) const
Definition: KviCString.h:451
KviCString & setNum(char num)
Definition: KviCString.h:463
int m_len
Definition: KviCString.h:164
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
void ensureLastCharIs(char ch)
Definition: KviCString.h:244
__KVI_EXTERN KVILIB_API bool kvi_qstringEqualCI(const QString &s1, const QString &s2)
Definition: KviCString.cpp:42
__KVI_EXTERN KVILIB_API int kvi_vsnprintf(char *buffer, int len, const char *fmt, kvi_va_list list)
Definition: KviCString.cpp:535
__KVI_EXTERN KVILIB_API bool kvi_strEqualCI(const char *str1, const char *str2)
Definition: KviCString.cpp:873
unsigned int toUInt(bool *bOk=0) const
Definition: KviCString.h:452
__KVI_EXTERN KVILIB_API bool kvi_matchStringWithTerminator(register const char *exp, register const char *str, char terminator, const char **r1, const char **r2)
__KVI_EXTERN KVILIB_API bool kvi_strEqualCIN(const char *str1, const char *str2, int len)
Definition: KviCString.cpp:858
int kvi_compare(const KviCString *p1, const KviCString *p2)
Definition: KviCString.h:608
KviCString & setNum(unsigned char num)
Definition: KviCString.h:464
char & at(int idx) const
Definition: KviCString.h:190
bool firstCharIs(char ch) const
Definition: KviCString.h:194
__KVI_EXTERN KVILIB_API kvi_wslen_t kvi_wstrlen(const kvi_wchar_t *str)
Definition: KviCString.cpp:34
void stripRight(QString &szSrc, const QChar &c)
Trims all c chars at the end of the given string.
Definition: KviQString.cpp:553
bool equalsCSN(const char *other, int len) const
Definition: KviCString.h:301
KviFormatConstructorTag
Definition: KviCString.h:111
__KVI_EXTERN KVILIB_API int kvi_wvsnprintcf(kvi_wchar_t *buffer, kvi_wslen_t len, const char *fmt, kvi_va_list list)
kvi_u16_t kvi_wchar_t
Definition: KviCString.h:87
#define kvi_va_list
Definition: kvi_stdarg.h:31
bool isEmpty() const
Definition: KviCString.h:180
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
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
bool hasData() const
Definition: KviCString.h:181
bool equalsCS(const KviCString &other) const
Definition: KviCString.h:292
btnDict clear()
void stripRightWhiteSpace(QString &szSrc)
Trims all the whitespaces at the end of the given string.
Definition: KviQString.cpp:533
short toShort(bool *bOk=0) const
Definition: KviCString.h:453
__KVI_EXTERN KVILIB_API bool kvi_strEqualCS(const char *str1, const char *str2)
Definition: KviCString.cpp:827
void transliterate(QString &szSrc, const QString &szToFind, const QString &szReplacement)
Replaces a string with another.
Definition: KviQString.cpp:1282
KviCString & operator+=(char c)
Definition: KviCString.h:274
unsigned char toUChar(bool *bOk=0) const
Definition: KviCString.h:450
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
unsigned short toUShort(bool *bOk=0) const
Definition: KviCString.h:454
void cutFromFirst(QString &szSrc, const QChar &c, bool bIncluded)
Cuts the string after the first occurrence of the given char.
Definition: KviQString.cpp:1114
__KVI_EXTERN bool operator!=(const KviCString &left, const KviCString &right)
Definition: KviCString.h:564
#define __KVI_EXTERN
Definition: KviCString.h:54
KviCString & setNum(unsigned int num)
Definition: KviCString.h:460
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
KviCString & setNum(int num)
Definition: KviCString.h:459
bool equalsCI(const char *other) const
Definition: KviCString.h:298
void stripLeft(QString &szSrc, const QChar &c)
Trims all c chars at the start of the given string.
Definition: KviQString.cpp:573
KviCString & operator+=(const char *str)
Definition: KviCString.h:269
__KVI_EXTERN KVILIB_API const char * kvi_extractUpTo(KviCString &str, const char *aux_ptr, char sep= ' ')
Definition: KviCString.cpp:522
__KVI_EXTERN KviCString operator+(const KviCString &left, const KviCString &right)
Definition: KviCString.h:577
__KVI_EXTERN KVILIB_API int kvi_strcmpCS(const char *str1, const char *str2)
Definition: KviCString.cpp:916
__KVI_EXTERN KVILIB_API bool kvi_matchStringCI(register const char *exp, register const char *str)
kvi_u32_t kvi_wslen_t
Definition: KviCString.h:88
void bufferToHex(QString &szRetBuffer, const unsigned char *pcBuffer, unsigned int uLen)
Returns an hexadecimal converted string starting from a buffer.
Definition: KviQString.cpp:1302
int len() const
Definition: KviCString.h:174
QString getToken(QString &szSrc, const QChar &sep)
Returns a token from a string.
Definition: KviQString.cpp:493
__KVI_EXTERN KVILIB_API bool kvi_matchStringCS(register const char *exp, register const char *str)
Heap Object.
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
bool equalsCS(const char *other) const
Definition: KviCString.h:299
__KVI_EXTERN KVILIB_API bool kvi_matchWildExprWithTerminator(register const char *m1, register const char *m2, char terminator, const char **r1, const char **r2)
void cutFromLast(QString &szSrc, const QChar &c, bool bIncluded)
Cuts the string after the last occurrence of the given char.
Definition: KviQString.cpp:1131
KviCString & operator+=(const KviCString &str)
Definition: KviCString.h:264
KviCString & setNum(short num)
Definition: KviCString.h:461
Definition: KviCString.h:113
KviCString & setNum(unsigned short num)
Definition: KviCString.h:462
bool equalsCIN(const char *other, int len) const
Definition: KviCString.h:300
bool lastCharIs(char ch) const
Definition: KviCString.h:193
bool equalsCI(const KviCString &other) const
Definition: KviCString.h:286
KviCString & operator+=(const QString &str)
Definition: KviCString.h:279
__KVI_EXTERN KVILIB_API const char * kvi_extractToken(KviCString &str, const char *aux_ptr, char sep= ' ')
Definition: KviCString.cpp:505
__KVI_EXTERN KVILIB_API bool kvi_strEqualCSN(const char *str1, const char *str2, int len)
Definition: KviCString.cpp:841
This file contains compile time settings.
KviCString & hexDecode()
Definition: KviCString.h:400
char * m_ptr
Definition: KviCString.h:163
QString upperISO88591(const QString &szSrc)
Returns an ISO-8859-1 upper case string.
Definition: KviQString.cpp:1228
char * ptr() const
Definition: KviCString.h:172
__KVI_EXTERN KVILIB_API int kvi_irc_vsnprintf(char *buffer, const char *fmt, kvi_va_list list, bool *bTruncated)
Definition: KviCString.cpp:694
char toChar(bool *bOk=0) const
Definition: KviCString.h:449
#define KVILIB_API
Definition: kvi_settings.h:125
__KVI_EXTERN KVILIB_API int kvi_wvsnprintf(kvi_wchar_t *buffer, kvi_wslen_t len, const kvi_wchar_t *fmt, kvi_va_list list)