-rw-r--r-- | kabc/vcard/AdrParam.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/kabc/vcard/AdrParam.cpp b/kabc/vcard/AdrParam.cpp new file mode 100644 index 0000000..fa46499 --- a/dev/null +++ b/kabc/vcard/AdrParam.cpp | |||
@@ -0,0 +1,126 @@ | |||
1 | /* | ||
2 | libvcard - vCard parsing library for vCard version 3.0 | ||
3 | |||
4 | Copyright (C) 1998 Rik Hemsley rik@kde.org | ||
5 | |||
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 | ||
8 | deal in the Software without restriction, including without limitation the | ||
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 | ||
11 | furnished to do so, subject to the following conditions: | ||
12 | |||
13 | The above copyright notice and this permission notice shall be included in | ||
14 | all copies or substantial portions of the Software. | ||
15 | |||
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, | ||
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 | ||
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. | ||
22 | */ | ||
23 | |||
24 | #include <VCardRToken.h> | ||
25 | #include <VCardAdrParam.h> | ||
26 | #include <VCardParam.h> | ||
27 | |||
28 | using namespace VCARD; | ||
29 | |||
30 | AdrParam::AdrParam() | ||
31 | :Param() | ||
32 | { | ||
33 | } | ||
34 | |||
35 | AdrParam::AdrParam(const AdrParam & x) | ||
36 | :Param(x), | ||
37 | adrTypeList_(x.adrTypeList_) | ||
38 | { | ||
39 | } | ||
40 | |||
41 | AdrParam::AdrParam(const QCString & s) | ||
42 | :Param(s) | ||
43 | { | ||
44 | } | ||
45 | |||
46 | AdrParam & | ||
47 | AdrParam::operator = (AdrParam & x) | ||
48 | { | ||
49 | if (*this == x) return *this; | ||
50 | |||
51 | adrTypeList_= x.adrTypeList(); | ||
52 | textParam_ = x.textParam(); | ||
53 | |||
54 | Param::operator = (x); | ||
55 | return *this; | ||
56 | } | ||
57 | |||
58 | AdrParam & | ||
59 | AdrParam::operator = (const QCString & s) | ||
60 | { | ||
61 | Param::operator = (s); | ||
62 | |||
63 | adrTypeList_.clear(); | ||
64 | textParam_.truncate(0); | ||
65 | |||
66 | return *this; | ||
67 | } | ||
68 | |||
69 | bool | ||
70 | AdrParam::operator == (AdrParam & x) | ||
71 | { | ||
72 | parse(); | ||
73 | |||
74 | if (!x.textParam().isEmpty()) | ||
75 | return (x.textParam_ == textParam_); | ||
76 | |||
77 | if (x.adrTypeList().count() != adrTypeList_.count()) | ||
78 | return false; | ||
79 | |||
80 | QStrListIterator it(x.adrTypeList_); | ||
81 | |||
82 | for (; it.current(); ++it) | ||
83 | if (!adrTypeList_.find(it.current())) | ||
84 | return false; | ||
85 | |||
86 | return true; | ||
87 | } | ||
88 | |||
89 | AdrParam::~AdrParam() | ||
90 | { | ||
91 | } | ||
92 | |||
93 | void | ||
94 | AdrParam::_parse() | ||
95 | { | ||
96 | adrTypeList_.clear(); | ||
97 | |||
98 | if (strRep_.left(4) != "TYPE") { | ||
99 | textParam_ = strRep_; | ||
100 | return; | ||
101 | } | ||
102 | |||
103 | if (!strRep_.contains('=')) | ||
104 | return; | ||
105 | |||
106 | RTokenise(strRep_, ",", adrTypeList_); | ||
107 | } | ||
108 | |||
109 | void | ||
110 | AdrParam::_assemble() | ||
111 | { | ||
112 | if (!textParam_.isEmpty()) { | ||
113 | strRep_ = textParam_; | ||
114 | return; | ||
115 | } | ||
116 | |||
117 | QStrListIterator it(adrTypeList_); | ||
118 | |||
119 | for (; it.current(); ++it) { | ||
120 | |||
121 | strRep_ += it.current(); | ||
122 | |||
123 | if (it.current() != adrTypeList_.last()) | ||
124 | strRep_ += ','; | ||
125 | } | ||
126 | } | ||