summaryrefslogtreecommitdiffabout
path: root/kabc/vcard/RToken.cpp
Unidiff
Diffstat (limited to 'kabc/vcard/RToken.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcard/RToken.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/kabc/vcard/RToken.cpp b/kabc/vcard/RToken.cpp
new file mode 100644
index 0000000..2a85820
--- a/dev/null
+++ b/kabc/vcard/RToken.cpp
@@ -0,0 +1,88 @@
1/*
2
3 libvcard - vCard parsing library for vCard version 3.0
4
5 Copyright (C) 1999 Rik Hemsley rik@kde.org
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to
9 deal in the Software without restriction, including without limitation the
10 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 sell copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*/
24
25#include <string.h>
26#include <stddef.h>
27#include <qcstring.h>
28#include <qstrlist.h>
29
30namespace VCARD
31{
32
33 Q_UINT32
34RTokenise(const char * str, const char * delim, QStrList & l)
35{
36 // FIXME no stderr !
37 l.clear();
38
39 if (!delim || !str || strlen(delim) == 0 || strlen(str) == 0) return 0;
40
41 char * len = (char *)(str + strlen(str));// End of string.
42
43 register char * rstart = new char[strlen(str) + 1];
44 register char * r = rstart;
45
46
47 register const char * i = str;// Cursor.
48
49 while (i <= len) {
50
51 if (*i == '\\') { // Escaped chars go straight through.
52 *r++ = *i++;
53 if (i <= len)
54 *r++ = *i++;
55 continue;
56 }
57
58 if (strchr(delim, *i) != 0) {
59 // We hit a delimiter. If we have some text, make a new token.
60 // This has the effect that multiple delimiters are collapsed.
61 // cs: We mustn't collapse multiple delimiters, otherwise we
62 // lose empty fields.
63 *r = '\0';
64 // if (r != rstart) {
65 l.append(rstart);
66 // }
67 r = rstart;
68 ++i;
69 continue;
70 }
71
72 *r++ = *i++;
73 }
74
75 // Catch last token
76 //if (r != rstart) {
77 *r = '\0';
78 l.append(rstart);
79 //}
80
81 r = 0;
82
83 delete [] rstart;
84
85 return l.count();
86}
87
88}