Escapes all potentially dangerous characters, so that the
resulting string can be safely inserted into attribute or
element text.
@param value
@returns escaped text
179079
function encodeEntities(value) {
  return value.
    replace(/&/g, '&amp;').
    replace(NON_ALPHANUMERIC_REGEXP, function(value){
      return '&#' + value.charCodeAt(0) + ';';
    }).
    replace(/</g, '&lt;').
    replace(/>/g, '&gt;');
}
675458
private String encode(final String value, final Charset charset) {
    if (StringUtils.isBlank(value)) {
      return "";
    }
    try {
      return URLEncoder.encode(value, charset.name());

    } catch (UnsupportedEncodingException e) {
      return value;
    }
  }
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();
    }
1266913
def escape_string(value):
    
    res = StringIO()
    res.write('"')
    for c in value:
        if c in CHAR_TO_ESCAPE:
            res.write(f'\\{CHAR_TO_ESCAPE[c]}')
        elif c.isprintable():
            res.write(c)
        elif ord(c) < 0x100:
            res.write(f'\\x{ord(c):02x}')
        elif ord(c) < 0x10000:
            res.write(f'\\u{ord(c):04x}')
        else:
            res.write(f'\\U{ord(c):06x}')
    res.write('"')
    return res.getvalue()
447164
private String escapeAndQuote(String value) {
        // the initial count is for the preceding and trailing quotes
        int count = 2;
        for (int i = 0; i < value.length(); i++) {
            switch (value.charAt(i)) {
                case '\"':
                case '\n':
                case '\r':
                case '\\':
                    count++;
                    break;
                default:
                    break;
            }
        }
        StringBuffer sb = new StringBuffer(value.length() + count);
        sb.append(strategy.getEncapsulator());
        for (int i = 0; i < value.length(); i++) {
            char c = value.charAt(i);

            if (c == strategy.getEncapsulator()) {
                sb.append('\\').append(c);
                continue;
            }
            switch (c) {
                case '\n':
                    sb.append("\\n");
                    break;
                case '\r':
                    sb.append("\\r");
                    break;
                case '\\':
                    sb.append("\\\\");
                    break;
                default:
                    sb.append(c);
            }
        }
        sb.append(strategy.getEncapsulator());
        return sb.toString();
    }
1217987
def _escape(value):
        
        value = str(value)
        for char, escaped in {' ': '\ ', ',': '\,', '"': '\"'}.items():
            value = value.replace(char, escaped)
        return value
216341
public static String decodeString(String value) {
    if (value == null) {
      return null;
    }
    StringBuilder decoded = new StringBuilder();
    int len = value.length();
    int escapeStart = -2;
    for (int i = 0; i < len; i++) {
      char c = value.charAt(i);
      if (c == ESCAPE_CHAR && escapeStart != i - 1) {
        escapeStart = i;
      }
      else {
        decoded.append(c);
      }
    }
    return decoded.toString();
  }
40431
private String escape(String value)
    {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < value.length(); ++i)
        {
            char c = value.charAt(i);
            if (c < reservedChars.length && reservedChars[c] == c)
            {
                result.append(ESCAPE_PREFIX);
                int code = c & 0xFF;
                if (code < 16) result.append("0");
                result.append(Integer.toHexString(code));
            }
            else
            {
                result.append(c);
            }
        }
        return result.toString();
    }
1062852
public static String encodeAttributeValue(String value)
	{
		String _result = value.replaceAll(PATTERN__CHAR_AMPERSAND, VALUE__ENTITY_AMPERSAND);
		_result = _result.replaceAll(PATTERN__CHAR_QUOTE, VALUE__ENTITY_QUOTE);
		return _result;
	}
354758
private Charset getCharset(final String value) {
        Charset c = null;
        if (value != null) {
            final String[] tokens = value.trim().split("[;=]");
            if (tokens.length >= 3 && tokens[1].trim().equals("charset")) {
                try {
                    c = Charset.forName(tokens[2].trim());
                } catch (final RuntimeException e) {
                    logger.error(MessageUtils.getMessage("DOTJ052E", tokens[2].trim()).toString());
                }
            }
        }
        if (c == null) {
            final String defaultCharset = Configuration.configuration.get("default.coderef-charset");
            if (defaultCharset != null) {
                c = Charset.forName(defaultCharset);
            } else {
                c = Charset.defaultCharset();
            }
        }
        return c;
    }
1264691
function escape(value) {
  return value
    .split('')
    .map(function(character) {
      return '\\u' + character.charCodeAt(0).toString(16)
    })
    .join('')
}
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();
   }
1101119
public static String escapeCssString(SoyValue value) {
    value = normalizeNull(value);
    return escapeCssString(value.coerceToString());
  }
789342
public ChainWriter encodeXmlAttribute(Object value) throws IOException {
		Coercion.write(value, textInXhtmlAttributeEncoder, out);
		return this;
	}
1125035
public static String escape(String value, char quote) {
    Map<CharSequence, CharSequence> lookupMap = new HashMap<>();
    lookupMap.put(Character.toString(quote), "\\" + quote);
    lookupMap.put("\\", "\\\\");

    final CharSequenceTranslator escape =
        new LookupTranslator(lookupMap)
                .with(new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE))
                .with(JavaUnicodeEscaper.outsideOf(32, 0x7f));

    return quote + escape.translate(value) + quote;
  }
821602
@Override
    public String getEscapedValue(String value, boolean toQuote) {
        // Escape special characters
        StringBuilder buf = new StringBuilder(value.length());
        int idx = 0;
        int ch;

        while (idx < value.length()) {
            ch = value.charAt(idx++);
            if (ch == 0) {
                buf.append("\\0");

            } else if (ch == 92) { // backslash
                buf.append("\\\\");

            } else if (ch == 124) { // vertical bar
                // 124 = "|" = AbstractSerializationStream.RPC_SEPARATOR_CHAR
                buf.append("\\!");

            } else if ((ch >= 0xD800) && (ch < 0xFFFF)) {
                buf.append(String.format("\\u%04x", ch));

            } else {
                buf.append((char) ch);
            }
        }

        return buf.toString();
    }
645984
public static String urlEncode(String value) {
        if (value == null) {
            return value;
        }
        try {
            value = URLEncoder.encode(value, CommonWebConstants.UTF_8);
        } catch (UnsupportedEncodingException e) {
            // Do nothing - UTF-8 should always be supported
        }
        return value;
    }