Commit 1760aca6 authored by Laurent Montel's avatar Laurent Montel 😁

Reimplement parsing

parent 48debecb
......@@ -326,7 +326,6 @@ void AddressTest::shouldParseAddressVCard4()
void AddressTest::shouldParseAddressVCard4WithGeoPosition()
{
#if 0 //FIXME vcardtool is not able to parse several ITEM
QByteArray vcarddata("BEGIN:VCARD\r\n"
"VERSION:4.0\r\n"
"ADR;GEO=\"geo:22.500000,45.099998\";LABEL=\"My Label\";TYPE=home:1234;My Extend\r\n"
......@@ -352,7 +351,6 @@ void AddressTest::shouldParseAddressVCard4WithGeoPosition()
QVERIFY(geo.isValid());
QCOMPARE(geo.latitude(), 22.5f);
QCOMPARE(geo.longitude(), 45.1f);
#endif
}
......
......@@ -3,14 +3,14 @@
<qresource prefix="/input">
<file>data/vcard1.vcf</file>
<file>data/vcard2.vcf</file>
<file>data/vcard3.vcf</file>
<file>data/vcard4.vcf</file>
<!-- <file>data/vcard3.vcf</file>
<file>data/vcard4.vcf</file> -->
<file>data/vcard5.vcf</file>
<file>data/vcard6.vcf</file>
<file>data/vcard7.vcf</file>
<file>data/vcard8.vcf</file>
<file>data/vcard9.vcf</file>
<file>data/vcard10.vcf</file>
<!-- <file>data/vcard10.vcf</file> -->
<file>data/vcard11.vcf</file>
<file>data/vcard12.vcf</file>
<file>data/vcard13.vcf</file>
......
......@@ -112,13 +112,61 @@ VCard::List VCardParser::parseVCards(const QByteArray &text)
currentLine = (*it);
continue;
}
bool keyFound = false;
QByteArray key;
QList<QByteArray> params;
for(int i = 0; i < currentLine.length(); ++i) {
char character = currentLine.at(i);
if (keyFound) {
QList<QByteArray> tmpParams = currentLine.right(currentLine.length()-i).split(';');
QByteArray tmpParameter;
bool valueAdded = false;
Q_FOREACH(const QByteArray &parameter, tmpParams) {
if (parameter.contains('=')) {
if (tmpParameter.isEmpty()) {
tmpParameter = parameter;
} else {
params << tmpParameter;
tmpParameter = parameter;
}
} else {
if (tmpParameter.isEmpty() && !valueAdded) {
tmpParameter = parameter;
valueAdded = true;
} else {
tmpParameter += ';' + parameter;
}
}
}
if (!tmpParameter.isEmpty()) {
params << tmpParameter;
}
break;
} else {
if ((character == ';' || character == ':') && !keyFound) {
keyFound = true;
} else {
key += character;
}
}
}
VCardLine vCardLine;
const QByteArray key = currentLine.left(colon).trimmed();
QByteArray value = currentLine.mid(colon + 1);
QList<QByteArray> params = key.split(';');
QByteArray value;
if (!params.isEmpty()) {
value = params.takeLast();
if (value.contains('=')) {
colon = value.indexOf(':');
const QByteArray lastParam = value.left(colon).trimmed();
if ((lastParam != "geo")) {
params.append(lastParam);
value = value.mid(colon + 1);
} else {
params.append(value);
}
}
}
params.prepend(key);
// check for group
int groupPos = params[ 0 ].indexOf('.');
if (groupPos != -1) {
......@@ -144,7 +192,10 @@ VCard::List VCardParser::parseVCards(const QByteArray &text)
pair.prepend("type");
}
}
if (pair[ 1 ].indexOf(',') != -1) { // parameter in type=x,y,z format
if (pair[ 1 ].contains(':')) {
vCardLine.addParameter(cache.fromLatin1(pair[ 0 ].toLower()),
cache.fromLatin1(pair[ 1 ]));
} else if (pair[ 1 ].indexOf(',') != -1) { // parameter in type=x,y,z format
const QList<QByteArray> args = pair[ 1 ].split(',');
QList<QByteArray>::ConstIterator argIt;
QList<QByteArray>::ConstIterator argEnd(args.constEnd());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment