def _patternToRegEx()

in scripts/yapl/Trace.py [0:0]


  def _patternToRegEx(self,pattern):
    """
      Return a Python/Jython regular expression string that represents the given pattern.
    """
    if (pattern == "*"):
      # special case that matches anything
      regex = ".*?"
    else:
      regex = pattern
      if (regex.find(".") >= 0):
        regex = regex.replace(".", "\.")
      #endIf
      
      asteriskIndex = regex.find("*")
      if (asteriskIndex < 0):
        # no wildcard in pattern
        regex = "%s$" % regex
      elif (asteriskIndex + 1 != len(regex)):
        raise TraceSpecificationException("Invalid entity pattern: %s. A wildcard character may only be used to terminate a pattern." % pattern)
      else:
        # remove * and add ".*?"
        regex = "%s.*?" % regex[:-1]
      #endIf
    #endIf
    return regex