KCalCore Library
Go to the documentation of this file.
37 #include <QtCore/QRegExp>
38 #include <QtCore/QDataStream>
47 class KCalCore::Person::Private
50 Private() : mCount(0) {}
81 d->mName == person.d->mName &&
82 d->mEmail == person.d->mEmail;
87 return !(*
this == person);
93 if (&person ==
this) {
103 if (d->mName.isEmpty()) {
106 if (d->mEmail.isEmpty()) {
110 QString
name = d->mName;
111 QRegExp needQuotes(QLatin1String(
"[^ 0-9A-Za-z\\x0080-\\xFFFF]"));
112 bool weNeedToQuote =
name.indexOf(needQuotes) != -1;
114 if (
name[0] != QLatin1Char(
'"')) {
115 name.prepend(QLatin1Char(
'"'));
117 if (
name[
name.length()-1 ] != QLatin1Char(
'"')) {
118 name.append(QLatin1Char(
'"'));
121 return name + QLatin1String(
" <") + d->mEmail + QLatin1Char(
'>');
138 return d->mEmail.isEmpty() && d->mName.isEmpty();
148 if (
email.startsWith(QLatin1String(
"mailto:"), Qt::CaseInsensitive)) {
149 d->mEmail =
email.mid(7);
157 int pos =
email.lastIndexOf(QLatin1String(
"@"));
158 return (pos > 0) && (
email.lastIndexOf(QLatin1String(
".")) > pos) && ((
email.length() - pos) > 4);
178 return stream << person->d->mName
180 << person->d->mCount;
188 stream >> name >> email >> count;
191 person_tmp->setCount(count);
192 person.swap(person_tmp);
199 static bool extractEmailAddressAndName(
const QString &aStr, QString &mail, QString &name)
204 const int len = aStr.length();
205 const char cQuotes =
'"';
207 bool bInComment =
false;
208 bool bInQuotesOutsideOfEmail =
false;
209 int i=0, iAd=0, iMailStart=0, iMailEnd=0;
211 unsigned int commentstack = 0;
217 if (QLatin1Char(
'(') == c) {
220 if (QLatin1Char(
')') == c) {
223 bInComment = commentstack != 0;
224 if (QLatin1Char(
'"') == c && !bInComment) {
225 bInQuotesOutsideOfEmail = !bInQuotesOutsideOfEmail;
228 if (!bInComment && !bInQuotesOutsideOfEmail) {
229 if (QLatin1Char(
'@') == c) {
241 for (i = 0; len > i; ++i) {
243 if (QLatin1Char(
'<') != c) {
249 mail = aStr.mid(i + 1);
250 if (mail.endsWith(QLatin1Char(
'>'))) {
251 mail.truncate(mail.length() - 1);
259 bInQuotesOutsideOfEmail =
false;
260 for (i = iAd-1; 0 <= i; --i) {
263 if (QLatin1Char(
'(') == c) {
264 if (!name.isEmpty()) {
265 name.prepend(QLatin1Char(
' '));
271 }
else if (bInQuotesOutsideOfEmail) {
272 if (QLatin1Char(cQuotes) == c) {
273 bInQuotesOutsideOfEmail =
false;
274 }
else if (c != QLatin1Char(
'\\')) {
279 if (QLatin1Char(
',') == c) {
284 if (QLatin1Char(cQuotes) == c) {
285 bInQuotesOutsideOfEmail =
true;
290 switch (c.toLatin1()) {
295 if (!name.isEmpty()) {
296 name.prepend(QLatin1Char(
' '));
301 if (QLatin1Char(
' ') != c) {
309 name = name.simplified();
310 mail = mail.simplified();
312 if (mail.isEmpty()) {
316 mail.append(QLatin1Char(
'@'));
322 bInQuotesOutsideOfEmail =
false;
323 int parenthesesNesting = 0;
324 for (i = iAd+1; len > i; ++i) {
327 if (QLatin1Char(
')') == c) {
328 if (--parenthesesNesting == 0) {
330 if (!name.isEmpty()) {
331 name.append(QLatin1Char(
' '));
335 name.append(QLatin1Char(
')'));
338 if (QLatin1Char(
'(') == c) {
340 ++parenthesesNesting;
344 }
else if (bInQuotesOutsideOfEmail) {
345 if (QLatin1Char(cQuotes) == c) {
346 bInQuotesOutsideOfEmail =
false;
347 }
else if (c != QLatin1Char(
'\\')) {
352 if (QLatin1Char(
',') == c) {
357 if (QLatin1Char(cQuotes) == c) {
358 bInQuotesOutsideOfEmail =
true;
363 switch (c.toLatin1()) {
368 if (!name.isEmpty()) {
369 name.append(QLatin1Char(
' '));
371 if (++parenthesesNesting > 0) {
376 if (QLatin1Char(
' ') != c) {
385 name = name.simplified();
386 mail = mail.simplified();
388 return !(name.isEmpty() || mail.isEmpty());
QString fullName() const
Returns the full name of this person.
bool operator==(const Person &person) const
Compares this with person for equality.
Represents a person, by name and email address.
static bool isValidEmail(const QString &email)
Returns true if person's email address is valid.
QString name() const
Returns the person name string.
QSharedPointer< Person > Ptr
A shared pointer to a Person object.
QString email() const
Returns the email address for this person.
int count() const
Returns the number of references or zero if it is not initialized.
KCALCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalCore::Alarm::Ptr &)
Alarm deserializer.
bool isEmpty() const
Returns true if the person name and email address are empty.
Person & operator=(const Person &person)
Sets this person equal to person.
uint qHash(const KCalCore::Person &key)
Return a hash value for a Person argument.
bool operator!=(const Person &person) const
Compares this with person for non-equality.
void setCount(int count)
Sets the number of references for this person.
Person()
Constructs a blank person.
void setEmail(const QString &email)
Sets the email address for this person to email.
static Person::Ptr fromFullName(const QString &fullName)
Constructs a person with name and email address taken from fullName.
void setName(const QString &name)
Sets the name of the person to name.
virtual ~Person()
Destroys a person.
KCALCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalCore::Alarm::Ptr &)
Alarm serializer.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Jul 28 2020 00:00:00 by
doxygen 1.8.18 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.