Пример #1
0
def ExtendedRegexEscape(s):
    """
  Quoted parts need to be regex-escaped when quoted, e.g. [[ $a =~ "{" ]].  I
  don't think libc has a function to do this.  Escape these characters:

  https://www.gnu.org/software/sed/manual/html_node/ERE-syntax.html
  """
    return util.BackslashEscape(s, ERE_META_CHARS)
Пример #2
0
def EreCharClassEscape(s):
    # \ is escaping
    # ^ would invert it at the front,
    # - is range
    #
    # ] would close it -- but there is a weird posix rule where it has to be put
    # FIRST.  Like []abc].
    return util.BackslashEscape(s, r'\^-')
Пример #3
0
def ShellQuoteB(s):
  """Quote by adding backslashes.

  This is friendlier for display on the command line.
  TODO: We could also use this strategy for printf %q?
  """
  # There's no way to escape a newline!  Bash prints ^J for some reason, but
  # we're more explicit.  This will happen if there's a newline on a file
  # system or a completion plugin returns a newline.

  # NOTE: tabs CAN be escaped with \.
  s = s.replace('\r', '<INVALID CR>').replace('\n', '<INVALID NEWLINE>')

  # ~ for home dir
  # ! for history
  # * [] ? for glob
  # {} for brace expansion
  # space because it separates words
  return util.BackslashEscape(s, ' `~!$&*()[]{}\\|;\'"<>?')
Пример #4
0
 def testLog(self):
     print(util.BackslashEscape('foo', 'o'))
Пример #5
0
 def Escape(self, s):
   # Note the characters here are DYNAMIC, unlike other usages of
   # BackslashEscape().
   return util.BackslashEscape(s, self.escape_chars)
Пример #6
0
def GlobEscape(s):
    # type: (str) -> str
    """
  For SingleQuoted, DoubleQuoted, and EscapedLiteral
  """
    return util.BackslashEscape(s, GLOB_META_CHARS)
Пример #7
0
def ExtendedRegexEscape(s):
  """
  For [[ foo =~ $\{ ]]
  """
  return util.BackslashEscape(s, ERE_META_CHARS)
Пример #8
0
def GlobEscape(s):
  """
  For SingleQuotedPart, DoubleQuotedPart, and EscapedLiteralPart
  """
  return util.BackslashEscape(s, GLOB_META_CHARS)