data/VCardWriter.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | // Internal write helpers of VCardCodec, shared by VCardPatch.cpp (Sprint 97 | ||
| 4 | // fields) and VCardPeoplePatch.cpp (Sprint 103 people details). Not part of | ||
| 5 | // the codec's public API: only the codec's own .cpp files include it. | ||
| 6 | |||
| 7 | #include <QList> | ||
| 8 | #include <QString> | ||
| 9 | #include <QStringList> | ||
| 10 | |||
| 11 | #include "data/ContactModels.h" | ||
| 12 | #include "data/ICalendar.h" | ||
| 13 | |||
| 14 | namespace VCardCodec::detail { | ||
| 15 | |||
| 16 | // The card being patched plus, per property, its index in the parsed base | ||
| 17 | // (-1 for created lines). Values refer to base indices (sourceIndex); every | ||
| 18 | // insertion and removal goes through the helpers so that mapping holds. | ||
| 19 | struct Writer { | ||
| 20 | ICal::Component card; | ||
| 21 | QList<int> origin; | ||
| 22 | bool v4 = false; | ||
| 23 | bool changed = false; | ||
| 24 | |||
| 25 |
1/2✓ Branch 2 → 3 taken 6098 times.
✗ Branch 2 → 5 not taken.
|
6098 | int currentIndex(int baseIndex) const { return baseIndex < 0 ? -1 : int(origin.indexOf(baseIndex)); } |
| 26 | 109152 | void insert(int position, const ICal::Property &property) { | |
| 27 |
1/1✓ Branch 3 → 4 taken 109152 times.
|
109152 | position = qBound(0, position, int(card.properties.size())); |
| 28 | 109152 | card.properties.insert(position, property); | |
| 29 | 109152 | origin.insert(position, -1); | |
| 30 | 109152 | changed = true; | |
| 31 | 109152 | } | |
| 32 | 76720 | void append(const ICal::Property &property) { insert(int(card.properties.size()), property); } | |
| 33 | 78 | void removeAt(int position) { | |
| 34 | 78 | card.properties.removeAt(position); | |
| 35 | 78 | origin.removeAt(position); | |
| 36 | 78 | changed = true; | |
| 37 | 78 | } | |
| 38 | 699 | template <typename Predicate> void removeWhere(Predicate predicate) { | |
| 39 |
8/8void VCardCodec::detail::Writer::removeWhere<VCardCodec::detail::setMembers(VCardCodec::detail::Writer*, QList<QString> const&)::{lambda(ICal::Property const&)#1}>(VCardCodec::detail::setMembers(VCardCodec::detail::Writer*, QList<QString> const&)::{lambda(ICal::Property const&)#1}):
✓ Branch 9 → 4 taken 309 times.
✓ Branch 9 → 10 taken 51 times.
void VCardCodec::detail::Writer::removeWhere<VCardCodec::detail::setCategories(VCardCodec::detail::Writer*, QList<QString> const&)::{lambda(ICal::Property const&)#1}>(VCardCodec::detail::setCategories(VCardCodec::detail::Writer*, QList<QString> const&)::{lambda(ICal::Property const&)#1}):
✓ Branch 9 → 4 taken 2495 times.
✓ Branch 9 → 10 taken 303 times.
void VCardCodec::detail::Writer::removeWhere<VCardCodec::detail::removeWithGroup(VCardCodec::detail::Writer*, int)::{lambda(ICal::Property const&)#1}>(VCardCodec::detail::removeWithGroup(VCardCodec::detail::Writer*, int)::{lambda(ICal::Property const&)#1}):
✓ Branch 9 → 4 taken 165 times.
✓ Branch 9 → 10 taken 12 times.
void VCardCodec::detail::Writer::removeWhere<VCardCodec::detail::setPhoto(VCardCodec::detail::Writer*, ContactPhoto const&)::{lambda(ICal::Property const&)#1}>(VCardCodec::detail::setPhoto(VCardCodec::detail::Writer*, ContactPhoto const&)::{lambda(ICal::Property const&)#1}):
✓ Branch 9 → 4 taken 3145 times.
✓ Branch 9 → 10 taken 333 times.
|
6813 | for (int i = int(card.properties.size()) - 1; i >= 0; --i) |
| 40 |
8/8void VCardCodec::detail::Writer::removeWhere<VCardCodec::detail::setMembers(VCardCodec::detail::Writer*, QList<QString> const&)::{lambda(ICal::Property const&)#1}>(VCardCodec::detail::setMembers(VCardCodec::detail::Writer*, QList<QString> const&)::{lambda(ICal::Property const&)#1}):
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 308 times.
void VCardCodec::detail::Writer::removeWhere<VCardCodec::detail::setCategories(VCardCodec::detail::Writer*, QList<QString> const&)::{lambda(ICal::Property const&)#1}>(VCardCodec::detail::setCategories(VCardCodec::detail::Writer*, QList<QString> const&)::{lambda(ICal::Property const&)#1}):
✓ Branch 6 → 7 taken 4 times.
✓ Branch 6 → 8 taken 2491 times.
void VCardCodec::detail::Writer::removeWhere<VCardCodec::detail::removeWithGroup(VCardCodec::detail::Writer*, int)::{lambda(ICal::Property const&)#1}>(VCardCodec::detail::removeWithGroup(VCardCodec::detail::Writer*, int)::{lambda(ICal::Property const&)#1}):
✓ Branch 6 → 7 taken 12 times.
✓ Branch 6 → 8 taken 153 times.
void VCardCodec::detail::Writer::removeWhere<VCardCodec::detail::setPhoto(VCardCodec::detail::Writer*, ContactPhoto const&)::{lambda(ICal::Property const&)#1}>(VCardCodec::detail::setPhoto(VCardCodec::detail::Writer*, ContactPhoto const&)::{lambda(ICal::Property const&)#1}):
✓ Branch 6 → 7 taken 4 times.
✓ Branch 6 → 8 taken 3141 times.
|
6114 | if (predicate(card.properties.at(i))) |
| 41 | 21 | removeAt(i); | |
| 42 | 699 | } | |
| 43 | }; | ||
| 44 | |||
| 45 | // First property with that base name (groups ignored), -1 when none. | ||
| 46 | int indexOfName(const ICal::Component &card, const QString &name); | ||
| 47 | // BDAY-style wire date: 4.0 "YYYYMMDD"/"--MMDD", 3.0 "YYYY-MM-DD" or | ||
| 48 | // Apple's "1604-MM-DD" placeholder for a date without year. | ||
| 49 | QString dateWire(const PartialDate &date, bool v4); | ||
| 50 | // The next unused "itemN" group name. | ||
| 51 | QString freeGroup(const ICal::Component &card); | ||
| 52 | // Index of the X-ABLabel line of a group, -1 when none. | ||
| 53 | int labelIndex(const ICal::Component &card, const QString &group); | ||
| 54 | // Sets, changes or clears the X-ABLabel of the property at `index` | ||
| 55 | // (groups the property when it had none). | ||
| 56 | void setLabel(Writer *w, int index, const QString &label); | ||
| 57 | // Replaces TYPE/PREF parameters (4.0 lower case + PREF=1, 3.0 upper case + | ||
| 58 | // TYPE=pref). | ||
| 59 | void setTypes(ICal::Property *property, const QStringList &types, bool preferred, bool v4); | ||
| 60 | // Removes the property at `index` and, when nothing else uses its group, | ||
| 61 | // the group's label lines. | ||
| 62 | void removeWithGroup(Writer *w, int index); | ||
| 63 | |||
| 64 | // Sprint 103: applies relations, how we met, social profiles, languages, | ||
| 65 | // interests, other dates, birthplace, positions and mail links that differ | ||
| 66 | // between `before` and `after` (VCardPeoplePatch.cpp). | ||
| 67 | void applyPeople(Writer *w, const ContactCard &before, const ContactCard &after); | ||
| 68 | |||
| 69 | } // namespace VCardCodec::detail | ||
| 70 | |||
| 71 | namespace VCardCodec { | ||
| 72 | // Sprint 103 read side (VCardPeople.cpp): fills the people members of | ||
| 73 | // `card` from the content-line tree. | ||
| 74 | void readPeople(const ICal::Component &tree, ContactCard *card); | ||
| 75 | } // namespace VCardCodec | ||
| 76 |