~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/kvilib/core/kvi_qstring.h

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef _KVI_QSTRING_H_
2
 
#define _KVI_QSTRING_H_
3
 
//=============================================================================
4
 
//
5
 
//   File : kvi_qstring.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-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 opinion) 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
 
/**
28
 
* \file kvi_qstring.h
29
 
* \author Szymon Stefanek
30
 
* \brief Helper functions for the QString class
31
 
*/
32
 
 
33
 
#include "kvi_settings.h"
34
 
#include "kvi_inttypes.h"
35
 
#include "kvi_stdarg.h"
36
 
 
37
 
#include <QString>
38
 
#include <QByteArray>
39
 
 
40
 
/**
41
 
* \namespace KviQString
42
 
* \brief A namespace for QString helper functions
43
 
*
44
 
* This namespace contains several helper functions that are used when dealing
45
 
* with QString.
46
 
*/
47
 
namespace KviQString
48
 
{
49
 
        /**
50
 
        * \brief A global empty string (note that this is ALSO NULL under Qt 3.x)
51
 
        */
52
 
        extern KVILIB_API const QString Empty;
53
 
        
54
 
        /**
55
 
        * \brief Returns a readable size in byte's multiples
56
 
        *
57
 
        * This will return strings like KiB, MiB, GiB, TiB and so on
58
 
        * \param size The size of the file
59
 
        * \return QString
60
 
        */
61
 
        extern KVILIB_API QString makeSizeReadable(quint64 size);
62
 
        
63
 
        /**
64
 
        * \brief Compares two strings with case sensitive
65
 
        *
66
 
        * It returns true if the strings are equal, false otherwise
67
 
        * \param sz1 First string
68
 
        * \param sz2 Second string
69
 
        * \return bool
70
 
        */
71
 
        extern KVILIB_API bool equalCS(const QString & sz1, const QString & sz2);
72
 
        
73
 
        /**
74
 
        * \brief Compares two strings with case sensitive
75
 
        *
76
 
        * It returns true if the strings are equal, false otherwise
77
 
        * \param sz1 First string
78
 
        * \param pc2 Second string
79
 
        * \return bool
80
 
        */
81
 
        extern KVILIB_API bool equalCS(const QString & sz1, const char * pc2);
82
 
        
83
 
        /**
84
 
        * \brief Compares two strings with case sensitive
85
 
        *
86
 
        * It returns true if the strings are equal, false otherwise
87
 
        * \param pc1 First string
88
 
        * \param sz2 Second string
89
 
        * \return bool
90
 
        */
91
 
        inline bool equalCS(const char * pc1, const QString & sz2)
92
 
                { return equalCS(sz2,pc1); }
93
 
        
94
 
        /**
95
 
        * \brief Compares two strings with case insensitive
96
 
        *
97
 
        * It returns true if the strings are equal, false otherwise
98
 
        * \param sz1 First string
99
 
        * \param sz2 Second string
100
 
        * \return bool
101
 
        */
102
 
        extern KVILIB_API bool equalCI(const QString & sz1, const QString & sz2);
103
 
        
104
 
        /**
105
 
        * \brief Compares two strings with case insensitive
106
 
        *
107
 
        * It returns true if the strings are equal, false otherwise
108
 
        * \param sz1 First string
109
 
        * \param pc2 Second string
110
 
        * \return bool
111
 
        */
112
 
        extern KVILIB_API bool equalCI(const QString & sz1, const char * pc2);
113
 
        
114
 
        /**
115
 
        * \brief Compares two strings with case insensitive
116
 
        *
117
 
        * It returns true if the strings are equal, false otherwise.
118
 
        * The parameter pC2 is assumed to be null terminated here!
119
 
        * \param sz1 First string
120
 
        * \param pC2 Second string
121
 
        * \return bool
122
 
        */
123
 
        extern KVILIB_API bool equalCI(const QString & sz1, const QChar * pC2);
124
 
        
125
 
        /**
126
 
        * \brief Compares two strings with case insensitive
127
 
        *
128
 
        * It returns true if the strings are equal, false otherwise.
129
 
        * \param pc1 First string
130
 
        * \param sz2 Second string
131
 
        * \return bool
132
 
        */
133
 
        inline bool equalCI(const char * pc1, const QString & sz2)
134
 
                { return equalCI(sz2,pc1); }
135
 
        
136
 
        /**
137
 
        * \brief Compares two strings with case insensitive
138
 
        *
139
 
        * It returns true if the strings are equal, false otherwise.
140
 
        * The parameter pC1 is assumed to be null terminated here!
141
 
        * \param pC1 First string
142
 
        * \param sz2 Second string
143
 
        * \return bool
144
 
        */
145
 
        inline bool equalCI(const QChar * pC1, const QString & sz2)
146
 
                { return equalCI(sz2,pC1); }
147
 
        
148
 
        /**
149
 
        * \brief Compares two strings with case sensitive up to N chars
150
 
        *
151
 
        * It returns true if the strings are equal, false otherwise
152
 
        * \param sz1 First string
153
 
        * \param sz2 Second string
154
 
        * \param uLen The length of the string to check
155
 
        * \return bool
156
 
        */
157
 
        extern KVILIB_API bool equalCSN(const QString & sz1, const QString & sz2, unsigned int uLen);
158
 
        
159
 
        /**
160
 
        * \brief Compares two strings with case sensitive up to N chars
161
 
        *
162
 
        * It returns true if the strings are equal, false otherwise
163
 
        * \param sz1 First string
164
 
        * \param pc2 Second string
165
 
        * \param uLen The length of the string to check
166
 
        * \return bool
167
 
        */
168
 
        extern KVILIB_API bool equalCSN(const QString & sz1, const char * pc2, unsigned int uLen);
169
 
        
170
 
        /**
171
 
        * \brief Compares two strings with case sensitive up to N chars
172
 
        *
173
 
        * It returns true if the strings are equal, false otherwise
174
 
        * \param pc1 First string
175
 
        * \param sz2 Second string
176
 
        * \param uLen The length of the string to check
177
 
        * \return bool
178
 
        */
179
 
        inline bool equalCSN(const char * pc1, const QString & sz2, unsigned int uLen)
180
 
                { return equalCSN(sz2,pc1,uLen); }
181
 
        
182
 
        /**
183
 
        * \brief Compares two strings with case insensitive up to N chars
184
 
        *
185
 
        * It returns true if the strings are equal, false otherwise
186
 
        * \param sz1 First string
187
 
        * \param sz2 Second string
188
 
        * \param uLen The length of the string to check
189
 
        * \return bool
190
 
        */
191
 
        extern KVILIB_API bool equalCIN(const QString & sz1, const QString & sz2, unsigned int uLen);
192
 
        
193
 
        /**
194
 
        * \brief Compares two strings with case insensitive up to N chars
195
 
        *
196
 
        * It returns true if the strings are equal, false otherwise
197
 
        * \param sz1 First string
198
 
        * \param pc2 Second string
199
 
        * \param uLen The length of the string to check
200
 
        * \return bool
201
 
        */
202
 
        extern KVILIB_API bool equalCIN(const QString & sz1, const char * pc2, unsigned int uLen);
203
 
        
204
 
        /**
205
 
        * \brief Compares two strings with case insensitive up to N chars
206
 
        *
207
 
        * It returns true if the strings are equal, false otherwise
208
 
        * pC2 is assumed to be null terminated here!
209
 
        * \param sz1 First string
210
 
        * \param pC2 Second string
211
 
        * \param uLen The length of the string to check
212
 
        * \return bool
213
 
        */
214
 
        extern KVILIB_API bool equalCIN(const QString & sz1, const QChar * pC2, unsigned int uLen);
215
 
        
216
 
        /**
217
 
        * \brief Compares two strings with case insensitive up to N chars
218
 
        *
219
 
        * It returns true if the strings are equal, false otherwise
220
 
        * \param pc1 First string
221
 
        * \param sz2 Second string
222
 
        * \param uLen The length of the string to check
223
 
        * \return bool
224
 
        */
225
 
        inline bool equalCIN(const char * pc1, const QString & sz2, unsigned int uLen)
226
 
                { return equalCIN(sz2,pc1,uLen); }
227
 
        
228
 
        /**
229
 
        * \brief Compares two strings with case insensitive up to N chars
230
 
        *
231
 
        * It returns true if the strings are equal, false otherwise
232
 
        * pC1 is assumed to be null terminated here!
233
 
        * \param pC1 First string
234
 
        * \param sz2 Second string
235
 
        * \param uLen The length of the string to check
236
 
        * \return bool
237
 
        */
238
 
        inline bool equalCIN(const QChar * pC1, const QString & sz2, unsigned int uLen)
239
 
                { return equalCIN(sz2,pC1,uLen); }
240
 
 
241
 
        /**
242
 
        * \brief Compares two strings with case insensitive
243
 
        *
244
 
        * Note that greater here means that come AFTER in the alphabetic order
245
 
        * return < 0 ---> str1 < str2
246
 
        * return = 0 ---> str1 = str2
247
 
        * return > 0 ---> str1 > str2
248
 
        * \param sz1 The first string
249
 
        * \param sz2 The second string
250
 
        * \param bNonAlphaGreater Wheter to check if strings are not alphabetics
251
 
        * \return int
252
 
        */
253
 
        extern KVILIB_API int cmpCI(const QString & sz1, const QString & sz2, bool bNonAlphaGreater = false);
254
 
        
255
 
        /**
256
 
        * \brief Compares two strings with case insensitive up to N chars
257
 
        *
258
 
        * Note that greater here means that come AFTER in the alphabetic order
259
 
        * return < 0 ---> str1 < str2
260
 
        * return = 0 ---> str1 = str2
261
 
        * return > 0 ---> str1 > str2
262
 
        * \param sz1 The first string
263
 
        * \param sz2 The second string
264
 
        * \param uLen The number of chars to check
265
 
        * \return int
266
 
        */
267
 
        extern KVILIB_API int cmpCIN(const QString & sz1, const QString & sz2, unsigned int uLen);
268
 
        
269
 
        /**
270
 
        * \brief Compares two strings with case sensitive
271
 
        *
272
 
        * Note that greater here means that come AFTER in the alphabetic order
273
 
        * return < 0 ---> str1 < str2
274
 
        * return = 0 ---> str1 = str2
275
 
        * return > 0 ---> str1 > str2
276
 
        * \param sz1 The first string
277
 
        * \param sz2 The second string
278
 
        * \return int
279
 
        */
280
 
        extern KVILIB_API int cmpCS(const QString & sz1, const QString & sz2);
281
 
 
282
 
        /**
283
 
        * \brief Resets the size of the string
284
 
        * \param szSrc The source string
285
 
        * \return void
286
 
        */
287
 
        extern KVILIB_API void detach(QString & szSrc);
288
 
 
289
 
        /**
290
 
        * \brief Returns a pointer to the data stored in the string.
291
 
        *
292
 
        * This makes the string szSrc appear as a null terminated array.
293
 
        * It MAY RETURN 0 when the string is null!
294
 
        * \param szSrc The source string
295
 
        * \return QChar *
296
 
        */
297
 
        extern KVILIB_API const QChar * nullTerminatedArray(const QString & szSrc);
298
 
 
299
 
        /**
300
 
        * \brief Returns true if the string ends with the given character
301
 
        * \param szSrc The source string
302
 
        * \param c The char to check
303
 
        * \return bool
304
 
        */
305
 
        inline bool lastCharIs(QString & szSrc, const QChar & c)
306
 
                { return szSrc.endsWith(c); }
307
 
 
308
 
        /**
309
 
        * \brief Ensures the last char of a string is the given char
310
 
        *
311
 
        * If the string does not end with the given char, it appends it
312
 
        * \param szSrc The source string
313
 
        * \param c The char to check
314
 
        * \return void
315
 
        */
316
 
        extern KVILIB_API void ensureLastCharIs(QString & szSrc, const QChar & c);
317
 
 
318
 
        /**
319
 
        * \brief Matches two strings containging wildcards (* and ?)
320
 
        * \param szM1 The first string to match
321
 
        * \param szM2 The second string to match
322
 
        * \return bool
323
 
        */
324
 
        extern KVILIB_API bool matchWildExpressions(const QString & szM1, const QString & szM2);
325
 
        
326
 
        /**
327
 
        * \brief Matches two string containging wildcards (* and ?) or regular expressions
328
 
        * \param szExp The regular expression to match
329
 
        * \param szStr The source string
330
 
        * \param bIsRegExp Wheter to use a wildcard or regexp matching
331
 
        * \param bExact Wheter to match the whole string
332
 
        * \param bCs Wheter to match with case sensitive
333
 
        * \return bool
334
 
        */
335
 
        extern KVILIB_API bool matchString(const QString & szExp, const QString & szStr, bool bIsRegExp = false, bool bExact = false, bool bCs = false);
336
 
 
337
 
        /**
338
 
        * \brief Writes to the character string
339
 
        * \param szSrc The source string
340
 
        * \param szFmt The format string
341
 
        * \param list The list of format parameters
342
 
        * \return void
343
 
        */
344
 
        extern KVILIB_API void vsprintf(QString & szSrc, const QString & szFmt, kvi_va_list list);
345
 
        
346
 
        /**
347
 
        * \brief Writes to the character string
348
 
        * \param szSrc The source string
349
 
        * \param szFmt The format string
350
 
        * \param ... The list of format parameters
351
 
        * \return QString
352
 
        */
353
 
        extern KVILIB_API QString & sprintf(QString & szSrc, const QString & szFmt, ...);
354
 
        
355
 
        /**
356
 
        * \brief Trims all the whitespaces at the end of the given string
357
 
        * \param szSrc The source string
358
 
        * \return void
359
 
        */
360
 
        extern KVILIB_API void stripRightWhiteSpace(QString & szSrc);
361
 
        
362
 
        /**
363
 
        * \brief Trims all c chars at the start of the given string
364
 
        * \param szSrc The source string
365
 
        * \param c The char to trim
366
 
        * \return void
367
 
        */
368
 
        extern KVILIB_API void stripLeft(QString & szSrc, const QChar & c);
369
 
        
370
 
        /**
371
 
        * \brief Trims all c chars at the end of the given string
372
 
        * \param szSrc The source string
373
 
        * \param c The char to trim
374
 
        * \return void
375
 
        */
376
 
        extern KVILIB_API void stripRight(QString & szSrc, const QChar & c);
377
 
        
378
 
        /**
379
 
        * \brief Appends a formatted string
380
 
        * \param szSrc The source string
381
 
        * \param szFmt The format string
382
 
        * \param ... Format string parameters
383
 
        * \return void
384
 
        */
385
 
        extern KVILIB_API void appendFormatted(QString & szSrc, const QString & szFmt, ...);
386
 
        
387
 
        /**
388
 
        * \brief Appends the given number to the source string
389
 
        * \param szSrc The source string
390
 
        * \param dReal Number in double format
391
 
        * \return void
392
 
        */
393
 
        extern KVILIB_API void appendNumber(QString & szSrc, double dReal);
394
 
        
395
 
        /**
396
 
        * \brief Appends the given number to the source string
397
 
        * \param szSrc The source string
398
 
        * \param iInteger Number in kvi_i64_t format
399
 
        * \return void
400
 
        */
401
 
        extern KVILIB_API void appendNumber(QString & szSrc, kvi_i64_t iInteger);
402
 
        
403
 
        /**
404
 
        * \brief Appends the given number to the source string
405
 
        * \param szSrc The source string
406
 
        * \param iInteger Number in int format
407
 
        * \return void
408
 
        */
409
 
        extern KVILIB_API void appendNumber(QString & szSrc, int iInteger);
410
 
        
411
 
        /**
412
 
        * \brief Appends the given number to the source string
413
 
        * \param szSrc The source string
414
 
        * \param uInteger Number in unsigned int format
415
 
        * \return void
416
 
        */
417
 
        extern KVILIB_API void appendNumber(QString & szSrc, unsigned int uInteger);
418
 
        
419
 
        /**
420
 
        * \brief Appends the given number to the source string
421
 
        * \param szSrc The source string
422
 
        * \param uInteger Number in kvi_i64_t format
423
 
        * \return void
424
 
        */
425
 
        extern KVILIB_API void appendNumber(QString & szSrc, kvi_u64_t uInteger);
426
 
 
427
 
        /**
428
 
        * \brief Cuts the string after the first occurrence of the given char
429
 
        *
430
 
        * If the char is not found, the string is returned as it is.
431
 
        * \param szSrc The source string
432
 
        * \param c The char to search for
433
 
        * \param bIncluded Wheter to include the given char
434
 
        * \return void
435
 
        */
436
 
        extern KVILIB_API void cutFromFirst(QString & szSrc, const QChar & c, bool bIncluded = true);
437
 
        
438
 
        /**
439
 
        * \brief Cuts the string after the first occurrence of the given char
440
 
        *
441
 
        * If the char is not found, the string is returned as it is.
442
 
        * \param szSrc The source string
443
 
        * \param szFind The string to search for
444
 
        * \param bIncluded Wheter to include the given string
445
 
        * \return void
446
 
        */
447
 
        extern KVILIB_API void cutFromFirst(QString & szSrc, const QString & szFind, bool bIncluded = true);
448
 
        
449
 
        /**
450
 
        * \brief Cuts the string after the last occurrence of the given char
451
 
        *
452
 
        * If the char is not found, the string is returned as it is.
453
 
        * \param szSrc The source string
454
 
        * \param c The char to search for
455
 
        * \param bIncluded Wheter to include the given char
456
 
        * \return void
457
 
        */
458
 
        extern KVILIB_API void cutFromLast(QString & szSrc, const QChar & c, bool bIncluded = true);
459
 
        
460
 
        /**
461
 
        * \brief Cuts the string after the last occurrence of the given char
462
 
        *
463
 
        * If the char is not found, the string is returned as it is.
464
 
        * \param szSrc The source string
465
 
        * \param szFind The string to search for
466
 
        * \param bIncluded Wheter to include the given string
467
 
        * \return void
468
 
        */
469
 
        extern KVILIB_API void cutFromLast(QString & szSrc, const QString & szFind, bool bIncluded = true);
470
 
        
471
 
        /**
472
 
        * \brief Cuts the string until the first occurrence of the given char is found
473
 
        *
474
 
        * If the char is not found, the string is returned as it is.
475
 
        * \param szSrc The source string
476
 
        * \param c The char to search for
477
 
        * \param bIncluded Wheter to include the given char in the cut
478
 
        * \param bClearIfNotFound Wheter to cut the whole string if the char is not found
479
 
        * \return void
480
 
        */
481
 
        extern KVILIB_API void cutToFirst(QString & szSrc, const QChar & c, bool bIncluded = true, bool bClearIfNotFound = false);
482
 
        
483
 
        /**
484
 
        * \brief Cuts the string until the first occurrence of the given char is found
485
 
        *
486
 
        * If the char is not found, the string is returned as it is.
487
 
        * \param szSrc The source string
488
 
        * \param szFind The string to search for
489
 
        * \param bIncluded Wheter to include the given string in the cut
490
 
        * \param bClearIfNotFound Wheter to cut the whole string if the string is not found
491
 
        * \return void
492
 
        */
493
 
        extern KVILIB_API void cutToFirst(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bClearIfNotFound = false);
494
 
        
495
 
        /**
496
 
        * \brief Cuts the string until the last occurrence of the given char is found
497
 
        *
498
 
        * If the char is not found, the string is returned as it is.
499
 
        * \param szSrc The source string
500
 
        * \param c The char to search for
501
 
        * \param bIncluded Wheter to include the given char in the cut
502
 
        * \param bClearIfNotFound Wheter to cut the whole string if the char is not found
503
 
        * \return void
504
 
        */
505
 
        extern KVILIB_API void cutToLast(QString & szSrc, const QChar & c, bool bIncluded = true, bool bClearIfNotFound = false);
506
 
        
507
 
        /**
508
 
        * \brief Cuts the string until the last occurrence of the given char is found
509
 
        *
510
 
        * If the char is not found, the string is returned as it is.
511
 
        * \param szSrc The source string
512
 
        * \param szFind The string to search for
513
 
        * \param bIncluded Wheter to include the given string in the cut
514
 
        * \param bClearIfNotFound Wheter to cut the whole string if the string is not found
515
 
        * \return void
516
 
        */
517
 
        extern KVILIB_API void cutToLast(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bClearIfNotFound = false);
518
 
 
519
 
        /**
520
 
        * \brief Returns the string up to the the first occurrence of the given char
521
 
        *
522
 
        * If the char is not found, the string is returned as it is.
523
 
        * \param szSrc The source string
524
 
        * \param c The char to search for
525
 
        * \param bIncluded Wheter to include the given char in the returned string
526
 
        * \param bReturnFullStringIfNotFound True if we want the function to return the whole string if the char isn't found and
527
 
        *        false if we want the function to return an empty string in this case.
528
 
        * \return void
529
 
        */
530
 
        extern KVILIB_API QString leftToFirst(QString & szSrc, const QChar & c, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
531
 
        
532
 
        /**
533
 
        * \brief Returns the string up to the first occurrence of the given string
534
 
        *
535
 
        * If the char is not found, the string is returned as it is.
536
 
        * \param szSrc The source string
537
 
        * \param szFind The string to search for
538
 
        * \param bIncluded Wheter to include the given string in the returned string
539
 
        * \param bReturnFullStringIfNotFound True if we want the function to return the whole string if the string isn't found and
540
 
        *        false if we want the function to return an empty string in this case.
541
 
        * \return void
542
 
        */
543
 
        extern KVILIB_API QString leftToFirst(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
544
 
        
545
 
        /**
546
 
        * \brief Returns the string up to the last occurrence of the given char
547
 
        *
548
 
        * If the char is not found, the string is returned as it is.
549
 
        * \param szSrc The source string
550
 
        * \param c The char to search for
551
 
        * \param bIncluded Wheter to include the given char in the returned string
552
 
        * \param bReturnFullStringIfNotFound True if we want the function to return the whole string if the char isn't found and
553
 
        *        false if we want the function to return an empty string in this case.
554
 
        * \return void
555
 
        */
556
 
        extern KVILIB_API QString leftToLast(QString & szSrc, const QChar & c, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
557
 
        
558
 
        /**
559
 
        * \brief Returns the string up to the last occurrence of the given string
560
 
        *
561
 
        * If the char is not found, the string is returned as it is.
562
 
        * \param szSrc The source string
563
 
        * \param szFind The string to search for
564
 
        * \param bIncluded Wheter to include the given string in the returned string
565
 
        * \param bReturnFullStringIfNotFound True if we want the function to return the whole string if the string isn't found and
566
 
        *        false if we want the function to return an empty string in this case.
567
 
        * \return void
568
 
        */
569
 
        extern KVILIB_API QString leftToLast(QString & szSrc, const QString & szFind, bool bIncluded = true, bool bReturnFullStringIfNotFound = true);
570
 
 
571
 
        /**
572
 
        * \brief Returns an ISO-8859-1 upper case string
573
 
        * \param szSrc The source string
574
 
        * \return QString
575
 
        */
576
 
        extern KVILIB_API QString upperISO88591(const QString & szSrc);
577
 
        
578
 
        /**
579
 
        * \brief Returns an ISO-8859-1 lower case string
580
 
        * \param szSrc The source string
581
 
        * \return QString
582
 
        */
583
 
        extern KVILIB_API QString lowerISO88591(const QString & szSrc);
584
 
        
585
 
        /**
586
 
        * \brief Returns a token from a string
587
 
        * \param szSrc The source string
588
 
        * \param sep The token to find
589
 
        * \return QString
590
 
        */
591
 
        extern KVILIB_API QString getToken(QString & szSrc, const QChar & sep);
592
 
 
593
 
        /**
594
 
        * \brief Replaces a string with another
595
 
        * \param szSrc The source string
596
 
        * \param szToFind The string to replace
597
 
        * \param szReplacement The string to replace with
598
 
        * \return void
599
 
        */
600
 
        extern KVILIB_API void transliterate(QString & szSrc, const QString & szToFind, const QString & szReplacement);
601
 
 
602
 
        /**
603
 
        * \brief Returns an hexadecimal converted string starting from a buffer
604
 
        * \param szRetBuffer The buffer to hold the hexadecimal string
605
 
        * \param pcBuffer The buffer containing the string to convert
606
 
        * \param uLen The max length of the original string
607
 
        */
608
 
        extern KVILIB_API void bufferToHex(QString & szRetBuffer, const unsigned char * pcBuffer, unsigned int uLen);
609
 
 
610
 
        /**
611
 
        * \brief Returns the index position of the last occurrence of the character
612
 
        *
613
 
        * The search is made forward starting from index.
614
 
        * \param szSrc The source string
615
 
        * \param c The character to find
616
 
        * \param iIndex The index to start from
617
 
        * \param bCs Case sensitive search
618
 
        * \return int
619
 
        */
620
 
        inline int find(const QString & szSrc, QChar c, int iIndex = 0, bool bCs = true)
621
 
        {
622
 
                return szSrc.indexOf(c,iIndex,bCs ? Qt::CaseSensitive : Qt::CaseInsensitive);
623
 
        }
624
 
 
625
 
        /**
626
 
        * \brief Returns the index position of the last occurrence of the character
627
 
        *
628
 
        * The search is made forward starting from index.
629
 
        * \param szSrc The source string
630
 
        * \param c The character to find
631
 
        * \param iIndex The index to start from
632
 
        * \param bCs Case sensitive search
633
 
        * \return int
634
 
        */
635
 
        inline int find(const QString & szSrc, char c, int iIndex = 0, bool bCs = true)
636
 
        {
637
 
                return szSrc.indexOf(c,iIndex,bCs ? Qt::CaseSensitive : Qt::CaseInsensitive);
638
 
        }
639
 
 
640
 
        /**
641
 
        * \brief Returns the index position of the last occurrence of the string
642
 
        *
643
 
        * The search is made forward starting from index.
644
 
        * \param szSrc The source string
645
 
        * \param szStr The string to find
646
 
        * \param iIndex The index to start from
647
 
        * \param bCs Case sensitive search
648
 
        * \return int
649
 
        */
650
 
        inline int find(const QString & szSrc, const QString & szStr, int iIndex = 0, bool bCs = true)
651
 
        {
652
 
                return szSrc.indexOf(szStr,iIndex,bCs ? Qt::CaseSensitive : Qt::CaseInsensitive);
653
 
        }
654
 
 
655
 
        /**
656
 
        * \brief Returns the index position of the last occurrence of the string
657
 
        *
658
 
        * The search is made forward starting from index.
659
 
        * \param szSrc The source string
660
 
        * \param pcStr The string to find
661
 
        * \param iIndex The index to start from
662
 
        * \param bCs Case sensitive search
663
 
        * \return int
664
 
        */
665
 
        inline int find(const QString & szSrc, const char * pcStr, int iIndex = 0, bool bCs = true)
666
 
        {
667
 
                return szSrc.indexOf(QString(pcStr),iIndex,bCs ? Qt::CaseSensitive : Qt::CaseInsensitive);
668
 
        }
669
 
 
670
 
        /**
671
 
        * \brief Returns the index position of the last occurrence of the string
672
 
        *
673
 
        * The search is made forward starting from index.
674
 
        * \param szSrc The source string
675
 
        * \param rx The regexp to match
676
 
        * \param iIndex The index to start from
677
 
        * \return int
678
 
        */
679
 
        inline int find(const QString & szSrc, const QRegExp & rx, int iIndex = 0)
680
 
        {
681
 
                return szSrc.indexOf(rx,iIndex);
682
 
        }
683
 
 
684
 
        /**
685
 
        * \brief Returns the index position of the last occurrence of the character
686
 
        *
687
 
        * The search is made backward.
688
 
        * If index is -1 the search starts at the last character.
689
 
        * \param szSrc The source string
690
 
        * \param c The character to find
691
 
        * \param iIndex The index to start from
692
 
        * \param bCs Case sensitive search
693
 
        * \return int
694
 
        */
695
 
        inline int findRev(const QString & szSrc, QChar c, int iIndex = -1, bool bCs = true)
696
 
        {
697
 
                return szSrc.lastIndexOf(c,iIndex,bCs ? Qt::CaseSensitive : Qt::CaseInsensitive);
698
 
        }
699
 
 
700
 
        /**
701
 
        * \brief Returns the index position of the last occurrence of the character
702
 
        *
703
 
        * The search is made backward.
704
 
        * If index is -1 the search starts at the last character.
705
 
        * \param szSrc The source string
706
 
        * \param c The character to find
707
 
        * \param iIndex The index to start from
708
 
        * \param bCs Case sensitive search
709
 
        * \return int
710
 
        */
711
 
        inline int findRev(const QString & szSrc, char c, int iIndex = -1, bool bCs = true)
712
 
        {
713
 
                return szSrc.lastIndexOf(c,iIndex,bCs ? Qt::CaseSensitive : Qt::CaseInsensitive);
714
 
        }
715
 
 
716
 
        /**
717
 
        * \brief Returns the index position of the last occurrence of the given string
718
 
        *
719
 
        * The search is made backward.
720
 
        * If index is -1 the search starts at the last character.
721
 
        * \param szSrc The source string
722
 
        * \param szStr The string to find
723
 
        * \param iIndex The index to start from
724
 
        * \param bCs Case sensitive search
725
 
        * \return int
726
 
        */
727
 
        inline int findRev(const QString & szSrc, const QString & szStr, int iIndex = -1, bool bCs = true)
728
 
        {
729
 
                return szSrc.lastIndexOf(szStr,iIndex,bCs ? Qt::CaseSensitive : Qt::CaseInsensitive);
730
 
        }
731
 
 
732
 
        /**
733
 
        * \brief Returns the index position of the last occurrence of the given string
734
 
        *
735
 
        * The search is made backward.
736
 
        * If index is -1 the search starts at the last character.
737
 
        * \param szSrc The source string
738
 
        * \param pcStr The string to find
739
 
        * \param iIndex The index to start from
740
 
        * \param bCs Case sensitive search
741
 
        * \return int
742
 
        */
743
 
        inline int findRev(const QString & szSrc, const char * pcStr, int iIndex = -1, bool bCs = true)
744
 
        {
745
 
                return szSrc.lastIndexOf(QString(pcStr),iIndex,bCs ? Qt::CaseSensitive : Qt::CaseInsensitive);
746
 
        }
747
 
 
748
 
        /**
749
 
        * \brief Returns the index position of the last match of the regexp
750
 
        *
751
 
        * The search is made backward.
752
 
        * If index is -1 the search starts at the last character.
753
 
        * \param szSrc The source string
754
 
        * \param rx The regexp to match
755
 
        * \param iIndex The index to start from
756
 
        * \return int
757
 
        */
758
 
        inline int findRev(const QString & szSrc, const QRegExp & rx, int iIndex = -1)
759
 
        {
760
 
                return szSrc.lastIndexOf(rx,iIndex);
761
 
        }
762
 
 
763
 
        /**
764
 
        * \brief Return a whitespace-trimmed string
765
 
        *
766
 
        * Spaces are trimmed at start and end of the string
767
 
        * \param szSrc The source string
768
 
        * \return QString
769
 
        */
770
 
        inline QString trimmed(const QString & szSrc)
771
 
        {
772
 
                return szSrc.trimmed();
773
 
        }
774
 
 
775
 
        /**
776
 
        * \brief Return a UTF-8 formatted string
777
 
        * \param szSrc The source string
778
 
        * \return QByteArray
779
 
        * \warning: DO NOT USE CONSTRUCTS LIKE char * c = KviQString::toUtf8(something).data();
780
 
        * They are dangerous since with many compilers the returned string
781
 
        * gets destroyed at the end of the instruction and the c pointer gets
782
 
        * thus invalidated.
783
 
        * Use
784
 
        * QByteArray tmp = KviQString::toUtf8(something);
785
 
        * char * c = tmp.data();
786
 
        * instead. Yes, I know that it sucks, but it's the only way to
787
 
        * transit to Qt 4.x more or less cleanly...
788
 
        */
789
 
        inline QByteArray toUtf8(const QString & szSrc)
790
 
        {
791
 
                return szSrc.toUtf8();
792
 
        }
793
 
 
794
 
        /**
795
 
        * \brief Return the local 8-bit representation of the string
796
 
        * \param szSrc The source string
797
 
        * \return QByteArray
798
 
        */
799
 
        inline QByteArray toLocal8Bit(const QString & szSrc)
800
 
        {
801
 
                return szSrc.toLocal8Bit();
802
 
        }
803
 
 
804
 
        /**
805
 
        * \brief Return the string converted to a long
806
 
        * \param szNumber The source number
807
 
        * \param bOk The conversion error handling
808
 
        * \return kvi_i64_t
809
 
        */
810
 
        inline kvi_i64_t toI64(QString & szNumber, bool * bOk)
811
 
        {
812
 
#if SYSTEM_SIZE_OF_LONG_INT == 8
813
 
                return szNumber.toLong(bOk);
814
 
#else
815
 
                return szNumber.toLongLong(bOk);
816
 
#endif
817
 
        }
818
 
 
819
 
        /**
820
 
        * \brief Return the string converted to an unsigned long
821
 
        * \param szNumber The source number
822
 
        * \param bOk The conversion error handling
823
 
        * \return kvi_u64_t
824
 
        */
825
 
        inline kvi_u64_t toU64(QString & szNumber, bool * bOk)
826
 
        {
827
 
#if SYSTEM_SIZE_OF_LONG_INT == 8
828
 
                return szNumber.toULong(bOk);
829
 
#else
830
 
                return szNumber.toULongLong(bOk);
831
 
#endif
832
 
        }
833
 
}
834
 
 
835
 
#endif //_KVI_QSTRING_H_