コード例 #1
0
ファイル: glob_.py プロジェクト: sailfish009/oil
def ExtendedRegexEscape(s):
    # type: (str) -> str
    """
  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 pyutil.BackslashEscape(s, ERE_META_CHARS)
コード例 #2
0
ファイル: glob_.py プロジェクト: sailfish009/oil
def EreCharClassEscape(s):
    # type: (str) -> str

    # \ 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 pyutil.BackslashEscape(s, r'\^-')
コード例 #3
0
ファイル: string_ops.py プロジェクト: dotmpe/oil
def ShellQuoteB(s):
    # type: (str) -> str
    """Quote by adding backslashes.

  Used for autocompletion, so it's friendlier for display on the command line.
  We use the strategy above for other use cases.
  """
    # 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 pyutil.BackslashEscape(s, ' `~!$&*()[]{}\\|;\'"<>?')
コード例 #4
0
 def Escape(self, s):
     # type: (str) -> str
     # Note the characters here are DYNAMIC, unlike other usages of
     # BackslashEscape().
     return pyutil.BackslashEscape(s, self.escape_chars)
コード例 #5
0
ファイル: glob_.py プロジェクト: sailfish009/oil
def GlobEscape(s):
    # type: (str) -> str
    """
  For SingleQuoted, DoubleQuoted, and EscapedLiteral
  """
    return pyutil.BackslashEscape(s, GLOB_META_CHARS)