parameters: (self, android_string, inside_placeholder=False)
return_statement: return output
docstring: r"""Returns android_string formatted for a .grd file.
  
        * Collapses consecutive whitespaces, except when inside double-quotes.
        * Replaces \\, \n, \t, \", \' with \, newline, tab, ", '.
docstring_summary: r"""Returns android_string formatted for a .grd file.
docstring_tokens: r Returns android_string formatted for a . grd file .
function: def __FormatAndroidString(self, android_string, inside_placeholder=False):
      r"""Returns android_string formatted for a .grd file.
  
        * Collapses consecutive whitespaces, except when inside double-quotes.
        * Replaces \\, \n, \t, \", \' with \, newline, tab, ", '.
      """
      backslash_map = {'\\' : '\\', 'n' : '\n', 't' : '\t', '"' : '"', "'" : "'"}
      is_quoted_section = False  # True when we're inside double quotes.
      is_backslash_sequence = False  # True after seeing an unescaped backslash.
      prev_char = ''
      output = []
      for c in android_string:
        if is_backslash_sequence:
          # Unescape \\, \n, \t, \", and \'.
          assert c in backslash_map, 'Illegal escape sequence: \\%s' % c
          output.append(backslash_map[c])
          is_backslash_sequence = False
        elif c == '\\':
          is_backslash_sequence = True
        elif c.isspace() and not is_quoted_section:
          # Turn whitespace into ' ' and collapse consecutive whitespaces.
          if not prev_char.isspace():
            output.append(' ')
        elif c == '"':
          is_quoted_section = not is_quoted_section
        else:
          output.append(c)
        prev_char = c
      output = ''.join(output)
  
      if is_quoted_section:
        print('Warning: unbalanced quotes in string: %s' % android_string)
  
      if is_backslash_sequence:
        print('Warning: trailing backslash in string: %s' % android_string)
  
      # Check for format specifiers outside of placeholder tags.
      if not inside_placeholder:
        format_specifier = _FORMAT_SPECIFIER.search(output)
        if format_specifier:
          print('Warning: format specifiers are not inside a placeholder '
                '<xliff:g/> tag: %s' % output)
  
      return output
function_tokens: def __FormatAndroidString ( self , android_string , inside_placeholder = False ) : backslash_map = { '\\' : '\\' , 'n' : '\n' , 't' : '\t' , '"' : '"' , "'" : "'" } is_quoted_section = False # True when we're inside double quotes. is_backslash_sequence = False # True after seeing an unescaped backslash. prev_char = '' output = [ ] for c in android_string : if is_backslash_sequence : # Unescape \\, \n, \t, \", and \'. assert c in backslash_map , 'Illegal escape sequence: \\%s' % c output . append ( backslash_map [ c ] ) is_backslash_sequence = False elif c == '\\' : is_backslash_sequence = True elif c . isspace ( ) and not is_quoted_section : # Turn whitespace into ' ' and collapse consecutive whitespaces. if not prev_char . isspace ( ) : output . append ( ' ' ) elif c == '"' : is_quoted_section = not is_quoted_section else : output . append ( c ) prev_char = c output = '' . join ( output ) if is_quoted_section : print ( 'Warning: unbalanced quotes in string: %s' % android_string ) if is_backslash_sequence : print ( 'Warning: trailing backslash in string: %s' % android_string ) # Check for format specifiers outside of placeholder tags. if not inside_placeholder : format_specifier = _FORMAT_SPECIFIER . search ( output ) if format_specifier : print ( 'Warning: format specifiers are not inside a placeholder ' '<xliff:g/> tag: %s' % output ) return output