-rw-r--r-- | kabc/vcard/VCardEntity.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/kabc/vcard/VCardEntity.cpp b/kabc/vcard/VCardEntity.cpp index a2ff327..bae5385 100644 --- a/kabc/vcard/VCardEntity.cpp +++ b/kabc/vcard/VCardEntity.cpp | |||
@@ -1,167 +1,169 @@ | |||
1 | /* | 1 | /* |
2 | libvcard - vCard parsing library for vCard version 3.0 | 2 | libvcard - vCard parsing library for vCard version 3.0 |
3 | 3 | ||
4 | Copyright (C) 1998 Rik Hemsley rik@kde.org | 4 | Copyright (C) 1998 Rik Hemsley rik@kde.org |
5 | 5 | ||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | of this software and associated documentation files (the "Software"), to | 7 | of this software and associated documentation files (the "Software"), to |
8 | deal in the Software without restriction, including without limitation the | 8 | deal in the Software without restriction, including without limitation the |
9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
10 | sell copies of the Software, and to permit persons to whom the Software is | 10 | sell copies of the Software, and to permit persons to whom the Software is |
11 | furnished to do so, subject to the following conditions: | 11 | furnished to do so, subject to the following conditions: |
12 | 12 | ||
13 | The above copyright notice and this permission notice shall be included in | 13 | The above copyright notice and this permission notice shall be included in |
14 | all copies or substantial portions of the Software. | 14 | all copies or substantial portions of the Software. |
15 | 15 | ||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qregexp.h> | 24 | #include <qregexp.h> |
25 | #include <qdatetime.h> | 25 | #include <qdatetime.h> |
26 | //Added by qt3to4: | ||
27 | #include <Q3CString> | ||
26 | 28 | ||
27 | #include <VCardDefines.h> | 29 | #include <VCardDefines.h> |
28 | #include <VCardVCardEntity.h> | 30 | #include <VCardVCardEntity.h> |
29 | 31 | ||
30 | using namespace VCARD; | 32 | using namespace VCARD; |
31 | 33 | ||
32 | VCardEntity::VCardEntity() | 34 | VCardEntity::VCardEntity() |
33 | :Entity() | 35 | :Entity() |
34 | { | 36 | { |
35 | cardList_.setAutoDelete( TRUE ); | 37 | cardList_.setAutoDelete( TRUE ); |
36 | } | 38 | } |
37 | 39 | ||
38 | VCardEntity::VCardEntity(const VCardEntity & x) | 40 | VCardEntity::VCardEntity(const VCardEntity & x) |
39 | :Entity(x) | 41 | :Entity(x) |
40 | { | 42 | { |
41 | cardList_.setAutoDelete( TRUE ); | 43 | cardList_.setAutoDelete( TRUE ); |
42 | } | 44 | } |
43 | 45 | ||
44 | VCardEntity::VCardEntity(const QCString & s) | 46 | VCardEntity::VCardEntity(const Q3CString & s) |
45 | :Entity(s) | 47 | :Entity(s) |
46 | { | 48 | { |
47 | cardList_.setAutoDelete( TRUE ); | 49 | cardList_.setAutoDelete( TRUE ); |
48 | } | 50 | } |
49 | 51 | ||
50 | VCardEntity & | 52 | VCardEntity & |
51 | VCardEntity::operator = (VCardEntity & x) | 53 | VCardEntity::operator = (VCardEntity & x) |
52 | { | 54 | { |
53 | if (*this == x) return *this; | 55 | if (*this == x) return *this; |
54 | 56 | ||
55 | Entity::operator = (x); | 57 | Entity::operator = (x); |
56 | return *this; | 58 | return *this; |
57 | } | 59 | } |
58 | 60 | ||
59 | VCardEntity & | 61 | VCardEntity & |
60 | VCardEntity::operator = (const QCString & s) | 62 | VCardEntity::operator = (const Q3CString & s) |
61 | { | 63 | { |
62 | Entity::operator = (s); | 64 | Entity::operator = (s); |
63 | return *this; | 65 | return *this; |
64 | } | 66 | } |
65 | 67 | ||
66 | bool | 68 | bool |
67 | VCardEntity::operator == (VCardEntity & x) | 69 | VCardEntity::operator == (VCardEntity & x) |
68 | { | 70 | { |
69 | x.parse(); | 71 | x.parse(); |
70 | return false; | 72 | return false; |
71 | } | 73 | } |
72 | 74 | ||
73 | VCardEntity::~VCardEntity() | 75 | VCardEntity::~VCardEntity() |
74 | { | 76 | { |
75 | } | 77 | } |
76 | 78 | ||
77 | void | 79 | void |
78 | VCardEntity::_parse() | 80 | VCardEntity::_parse() |
79 | { | 81 | { |
80 | #if 0 | 82 | #if 0 |
81 | QTime tim; | 83 | QTime tim; |
82 | tim.start(); | 84 | tim.start(); |
83 | int num = 0; | 85 | int num = 0; |
84 | // old code | 86 | // old code |
85 | vDebug("parse"); | 87 | vDebug("parse"); |
86 | QCString s(strRep_); | 88 | Q3CString s(strRep_); |
87 | 89 | ||
88 | int i = s.find(QRegExp("BEGIN:VCARD", false)); | 90 | int i = s.find(QRegExp("BEGIN:VCARD", false)); |
89 | 91 | ||
90 | while (i != -1) { | 92 | while (i != -1) { |
91 | 93 | ||
92 | i = s.find(QRegExp("BEGIN:VCARD", false), 11); | 94 | i = s.find(QRegExp("BEGIN:VCARD", false), 11); |
93 | 95 | ||
94 | QCString cardStr(s.left(i)); | 96 | Q3CString cardStr(s.left(i)); |
95 | 97 | ||
96 | VCard * v = new VCard(cardStr); | 98 | VCard * v = new VCard(cardStr); |
97 | 99 | ||
98 | cardList_.append(v); | 100 | cardList_.append(v); |
99 | 101 | ||
100 | v->parse(); | 102 | v->parse(); |
101 | 103 | ||
102 | s.remove(0, i); | 104 | s.remove(0, i); |
103 | } | 105 | } |
104 | 106 | ||
105 | #else | 107 | #else |
106 | // this code is up to 17 (!) times faster | 108 | // this code is up to 17 (!) times faster |
107 | int start = 0; | 109 | int start = 0; |
108 | QTime tim; | 110 | QTime tim; |
109 | tim.start(); | 111 | tim.start(); |
110 | int i = 11; | 112 | int i = 11; |
111 | int len = strRep_.length(); | 113 | int len = strRep_.length(); |
112 | int num = 0; | 114 | int num = 0; |
113 | while (i < len ) { | 115 | while (i < len ) { |
114 | while( i < len ) { | 116 | while( i < len ) { |
115 | int add = 1; | 117 | int add = 1; |
116 | if ( strRep_.at(i) == 'B' ) { | 118 | if ( strRep_.at(i) == 'B' ) { |
117 | if ( i+add < len && strRep_.at(i+add++) == 'E') | 119 | if ( i+add < len && strRep_.at(i+add++) == 'E') |
118 | if ( i+add < len && strRep_.at(i+add++) == 'G') | 120 | if ( i+add < len && strRep_.at(i+add++) == 'G') |
119 | if ( i+add < len && strRep_.at(i+add++) == 'I') | 121 | if ( i+add < len && strRep_.at(i+add++) == 'I') |
120 | if ( i+add < len && strRep_.at(i+add++) == 'N') | 122 | if ( i+add < len && strRep_.at(i+add++) == 'N') |
121 | if ( i+add < len && strRep_.at(i+add++) == ':') | 123 | if ( i+add < len && strRep_.at(i+add++) == ':') |
122 | if ( i+add < len && strRep_.at(i+add++) == 'V') | 124 | if ( i+add < len && strRep_.at(i+add++) == 'V') |
123 | if ( i+add < len && strRep_.at(i+add++) == 'C') | 125 | if ( i+add < len && strRep_.at(i+add++) == 'C') |
124 | if ( i+add < len && strRep_.at(i+add++) == 'A') | 126 | if ( i+add < len && strRep_.at(i+add++) == 'A') |
125 | if ( i+add < len && strRep_.at(i+add++) == 'R') | 127 | if ( i+add < len && strRep_.at(i+add++) == 'R') |
126 | if ( i+add < len && strRep_.at(i+add++) == 'D') | 128 | if ( i+add < len && strRep_.at(i+add++) == 'D') |
127 | if ( i+add < len && (strRep_.at(i+add) == '\r' || strRep_.at(i+add) == '\n' )) | 129 | if ( i+add < len && (strRep_.at(i+add) == '\r' || strRep_.at(i+add) == '\n' )) |
128 | break; | 130 | break; |
129 | } | 131 | } |
130 | ++i; | 132 | ++i; |
131 | } | 133 | } |
132 | if ( i <= len ) { | 134 | if ( i <= len ) { |
133 | ++num; | 135 | ++num; |
134 | char* dat = strRep_.data()+start; | 136 | char* dat = strRep_.data()+start; |
135 | VCard * v = new VCard( QCString ( dat,i-start ) ); | 137 | VCard * v = new VCard( Q3CString ( dat,i-start ) ); |
136 | start = i; | 138 | start = i; |
137 | cardList_.append(v); | 139 | cardList_.append(v); |
138 | v->parse(); | 140 | v->parse(); |
139 | } | 141 | } |
140 | i+= 11; | 142 | i+= 11; |
141 | } | 143 | } |
142 | #endif | 144 | #endif |
143 | //qDebug("***time %d found %d", tim.elapsed(), num); | 145 | //qDebug("***time %d found %d", tim.elapsed(), num); |
144 | } | 146 | } |
145 | 147 | ||
146 | void | 148 | void |
147 | VCardEntity::_assemble() | 149 | VCardEntity::_assemble() |
148 | { | 150 | { |
149 | VCardListIterator it(cardList_); | 151 | VCardListIterator it(cardList_); |
150 | 152 | ||
151 | for (; it.current(); ++it) | 153 | for (; it.current(); ++it) |
152 | strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck. | 154 | strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck. |
153 | } | 155 | } |
154 | 156 | ||
155 | VCardList & | 157 | VCardList & |
156 | VCardEntity::cardList() | 158 | VCardEntity::cardList() |
157 | { | 159 | { |
158 | parse(); | 160 | parse(); |
159 | return cardList_; | 161 | return cardList_; |
160 | } | 162 | } |
161 | 163 | ||
162 | void | 164 | void |
163 | VCardEntity::setCardList(const VCardList & l) | 165 | VCardEntity::setCardList(const VCardList & l) |
164 | { | 166 | { |
165 | parse(); | 167 | parse(); |
166 | //UScardList_ = l; | 168 | //UScardList_ = l; |
167 | VCardListIterator it(l); | 169 | VCardListIterator it(l); |