parameters: (s)
return_statement: return s
docstring: Escapes command line arguments for MSVS.
  
    The VCProj format stores string lists in a single string using commas and
    semi-colons as separators, which must be quoted if they are to be
    interpreted literally. However, command-line arguments may already have
    quotes, and the VCProj parser is ignorant of the backslash escaping
    convention used by CommandLineToArgv, so the command-line quotes and the
    VCProj quotes may not be the same quotes. So to store a general
    command-line argument in a VCProj list, we need to parse the existing
    quoting according to VCProj's convention and quote any delimiters that are
    not already quoted by that convention. The quotes that we add will also be
    seen by CommandLineToArgv, so if backslashes precede them then we also have
    to escape those backslashes according to the CommandLineToArgv
    convention.
  
    Args:
        s: the string to be escaped.
    Returns:
        the escaped string.
docstring_summary: Escapes command line arguments for MSVS.
docstring_tokens: Escapes command line arguments for MSVS .
function: def _EscapeVCProjCommandLineArgListItem(s):
    """Escapes command line arguments for MSVS.
  
    The VCProj format stores string lists in a single string using commas and
    semi-colons as separators, which must be quoted if they are to be
    interpreted literally. However, command-line arguments may already have
    quotes, and the VCProj parser is ignorant of the backslash escaping
    convention used by CommandLineToArgv, so the command-line quotes and the
    VCProj quotes may not be the same quotes. So to store a general
    command-line argument in a VCProj list, we need to parse the existing
    quoting according to VCProj's convention and quote any delimiters that are
    not already quoted by that convention. The quotes that we add will also be
    seen by CommandLineToArgv, so if backslashes precede them then we also have
    to escape those backslashes according to the CommandLineToArgv
    convention.
  
    Args:
        s: the string to be escaped.
    Returns:
        the escaped string.
    """
  
    def _Replace(match):
      # For a non-literal quote, CommandLineToArgv requires an even number of
      # backslashes preceding it, and it produces half as many literal
      # backslashes. So we need to produce 2n backslashes.
      return 2 * match.group(1) + '"' + match.group(2) + '"'
  
    segments = s.split('"')
    # The unquoted segments are at the even-numbered indices.
    for i in range(0, len(segments), 2):
      segments[i] = delimiters_replacer_regex.sub(_Replace, segments[i])
    # Concatenate back into a single string
    s = '"'.join(segments)
    if len(segments) % 2 == 0:
      # String ends while still quoted according to VCProj's convention. This
      # means the delimiter and the next list item that follow this one in the
      # .vcproj file will be misinterpreted as part of this item. There is nothing
      # we can do about this. Adding an extra quote would correct the problem in
      # the VCProj but cause the same problem on the final command-line. Moving
      # the item to the end of the list does works, but that's only possible if
      # there's only one such item. Let's just warn the user.
      print >> sys.stderr, ('Warning: MSVS may misinterpret the odd number of ' +
                            'quotes in ' + s)
    return s
function_tokens: def _EscapeVCProjCommandLineArgListItem ( s ) : def _Replace ( match ) : # For a non-literal quote, CommandLineToArgv requires an even number of # backslashes preceding it, and it produces half as many literal # backslashes. So we need to produce 2n backslashes. return 2 * match . group ( 1 ) + '"' + match . group ( 2 ) + '"' segments = s . split ( '"' ) # The unquoted segments are at the even-numbered indices. for i in range ( 0 , len ( segments ) , 2 ) : segments [ i ] = delimiters_replacer_regex . sub ( _Replace , segments [ i ] ) # Concatenate back into a single string s = '"' . join ( segments ) if len ( segments ) % 2 == 0 : # String ends while still quoted according to VCProj's convention. This # means the delimiter and the next list item that follow this one in the # .vcproj file will be misinterpreted as part of this item. There is nothing # we can do about this. Adding an extra quote would correct the problem in # the VCProj but cause the same problem on the final command-line. Moving # the item to the end of the list does works, but that's only possible if # there's only one such item. Let's just warn the user. print >> sys . stderr , ( 'Warning: MSVS may misinterpret the odd number of ' + 'quotes in ' + s ) return s