parse method

  1. @override
TelParsedResult? 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
TelParsedResult? parse(Result result) {
  final rawText = ResultParser.getMassagedText(result);
  if (!rawText.startsWith('tel:') && !rawText.startsWith('TEL:')) {
    return null;
  }
  // Normalize "TEL:" to "tel:"
  final telURI =
      rawText.startsWith('TEL:') ? 'tel:${rawText.substring(4)}' : rawText;
  // Drop tel, query portion
  final queryStart = rawText.indexOf('?', 4);
  final number = queryStart < 0
      ? rawText.substring(4)
      : rawText.substring(4, queryStart);
  return TelParsedResult(number, telURI, null);
}