escape the given string such that it can be placed in an XML attribute, like:

        <foo bar='$value'>

    Args:
      s (str): the string to escape.

    Returns:
      str: the escaped string.
344727
def escape_attr(s):
    '''
    
    '''
    esc = xml.sax.saxutils.quoteattr(s)
    esc = esc.encode('ascii', 'xmlcharrefreplace').decode('ascii')
    esc = RESTRICTED_CHARS.sub('', esc)
    return esc
845099
public static void escapeXML(StringBuilder sb) {
        // double quote -- quot
        // ampersand -- amp
        // less than -- lt
        // greater than -- gt
        // apostrophe -- apos
        for (int i = 0; i < sb.length();) {
            int codePoint = Character.codePointAt(sb, i);
            int length = Character.charCount(codePoint);
            if (codePoint == '<') {
                sb.replace(i, i + length, LT);
                i += LT.length();
            } else if (codePoint == '>') {
                sb.replace(i, i + length, GT);
                i += GT.length();
            } else if (codePoint == '\"') {
                sb.replace(i, i + length, QUOT);
                i += QUOT.length();
            } else if (codePoint == '&') {
                sb.replace(i, i + length, AMP);
                i += AMP.length();
            } else if (codePoint == '\'') {
                sb.replace(i, i + length, APOS);
                i += APOS.length();
            } else {
                i += length;
            }
        }
    }
713351
def escapeXML( char )
      if @xmlEscapes.nil?
         @xmlEscapes = {}
         (0..255).each{ |i| @xmlEscapes[ i.chr ] = sprintf( "&#%03d;", i )  }
      end
      return @xmlEscapes[ char ] if @xmlEscapes[ char ]
      char
   end
188124
private String escapeString(String value)
   {
      m_buffer.setLength(0);
      m_buffer.append('"');
      for (int index = 0; index < value.length(); index++)
      {
         char c = value.charAt(index);
         switch (c)
         {
            case '"':
            {
               m_buffer.append("\\\"");
               break;
            }

            case '\\':
            {
               m_buffer.append("\\\\");
               break;
            }

            case '/':
            {
               m_buffer.append("\\/");
               break;
            }

            case '\b':
            {
               m_buffer.append("\\b");
               break;
            }

            case '\f':
            {
               m_buffer.append("\\f");
               break;
            }

            case '\n':
            {
               m_buffer.append("\\n");
               break;
            }

            case '\r':
            {
               m_buffer.append("\\r");
               break;
            }

            case '\t':
            {
               m_buffer.append("\\t");
               break;
            }

            default:
            {
               // Append if it's not a control character (0x00 to 0x1f)
               if (c > 0x1f)
               {
                  m_buffer.append(c);
               }
               break;
            }
         }
      }
      m_buffer.append('"');
      return m_buffer.toString();
   }
564793
public static String escapeJavaString(String s)
  {
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < s.length(); i++) {
      char ch = s.charAt(i);

      switch (ch) {
      case '\\':
        sb.append("\\\\");
        break;
      case '\n':
        sb.append("\\n");
        break;
      case '\r':
        sb.append("\\r");
        break;
      case '"':
        sb.append("\\\"");
        break;
      default:
        sb.append(ch);
      }
    }

    return sb.toString();
  }
280701
def _xml_escape_attr(attr, skip_single_quote=True):
    
    escaped = (attr
        .replace('&', '&amp;')
        .replace('"', '&quot;')
        .replace('<', '&lt;')
        .replace('>', '&gt;'))
    if not skip_single_quote:
        escaped = escaped.replace("'", "&#39;")
    return escaped
186847
public static String escapeEscapes(String value)
    {
        assert(value != null);
        InternalStringBuilder sb = new InternalStringBuilder(value.length());
        for (int i = 0; i < value.length(); i++) {
            char c = value.charAt(i);
            if (c == '"') {
                sb.append("&quot;");
                continue;
            }
            if (c == '\\') {
                sb.append("\\\\");
                continue;
            }
            sb.append(c);
        }
        return sb.toString();
    }
1133567
def _surface_escape(code, char):
        
        replacement = str(HTMLEntity(value=ord(char)))
        for node in code.filter_text(recursive=False):
            if char in node:
                code.replace(node, node.replace(char, replacement), False)
325348
function escapeXML($elementValue){
    $escapedValue = str_replace("&", "&amp;", trim($elementValue));
    $escapedValue = str_replace("<", "&lt;", $escapedValue);
    return $escapedValue;
  }
215926
function escapeXml (string) {
    return String(string).replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  }
1217987
def _escape(value):
        
        value = str(value)
        for char, escaped in {' ': '\ ', ',': '\,', '"': '\"'}.items():
            value = value.replace(char, escaped)
        return value
45252
public static String escapeHtml(String s) {
        // (The code of this method is a bit redundant in order to optimize speed)
        if (s == null) {
            return null;
        }
        int sLength = s.length();
        boolean found = false;
        int p;
        loop1: for (p = 0; p < sLength; p++) {
            switch (s.charAt(p)) {
                case '<':
                case '>':
                case '&':
                case '\'':
                case '"':
                    found = true;
                    break loop1;
            }
        }
        if (!found) {
            return s;
        }
        StringBuilder sb = new StringBuilder(sLength + 16);
        sb.append(s.substring(0, p));
        for (; p < sLength; p++) {
            char c = s.charAt(p);
            switch (c) {
                case '<':
                    sb.append("&lt;");
                    break;
                case '>':
                    sb.append("&gt;");
                    break;
                case '&':
                    sb.append("&amp;");
                    break;
                case '\'':
                    sb.append("&#39;");
                    break;
                case '"':
                    sb.append("&#34;");
                    break;
                default:
                    sb.append(c);
            }
        }
        return sb.toString();
    }
1287577
def html_escape(s, encoding='utf-8', encoding_errors='strict'):
    
    return escape(make_unicode(s, encoding, encoding_errors), quote=True)
246681
def escape(s, quote=True):
    
    assert not isinstance(s, bytes), 'Pass a unicode string'
    if quote:
        return s.translate(_escape_map_full)
    return s.translate(_escape_map)
1372840
protected function escapeAttribute(): string
    {
        $value = $this->validateEncoding();
        $value = strip_tags($value);

        return htmlspecialchars($value, ENT_QUOTES);
    }
175281
private static String escapeXml(String input) {
        return input == null ? "" : input.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
    }
981908
public static String escapeString(String value, boolean noBackslashEscapes) {
    if (!value.contains("'")) {
      if (noBackslashEscapes) {
        return value;
      }
      if (!value.contains("\\")) {
        return value;
      }
    }
    String escaped = value.replace("'", "''");
    if (noBackslashEscapes) {
      return escaped;
    }
    return escaped.replace("\\", "\\\\");
  }