Function used internally to format string data for output to XML.
	Escapes back-slashes and quotes, and wraps the resulting string in
	quotes.
195826
def string_format_func(s):
	
	return u"\"%s\"" % unicode(s).replace(u"\\", u"\\\\").replace(u"\"", u"\\\"")
1145576
def prettify_xml(xml_str):
    
    parsed_xml = parseString(get_string(xml_str))
    pretty_xml = '\n'.join(
        [line for line in parsed_xml.toprettyxml(indent=' ' * 2)
         .split('\n') if line.strip()])
    if not pretty_xml.endswith('\n'):
        pretty_xml += '\n'
    return pretty_xml
507233
def to_string(self, indent="", newl="", addindent=""):
        '''
        
        '''
        buf = StringIO()
        self.to_xml().writexml(buf, indent=indent, addindent=addindent,
                               newl=newl)
        return buf.getvalue()
743959
public static String escapeXmlString(String str, boolean escapeQuots)
    {
        if (str == null) {
            return "";
        }
        StringBuffer buf = new StringBuffer();
        char[] array = str.toCharArray();
        for (int i = 0; i < array.length; i++) {
            if (array[i] == '>'
                || array[i] == '&'
                || array[i] == '<'
                || (escapeQuots && (array[i] == '\'' || array[i] == '"')))
            {
                buf.append("&#x" + Integer.toHexString(array[i]) + ";");
            } else {
                buf.append(array[i]);
            }
        }
        return buf.toString();
    }
619115
def to_string(line_prefix = "", indent = "\t")
      line_prefix = "" if line_prefix.nil?
      s = ""
      s << line_prefix
      
      if name == "content" && namespace.empty?
        skip_value_space = true
      else
        skip_value_space = false
        s << "#{namespace}:" unless namespace.empty?
        s << name
      end

      # output values
      values do |value|
        if skip_value_space
          skip_value_space = false
        else
          s << " "
        end
        s << SDL4R.format(value, true, line_prefix, indent)
      end

      # output attributes
      unless @attributesByNamespace.empty?
        all_attributes_hash = attributes
        all_attributes_array = all_attributes_hash.sort { |a, b|
          namespace1, name1 = a[0].split(':')
          namespace1, name1 = "", namespace1 if name1.nil?
          namespace2, name2 = b[0].split(':')
          namespace2, name2 = "", namespace2 if name2.nil?

          diff = namespace1 <=> namespace2
          diff == 0 ? name1 <=> name2 : diff
        }
        all_attributes_array.each do |attribute_name, attribute_value|
          s << " " << attribute_name << '=' << SDL4R.format(attribute_value, true)
        end
      end

      # output children
      unless @children.empty?
        s << " {#{$/}"
        children_to_string(line_prefix + indent, s)
        s << line_prefix << ?}
      end

      return s
    end
1020926
def to_xml_string(str = '')
      str << '<c:catAx>'
      super(str)
      str << ('<c:auto val="' << @auto.to_s << '"/>')
      str << ('<c:lblAlgn val="' << @lbl_algn.to_s << '"/>')
      str << ('<c:lblOffset val="' << @lbl_offset.to_i.to_s << '"/>')
      str << ('<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>')
      str << ('<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>')
      str << '</c:catAx>'
    end
312004
def as_fstring(text):
    
    for quote in ('"""', "'''"):
        # although script-format always ends with \n, direct use of this function might
        # have string ending with " or '
        if quote not in text and not text.endswith(quote[0]):
            return 'fr' + quote + text + quote

    # now, we need to look into the structure of f-string
    pieces = split_fstring(text)
    # if all expressions do not have single quote, we can
    # safely repr the entire string
    if not any("'" in piece for piece in pieces[1::2]):
        return 'f' + repr(text)
    #
    # unfortunately, this thing has both single and double triple quotes
    # because we cannot use backslash inside expressions in f-string, we
    # have to use format string now.
    args = []
    for idx in range(len(pieces))[1::2]:
        pos = valid_expr_till(pieces[idx])
        if pos == 0:
            raise SyntaxError(f'invalid expression in {pieces[idx]}')
        args.append(pieces[idx][:pos])
        pieces[idx] = '{' + str(idx // 2) + pieces[idx][pos:] + '}'
    return repr(''.join(pieces)) + '.format(' + ', '.join(args) + ')'
557177
private static String _escapeXML(String value) {
        int len = value.length();
        if (0 == len) {
            return value;
        }
        StringBuilder buf = null;
        for (int i = 0; i < len; i++) {
            char ch = value.charAt(i);
            switch (ch) {
                case '<':
                    if (buf == null) {
                        buf = new StringBuilder(len * 2);
                        if (i > 0) {
                            buf.append(value.substring(0, i));
                        }
                    }
                    buf.append("&lt;");
                    break;
                case '>':
                    if (buf == null) {
                        buf = new StringBuilder(len * 2);
                        if (i > 0) {
                            buf.append(value.substring(0, i));
                        }
                    }
                    buf.append("&gt;");
                    break;
                case '\"':
                    if (buf == null) {
                        buf = new StringBuilder(len * 2);
                        if (i > 0) {
                            buf.append(value.substring(0, i));
                        }
                    }
                    buf.append("&quot;");
                    break;
                case '\'':
                    if (buf == null) {
                        buf = new StringBuilder(len * 2);
                        if (i > 0) {
                            buf.append(value.substring(0, i));
                        }
                    }
                    buf.append("&apos;");
                    break;
                case '&':
                    if (buf == null) {
                        buf = new StringBuilder(len * 2);
                        if (i > 0) {
                            buf.append(value.substring(0, i));
                        }
                    }
                    buf.append("&amp;");
                    break;
                default:
                    if (buf != null) {
                        buf.append(ch);
                    }
                    break;
            }
        }
        if (buf != null) {
            return buf.toString();
        }
        return value;
    }
434381
private static String escapeXml (String nonEscapedXmlStr) {
        StringBuilder escapedXML = new StringBuilder();
        for (int i = 0; i < nonEscapedXmlStr.length(); i++) {
            char c = nonEscapedXmlStr.charAt(i);
            switch (c) {
                case '<':
                    escapedXML.append("&lt;");
                    break;
                case '>':
                    escapedXML.append("&gt;");
                    break;
                case '\"':
                    escapedXML.append("&quot;");
                    break;
                case '&':
                    escapedXML.append("&amp;");
                    break;
                case '\'':
                    escapedXML.append("&apos;");
                    break;
                default:
                    if (c > 0x7e) {
                        escapedXML.append("&#" + ((int) c) + ";");
                    } else {
                        escapedXML.append(c);
                    }
            }
        }
        return escapedXML.toString();
    }
993029
def html_format(data, out, opts=None, **kwargs):
    '''
    
    '''
    ansi_escaped_string = string_format(data, out, opts, **kwargs)
    return ansi_escaped_string.replace(' ', '&nbsp;').replace('\n', '<br />')
264805
def escape(cls, string):
        

        return ''.join([cls._escapes[c] if cls._needescape(c) else c
                        for c in string.encode('utf8')])
958658
public static String escapeString(String data) {
    return StringUtils.escapeString(data, StringUtils.ESCAPE_CHAR, 
                                    charsToEscape);
  }
598192
def to_xml_string(str = '')
      str << '<xf '
      serialized_attributes str
      str << '>'
      alignment.to_xml_string(str) if self.alignment
      protection.to_xml_string(str) if self.protection
      str << '</xf>'
    end
777478
def _escape_attribute_quotes(self, v):
        '''
        
        '''
        escaped = []
        inside_tag = False
        for i, _ in enumerate(v):
            if v[i:i + 2] == '{%':
                inside_tag = True
            elif v[i:i + 2] == '%}':
                inside_tag = False

            if v[i] == self.attr_wrapper and not inside_tag:
                escaped.append('\\')

            escaped.append(v[i])

        return ''.join(escaped)
154350
public static RawData escapeXml(Object o) {
        if (null == o) return RawData.NULL;
        if (o instanceof RawData)
            return (RawData) o;
        return new RawData(_escapeXML(o.toString()));
    }
1097646
function format(string) {
  string = _.toString(string);

  // Replace all code snippets with a token.
  var snippets = [];
  string = string.replace(reCode, function(match) {
    snippets.push(match);
    return token;
  });

  return string
    // Add line breaks.
    .replace(/:\n(?=[\t ]*\S)/g, ':<br>\n')
    .replace(/\n( *)[-*](?=[\t ]+\S)/g, '\n<br>\n$1*')
    .replace(/^[\t ]*\n/gm, '<br>\n<br>\n')
    // Normalize whitespace.
    .replace(/\n +/g, ' ')
    // Italicize parentheses.
    .replace(/(^|\s)(\(.+\))/g, '$1*$2*')
    // Mark numbers as inline code.
    .replace(/[\t ](-?\d+(?:.\d+)?)(?!\.[^\n])/g, ' `$1`')
    // Replace all tokens with code snippets.
    .replace(reToken, function(match) {
      return snippets.shift();
    })
    .trim();
}
976881
function(string) {
            // If the string contains no control characters, no quote characters, and no
            // backslash characters, then we can simply slap some quotes around it.
            // Otherwise we must also replace the offending characters with safe
            // sequences.    
            var m = {
                '\b': '\\b',
                '\t': '\\t',
                '\n': '\\n',
                '\f': '\\f',
                '\r': '\\r',
                '"' : '\\"',
                '\\': '\\\\'
            };
            if(/["\\\x00-\x1f]/.test(string)) {
                return '"' + string.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                    var c = m[b];
                    if(c) {
                        return c;
                    }
                    c = b.charCodeAt();
                    return '\\u00' +
                        Math.floor(c / 16).toString(16) +
                        (c % 16).toString(16);
                }) + '"';
            }
            return '"' + string + '"';
        }