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);
  // MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF
  if (!rawText.contains('MEMORY') || !rawText.contains('\r\n')) {
    return null;
  }

  // NAME1 and NAME2 have specific uses, namely written name and pronunciation, respectively.
  // Therefore we treat them specially instead of as an array of names.
  final name = matchSinglePrefixedField('NAME1:', rawText, '\r', true);
  final pronunciation =
      matchSinglePrefixedField('NAME2:', rawText, '\r', true);

  final phoneNumbers = _matchMultipleValuePrefix('TEL', rawText);
  final emails = _matchMultipleValuePrefix('MAIL', rawText);
  final note = matchSinglePrefixedField('MEMORY:', rawText, '\r', false);
  final address = matchSinglePrefixedField('ADD:', rawText, '\r', true);
  final addresses = address == null ? null : [address];
  return AddressBookParsedResult.full(
    maybeWrap(name),
    null,
    pronunciation,
    phoneNumbers,
    null,
    emails,
    null,
    null,
    note,
    addresses,
    null,
    null,
    null,
    null,
    null,
    null,
  );
}