parse method
Attempts to parse the raw Result's contents as a particular type of information (email, URL, etc.) and return a ParsedResult encapsulating the result of parsing.
@param theResult the raw Result to parse @return ParsedResult encapsulating the parsing result
Implementation
@override
AddressBookParsedResult? parse(Result result) {
// Although we should insist on the raw text ending with "END:VCARD", there's no reason
// to throw out everything else we parsed just because this was omitted. In fact, Eclair
// is doing just that, and we can't parse its contacts without this leniency.
final rawText = ResultParser.getMassagedText(result);
if (!_beginVcard.hasMatch(rawText)) {
return null;
}
List<List<String>>? names =
matchVCardPrefixedField('FN', rawText, true, false);
if (names == null) {
// If no display names found, look for regular name fields and format them
names = matchVCardPrefixedField('N', rawText, true, false);
_formatNames(names);
}
final nicknameString =
matchSingleVCardPrefixedField('NICKNAME', rawText, true, false);
final nicknames =
nicknameString == null ? null : nicknameString[0].split(_comma);
final phoneNumbers = matchVCardPrefixedField('TEL', rawText, true, false);
final emails = matchVCardPrefixedField('EMAIL', rawText, true, false);
final note = matchSingleVCardPrefixedField('NOTE', rawText, false, false);
final addresses = matchVCardPrefixedField('ADR', rawText, true, true);
final org = matchSingleVCardPrefixedField('ORG', rawText, true, true);
final birthday =
matchSingleVCardPrefixedField('BDAY', rawText, true, false);
final title = matchSingleVCardPrefixedField('TITLE', rawText, true, false);
final urls = matchVCardPrefixedField('URL', rawText, true, false);
final instantMessenger =
matchSingleVCardPrefixedField('IMPP', rawText, true, false);
final geoString =
matchSingleVCardPrefixedField('GEO', rawText, true, false);
List<String>? geo =
geoString == null ? null : geoString[0].split(_semicolonOrComma);
if (geo != null && geo.length != 2) {
geo = null;
}
return AddressBookParsedResult.full(
_toPrimaryValues(names),
nicknames,
null,
_toPrimaryValues(phoneNumbers),
_toTypes(phoneNumbers),
_toPrimaryValues(emails),
_toTypes(emails),
_toPrimaryValue(instantMessenger),
_toPrimaryValue(note),
_toPrimaryValues(addresses),
_toTypes(addresses),
_toPrimaryValue(org),
_toPrimaryValue(
(birthday != null && !_isLikeVCardDate(birthday[0])) ? null : birthday,
),
_toPrimaryValue(title),
_toPrimaryValues(urls),
geo,
);
}