# kabc Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# ContentLine.cpp

    00001 /*
    00002         libvcard - vCard parsing library for vCard version 3.0
    00003
    00004         Copyright (C) 1999 Rik Hemsley rik@kde.org
    00005
    00006   Permission is hereby granted, free of charge, to any person obtaining a copy
    00007   of this software and associated documentation files (the "Software"), to
    00008   deal in the Software without restriction, including without limitation the
    00009   rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    00010   sell copies of the Software, and to permit persons to whom the Software is
    00011   furnished to do so, subject to the following conditions:
    00012
    00013   The above copyright notice and this permission notice shall be included in
    00014   all copies or substantial portions of the Software.
    00015
    00016   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00017   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00018   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    00019   AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
    00020   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    00021   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00022 */
    00023
    00024 #include <qcstring.h>
    00025 #include <qstrlist.h>
    00026 #include <qregexp.h>
    00027
    00028 #include <kdebug.h>
    00029
    00030 #include <VCardAdrParam.h>
    00031 #include <VCardAgentParam.h>
    00032 #include <VCardDateParam.h>
    00033 #include <VCardEmailParam.h>
    00034 #include <VCardImageParam.h>
    00035 #include <VCardSourceParam.h>
    00036 #include <VCardTelParam.h>
    00037 #include <VCardTextBinParam.h>
    00038 #include <VCardTextParam.h>
    00039
    00040 #include <VCardAdrValue.h>
    00041 #include <VCardAgentValue.h>
    00042 #include <VCardDateValue.h>
    00043 #include <VCardImageValue.h>
    00044 #include <VCardTextValue.h>
    00045 #include <VCardTextBinValue.h>
    00046 #include <VCardLangValue.h>
    00047 #include <VCardNValue.h>
    00048 #include <VCardURIValue.h>
    00049 #include <VCardSoundValue.h>
    00050 #include <VCardClassValue.h>
    00051 #include <VCardFloatValue.h>
    00052 #include <VCardOrgValue.h>
    00053 #include <VCardTelValue.h>
    00054 #include <VCardTextListValue.h>
    00055 #include <VCardUTCValue.h>
    00056 #include <VCardGeoValue.h>
    00057
    00058 #include <VCardRToken.h>
    00059 #include <VCardContentLine.h>
    00060
    00061 #include <VCardEntity.h>
    00062 #include <VCardEnum.h>
    00063 #include <VCardDefines.h>
    00064
    00065 using namespace VCARD;
    00066
    00067 ContentLine::ContentLine()
    00068         :       Entity(),
    00069                 value_(0)
    00070 {
    00071 }
    00072
    00073 ContentLine::ContentLine(const ContentLine & x)
    00074         :       Entity(x),
    00075                 group_ (x.group_),
    00076                 name_ (x.name_),
    00077                 paramList_(x.paramList_),
    00078                 value_(x.value_->clone())
    00079 {
    00080 }
    00081
    00082 ContentLine::ContentLine(const QCString & s)
    00083         :       Entity(s),
    00084                 value_(0)
    00085 {
    00086 }
    00087
    00088         ContentLine &
    00089 ContentLine::operator = (ContentLine & x)
    00090 {
    00091         if (*this == x) return *this;
    00092
    00093         paramList_ = x.paramList();
    00094         value_ = x.value_->clone();
    00095
    00096         Entity::operator = (x);
    00097         return *this;
    00098 }
    00099
    00100         ContentLine &
    00101 ContentLine::operator = (const QCString & s)
    00102 {
    00103         Entity::operator = (s);
    00104         delete value_;
    00105         value_ = 0;
    00106         return *this;
    00107 }
    00108
    00109         bool
    00110 ContentLine::operator == (ContentLine & x)
    00111 {
    00112         x.parse();
    00113
    00114         QPtrListIterator<Param> it(x.paramList());
    00115
    00116         if (!paramList_.find(it.current()))
    00117                 return false;
    00118
    00119         return true;
    00120 }
    00121
    00122 ContentLine::~ContentLine()
    00123 {
    00124         delete value_;
    00125         value_ = 0;
    00126 }
    00127
    00128         void
    00129 ContentLine::_parse()
    00130 {
    00131         vDebug("parse");
    00132
    00133         // Unqote newlines
    00134         strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" );
    00135
    00136         int split = strRep_.find(':');
    00137
    00138         if (split == -1) { // invalid content line
    00139                 vDebug("No ':'");
    00140                 return;
    00141         }
    00142
    00143         QCString firstPart(strRep_.left(split));
    00144         QCString valuePart(strRep_.mid(split + 1));
    00145
    00146         split = firstPart.find('.');
    00147
    00148         if (split != -1) {
    00149                 group_          = firstPart.left(split);
    00150                 firstPart       = firstPart.mid(split + 1);
    00151         }
    00152
    00153         vDebug("Group == " + group_);
    00154         vDebug("firstPart == " + firstPart);
    00155         vDebug("valuePart == " + valuePart);
    00156
    00157         // Now we have the group, the name and param list together and the value.
    00158
    00159         QStrList l;
    00160
    00161         RTokenise(firstPart, ";", l);
    00162
    00163         if (l.count() == 0) {// invalid - no name !
    00164                 vDebug("No name for this content line !");
    00165                 return;
    00166         }
    00167
    00168         name_ = l.at(0);
    00169
    00170         // Now we have the name, so the rest of 'l' is the params.
    00171         // Remove the name part.
    00172         l.remove(0u);
    00173
    00174         entityType_     = EntityNameToEntityType(name_);
    00175         paramType_      = EntityTypeToParamType(entityType_);
    00176
    00177         unsigned int i = 0;
    00178
    00179         // For each parameter, create a new parameter of the correct type.
    00180
    00181         QStrListIterator it(l);
    00182
    00183         for (; it.current(); ++it, i++) {
    00184
    00185                 QCString str = *it;
    00186
    00187                 split = str.find("=");
    00188                 if (split < 0 ) {
    00189                         vDebug("No '=' in paramter.");
    00190                         continue;
    00191                 }
    00192
    00193                 QCString paraName = str.left(split);
    00194                 QCString paraValue = str.mid(split + 1);
    00195
    00196                 QStrList paraValues;
    00197                 RTokenise(paraValue, ",", paraValues);
    00198
    00199                 QStrListIterator it2( paraValues );
    00200
    00201                 for(; it2.current(); ++it2) {
    00202
    00203                         Param *p = new Param;
    00204                         p->setName( paraName );
    00205                         p->setValue( *it2 );
    00206
    00207                         paramList_.append(p);
    00208                 }
    00209         }
    00210
    00211         // Create a new value of the correct type.
    00212
    00213         valueType_ = EntityTypeToValueType(entityType_);
    00214
    00215 //      kdDebug(5710) << "valueType: " << valueType_ << endl;
    00216
    00217         switch (valueType_) {
    00218
    00219                 case ValueSound:        value_ = new SoundValue;        break;
    00220                 case ValueAgent:        value_ = new AgentValue;        break;
    00221                 case ValueAddress:      value_ = new AdrValue;          break;
    00222                 case ValueTel:          value_ = new TelValue;          break;
    00223                 case ValueTextBin:      value_ = new TextBinValue;      break;
    00224                 case ValueOrg:          value_ = new OrgValue;          break;
    00225                 case ValueN:            value_ = new NValue;            break;
    00226                 case ValueUTC:          value_ = new UTCValue;          break;
    00227                 case ValueURI:          value_ = new URIValue;          break;
    00228                 case ValueClass:        value_ = new ClassValue;        break;
    00229                 case ValueFloat:        value_ = new FloatValue;        break;
    00230                 case ValueImage:        value_ = new ImageValue;        break;
    00231                 case ValueDate:         value_ = new DateValue;         break;
    00232                 case ValueTextList:     value_ = new TextListValue;     break;
    00233                 case ValueGeo:          value_ = new GeoValue;          break;
    00234                 case ValueText:
    00235                 case ValueUnknown:
    00236                 default:                value_ = new TextValue;         break;
    00237         }
    00238
    00239         *value_ = valuePart;
    00240 }
    00241
    00242         void
    00243 ContentLine::_assemble()
    00244 {
    00245         vDebug("Assemble (argl) - my name is \"" + name_ + "\"");
    00246         strRep_.truncate(0);
    00247
    00248         QCString line;
    00249
    00250         if (!group_.isEmpty())
    00251                 line += group_ + '.';
    00252
    00253         line += name_;
    00254
    00255         vDebug("Adding parameters");
    00256         ParamListIterator it(paramList_);
    00257
    00258         for (; it.current(); ++it)
    00259                 line += ";" + it.current()->asString();
    00260
    00261         vDebug("Adding value");
    00262         if (value_ != 0)
    00263                 line += ":" + value_->asString();
    00264         else
    00265                 vDebug("No value");
    00266
    00267         // Quote newlines
    00268         line = line.replace( QRegExp( "\n" ), "\\n" );
    00269
    00270         // Fold lines longer than 72 chars
    00271         const int maxLen = 72;
    00272         uint cursor = 0;
    00273         while( line.length() > ( cursor + 1 ) * maxLen ) {
    00274                 strRep_ += line.mid( cursor * maxLen, maxLen );
    00275                 strRep_ += "\r\n ";
    00276                 ++cursor;
    00277         }
    00278         strRep_ += line.mid( cursor * maxLen );
    00279 }
    00280
    00281         void
    00282 ContentLine::clear()
    00283 {
    00284         group_.truncate(0);
    00285         name_.truncate(0);
    00286         paramList_.clear();
    00287         delete value_;
    00288         value_ = 0;
    00289 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:29:19 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001