parse method

  1. @override
AddressBookParsedResult? parse(
  1. Result result
)
override

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) {
  final rawText = ResultParser.getMassagedText(result);
  if (!rawText.startsWith('MECARD:')) {
    return null;
  }
  final rawName = matchDoCoMoPrefixedField('N:', rawText);
  if (rawName == null) {
    return null;
  }
  final name = _parseName(rawName[0]);
  final pronunciation =
      matchSingleDoCoMoPrefixedField('SOUND:', rawText, true);
  final phoneNumbers = matchDoCoMoPrefixedField('TEL:', rawText);
  final emails = matchDoCoMoPrefixedField('EMAIL:', rawText);
  final note = matchSingleDoCoMoPrefixedField('NOTE:', rawText, false);
  final addresses = matchDoCoMoPrefixedField('ADR:', rawText);
  final birthday = matchSingleDoCoMoPrefixedField('BDAY:', rawText, true);
  final urls = matchDoCoMoPrefixedField('URL:', rawText);

  // Although ORG may not be strictly legal in MECARD, it does exist in VCARD and we might as well
  // honor it when found in the wild.
  final org = matchSingleDoCoMoPrefixedField('ORG:', rawText, true);

  return AddressBookParsedResult.full(
    maybeWrap(name),
    null,
    pronunciation,
    phoneNumbers,
    null,
    emails,
    null,
    null,
    note,
    addresses,
    null,
    org,
    // No reason to throw out the whole card because the birthday is formatted wrong.
    !isStringOfDigits(birthday, 8) ? null : birthday,
    null,
    urls,
    null,
  );
}