parse method

  1. @override
URIParsedResult? 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
URIParsedResult? parse(Result result) {
  String rawText = ResultParser.getMassagedText(result);
  // We specifically handle the odd "URL" scheme here for simplicity and add "URI" for fun
  // Assume anything starting this way really means to be a URI
  if (rawText.startsWith('URL:') || rawText.startsWith('URI:')) {
    return URIParsedResult(rawText.substring(4).trim(), null);
  }
  rawText = rawText.trim();
  if (!isBasicallyValidURI(rawText) || isPossiblyMaliciousURI(rawText)) {
    return null;
  }
  return URIParsedResult(rawText, null);
}