code: def match_main(self, text, pattern, loc):
      
      # Check for null inputs.
      if text == None or pattern == None:
        raise ValueError("Null inputs. (match_main)")
  
      loc = max(0, min(loc, len(text)))
      if text == pattern:
        # Shortcut (potentially not guaranteed by the algorithm)
        return 0
      elif not text:
        # Nothing to match.
        return -1
      elif text[loc:loc + len(pattern)] == pattern:
        # Perfect match at the perfect spot!  (Includes case of null pattern)
        return loc
      else:
        # Do a fuzzy compare.
        match = self.match_bitap(text, pattern, loc)
        return match
docs: Locate the best instance of 'pattern' in 'text' near 'loc'.
  
      Args:
        text: The text to search.
        pattern: The pattern to search for.
        loc: The location to search around.
  
      Returns:
        Best match index or -1.