parse

fun parse(input: String): VCard

Parses the given string into a VCard object.

Though according to RFC 6350 there are some requirements and restrictions on how a vCard String should be structured, this parsing method tries to be as forgiving as possible with the given input.

If the BEGIN:VCARD and/or END:VCARD property is missing the card will still be parsed. Currently even the VERSION property is ignored for the time being because the parser currently is only supporting version 4.0. E The parser even doesn't care if the VERSION is there or not. And if a property line has no ":" to separate the property name from the property value it just assumes that it is the FN property.

So the following vCard-String

BEGIN:VCARD
VERSION:4.0
FN:Arthur Dent
END:VCARD

would lead to the same result if the parser would have just parsed the String "Arthur Dent" and parse to the same card as:

VCard("Arthur Dent")

Linebreaks

The parser does not actually care about which of the commonly used linebreak characters and combinations are used. Either \r\n, \n or \r will be accepted. Even if one vCard uses different line breaks.

Case-Sensitivity

As described in RFC 6350 some parts are case-insensitive, so for example the property groups or property names will be recognized no matter if they ar lower or upper case or a combination of both.

bEgIn:VCARD
versION:4.0
fn:Arthur Dent
END:VCARD

will parse to the same card as:

VCard("Arthur Dent")

Value Escaping

Because some characters might have special meaning and others are used for text formatting and some lines might get long but should be displayed wrapped without actually wrapping the content at the vCards wrapping position there are some escape and wrapping techniques that will be taken into account while parsing the input.

BEGIN:VCARD
VERSION:4.0
FN:Arthur Dent
NOTE:Along with Ford Prefect\, Arthur Dent barely escapes the Earth's
destruction as it is demolished to make way for a hyperspace bypass.
END:VCARD

will parse to the same card as:

VCard("Arthur Dent")
.property(Note("Along with Ford Prefect, Arthur Dent barely escapes the Earth's destruction" +
" as it is demolished to make way for a hyperspace bypass."))

Invalid Content

Invalid Properties will be ignored.

BEGIN:VCARD
VERSION:4.0
FN:Arthur Dent
INVALID:property
NON:existing
END:VCARD

will parse to the same card as:

VCard("Arthur Dent")

Invalid Parameters will be ignored.

BEGIN:VCARD
VERSION:4.0
FN;INVALID=param;NON=existing:Arthur Dent
END:VCARD

will parse to the same card as:

VCard("Arthur Dent")

Return

a VCard that represents the given string.

Parameters

input

the string to be parsed.