Encodes a character to an HTML-Ampersand code (if necessary)
353451
public static String encodeAmpersand(char c) {
    String s;
    if (null != (s = charToAmpersand.get(c))) return (s);
    if (c < 128 && c >= 32) return ("" + c);
    else return ("&#" + ((int) c) + ";");
  }
1309008
public static String encodeXmlAttribute(String str) {
    if (str == null) return null;
    int len = str.length();
    if (len == 0) return str;
    StringBuffer encoded = new StringBuffer();
    for (int i = 0; i < len; i++) {
      char c = str.charAt(i);
      if (c == '<') encoded.append("&lt;");
      else if (c == '\"') encoded.append("&quot;");
      else if (c == '>') encoded.append("&gt;");
      else if (c == '\'') encoded.append("&apos;");
      else if (c == '&') encoded.append("&amp;");
      else encoded.append(c);
    }
    return encoded.toString();
  }
1330727
function(charCode)
	{
		var output = "";
		if (charCode>255) {
			output = "\\u"+(charCode<4096?"0":"")+charCode.toString(16);
		} else if (charCode>127) {
			output = "\\x"+charCode.toString(16);
		} else {
			output = (this.needsEscapingInCharClass(charCode)?"\\":"")+String.fromCharCode(charCode);
		}
		return output;
	}
300083
def _xml_escape(data):
    """"""

    # ampersand must be replaced first
    from_symbols = '&><"\''
    to_symbols = ('&'+s+';' for s in "amp gt lt quot apos".split())
    for from_,to_ in zip(from_symbols, to_symbols):
        data = data.replace(from_, to_)
    return data
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)
164028
def _encode_code(name, value, dummy, opts):
    """"""
    cstring = _make_c_string(value)
    cstrlen = len(cstring)
    if not value.scope:
        return b"\x0D" + name + _PACK_INT(cstrlen) + cstring
    scope = _dict_to_bson(value.scope, False, opts, False)
    full_length = _PACK_INT(8 + cstrlen + len(scope))
    return b"\x0F" + name + full_length + _PACK_INT(cstrlen) + cstring + scope
1029853
def url_encode(str)
      encoded_string = ""
      str.each_char do |char|
        case char
        when "+"
          encoded_string << "%2b"
        when "="
          encoded_string << "%3d"
        when "?"
          encoded_string << "%3f"
        when "&"
          encoded_string << "%26"
        when "%"
          encoded_string << "%25"
        when ","
          encoded_string << "%2C"
        else
          encoded_string << char
        end
      end
      encoded_string
    end
1370979
public StringBuffer encode(StringBuffer buff) {
		buff.append('(');
		buff.append(attribute).append(getCompareString()).append(encodedValue);
		buff.append(')');

		return buff;
	}
234082
public static String encodeChars(String iString)
    {
        if (iString == null)
            return "";

        int strLen = iString.length(), i;

        if (strLen < 1)
            return iString;

        // convert any special chars to their browser equivalent specification
        StringBuffer retString = new StringBuffer(strLen * 2);

        for (i = 0; i < strLen; i++)
        {
            switch (iString.charAt(i))
            {
                case '<':
                    retString.append("&lt;");
                    break;

                case '>':
                    retString.append("&gt;");
                    break;

                case '&':
                    retString.append("&amp;");
                    break;

                case '\"':
                    retString.append("&quot;");
                    break;

                case '+':
                    retString.append("&#43;");
                    break;

                case '(':
                    retString.append("&#40;");
                    break;

                case ')':
                    retString.append("&#41;");
                    break;

                case '\'':
                    retString.append("&#39;");
                    break;

                case '%':
                    retString.append("&#37;");
                    break;

                case ';':
                    retString.append("&#59;");
                    break;

                default:
                    retString.append(iString.charAt(i));
                    break;
            }
        }

        return retString.toString();
    }
355192
def escape(string, quote=False):
    
    if string is None:
        return ''
    elif hasattr(string, '__html__'):
        return unicode(string)
    string = string.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
    if quote:
        string = string.replace('"', "&quot;")
    return string
768779
@Override
    protected void encode() {
        int l = content.length();
        String localstr;
        int zeroes, count = 0, check_digit;
        Code3Of9 c = new Code3Of9();

        if (l > 7) {
            throw new OkapiException("Input data too long");
        }

        if (!content.matches("[0-9]+")) {
            throw new OkapiException("Invalid characters in input");
        }

        localstr = "-";
        zeroes = 7 - l + 1;
        for (int i = 1; i < zeroes; i++)
            localstr += '0';

        localstr += content;

        for (int i = 1; i < 8; i++) {
            count += i * Character.getNumericValue(localstr.charAt(i));
        }

        check_digit = count % 11;
        if (check_digit == 11) {
            check_digit = 0;
        }
        if (check_digit == 10) {
            throw new OkapiException("Not a valid PZN identifier");
        }

        encodeInfo += "Check Digit: " + check_digit + "\n";

        localstr += (char)(check_digit + '0');

        c.setContent(localstr);

        readable = "PZN" + localstr;
        pattern = new String[1];
        pattern[0] = c.pattern[0];
        row_count = 1;
        row_height = new int[1];
        row_height[0] = -1;
    }
629278
private static String xmlEncode(String input, boolean attribute) {
    if (input == null || input.length() == 0) {
      return attribute ? "\"\"" : input;
    }
    StringBuilder output = new StringBuilder();
    if (attribute) {
      output.append(0); // reserve space for leading quote
    }
    char quoteChar = 0;
    for (int i = 0; i < input.length(); i++) {
      char ch = input.charAt(i);
      switch (ch) {
        case '<':
          output.append("&lt;");
          break;
        case '>':
          output.append("&gt;");
          break;
        case '&':
          output.append("&amp;");
          break;
        case '"':
          if (attribute && quoteChar == '"') {
            output.append("&quot;");
          }
          else {
            output.append(ch);
            quoteChar = '\'';
          }
          break;
        case '\'':
          if (attribute && quoteChar == '\'') {
            output.append("&apos;");
          }
          else {
            output.append(ch);
            quoteChar = '"';
          }
          break;
        case 0x0009: // tab
        case 0x000A: // linefeed
        case 0x000D: // carriage return
          if (attribute) {
            output.append("&#");
            output.append((int) ch);
            output.append(";");
          }
          else {
            output.append(ch);
          }
          break;
        default:
          if (ch < 32 || ch >= 0xFFFE) {
            throw new IllegalArgumentException("UTF-16 Codepoint 0x" + Integer.toString(ch, 16) + " is not valid for XML content");
          }
          output.append(ch);
      }
    }
    if (attribute) {
      if (quoteChar == 0) {
        quoteChar = '"';
      }
      output.setCharAt(0, quoteChar);
      output.append(quoteChar);
    }
    return output.toString();
  }
558329
function htmlDecode(str) {
  if (typeof str === 'string' && str.length === 0) return;

  let s = str.replace(/&amp;/g, '&');

  return s.replace(/&lt;/g, '<')
        .replace(/&gt;/g, '>')
        .replace(/&#39;/g, '\'')
        .replace(/&nbsp;/g, ' ')
        .replace(/&quot;/g, '"')
        .replace(/<br>/g, '\\n');
}
62696
function(s, anchor) {
    if (
        anchor === 0 &&
        s.charCodeAt(0) === 0x2F /* '/' */ &&
        s.length > 2 &&
        s.charCodeAt(s.length-1) === 0x2F /* '/' */
    ) {
        s = s + '*';
    }
    return s;
}
471858
function encodeUnicode(str) {
  return String(str).replace(/[^\x09-\x7f\ufeff]/g, function (all) {
    return '\\u' + (0x10000 + all.charCodeAt()).toString(16).substring(1);
  });
}
291175
def html_encode(text):
    
    text = text.replace('&', '&amp;')
    text = text.replace('<', '&lt;')
    text = text.replace('>', '&gt;')
    text = text.replace('"', '&quot;')
    return text
863282
public static String encode(String string) {
        int n = string.length();
        char character;
        StringBuffer buffer = new StringBuffer();
        // loop over all the characters of the String.
        for (int i = 0; i < n; i++) {
            character = string.charAt(i);
            // the Htmlcode of these characters are added to a StringBuffer one by one
            if (character < 256) {
                buffer.append(htmlCode[character]);
            }
            else {
                // Improvement posted by Joachim Eyrich
                buffer.append("&#").append((int)character).append(';');
            }
        }
        return buffer.toString();
    }