decode html entity into one of the codepoint2name
776391
def html_entity_decode_codepoint(self, m,
                                     defs=htmlentities.codepoint2name):
        
        try:
            char = defs[m.group(1)]
            return "&{char};".format(char=char)
        except ValueError:
            return m.group(0)
        except KeyError:
            return m.group(0)
920071
def _unescape_fixup(match):
    
    text = match.group(0)
    if text[:2] == "&#":
        # character reference
        try:
            if text[:3] == "&#x":
                codept = int(text[3:-1], 16)
            else:
                codept = int(text[2:-1])
            if 0x80 <= codept < 0xa0:
                # Decode this range of characters as Windows-1252, as Web
                # browsers do in practice.
                return bytes([codept]).decode('sloppy-windows-1252')
            else:
                return chr(codept)
        except ValueError:
            return text
    else:
        # This is a named entity; if it's a known HTML5 entity, replace
        # it with the appropriate character.
        try:
            return entities.html5[text[1:]]
        except KeyError:
            return text
322778
public static int getHtmlCodeByHtmlEntity(String htmlEntity)
    {
        Entity entity = fHtmlToWiki.get(htmlEntity);
        return entity != null ? entity.fHtmlCode : 0;
    }
1325832
function encodeFactory(type) {
  var options = {}

  if (type === 'false') {
    return identity
  }

  if (type === 'true') {
    options.useNamedReferences = true
  }

  if (type === 'escape') {
    options.escapeOnly = true
    options.useNamedReferences = true
  }

  return wrapped

  // Encode HTML entities using the bound options.
  function wrapped(value) {
    return encode(value, options)
  }
}
1037825
def replace_html_entities(cls, replacement_string):
        
        def _hex_to_unicode(hex_code):
            if PYTHON3:
                hex_code = '{0:0>8}'.format(hex_code)
                as_int = struct.unpack('>i', bytes.fromhex(hex_code))[0]
                return '{0:c}'.format(as_int)
            else:
                return hex_to_unicode(hex_code)

        def _replace_integer_entity(match):
            hex_val = hex(int(match.group(1)))

            return _hex_to_unicode(hex_val.replace('0x', ''))

        def _replace_hex_entity(match):
            return _hex_to_unicode(match.group(1))

        # replace integer code points, &#65;
        replacement_string = re.sub(
            cls._html_entities_integer_unicode_regex,
            _replace_integer_entity,
            replacement_string
        )
        # replace hex code points, &#x41;
        replacement_string = re.sub(
            cls._html_entities_hex_unicode_regex,
            _replace_hex_entity,
            replacement_string
        )

        return replacement_string
1114855
def unescape(text):
    
    def fixup(m):
        text = m.group(0)
        if text[:2] == "&#":
            # character reference
            try:
                if text[:3] == "&#x":
                    return unichr(int(text[3:-1], 16))
                else:
                    return unichr(int(text[2:-1]))
            except ValueError:
                pass
        else:
            # named entity
            try:
                text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
            except KeyError:
                pass
        return text # leave as is

    return re.sub("&#?\w+;", fixup, text)
450835
function getCodePoints(str) {
  const codePoints = [];
  for (let pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
    codePoints.push(str.codePointAt(pos));
  }
  return codePoints;
}
1374556
public static String decodeHtml(String s) {
    int firstAmp = s.indexOf('&');
    int safeLimit = longestPrefixOfGoodCodeunits(s);
    if ((firstAmp & safeLimit) < 0) { return s; }

    StringBuilder sb;
    {
      int n = s.length();
      sb = new StringBuilder(n);
      int pos = 0;
      int amp = firstAmp;
      while (amp >= 0) {
        long endAndCodepoint = HtmlEntities.decodeEntityAt(s, amp, n);
        int end = (int) (endAndCodepoint >>> 32);
        int codepoint = (int) endAndCodepoint;
        sb.append(s, pos, amp).appendCodePoint(codepoint);
        pos = end;
        amp = s.indexOf('&', end);
      }
      sb.append(s, pos, n);
    }

    stripBannedCodeunits(
        sb,
        firstAmp < 0
          ? safeLimit : safeLimit < 0
          ? firstAmp : Math.min(firstAmp, safeLimit));

    return sb.toString();
  }
256969
def unescape(s):
    
    def handle_match(m):
        name = m.group(1)
        if name in HTMLBuilder._entities:
            return unichr(HTMLBuilder._entities[name])
        try:
            if name[:2] in ('#x', '#X'):
                return unichr(int(name[2:], 16))
            elif name.startswith('#'):
                return unichr(int(name[1:]))
        except ValueError:
            pass
        return u''
    return _entity_re.sub(handle_match, s)
986248
private static String decodeAttribute(String s, Charset charset) {
        try {
            return QueryStringDecoder.decodeComponent(s, charset);
        } catch (IllegalArgumentException e) {
            throw new ErrorDataDecoderException("Bad string: '" + s + '\'', e);
        }
    }
394072
public static String unescapeHtml(String s) {
    int amp = s.indexOf('&');
    if (amp < 0) { // Fast path.
      return s;
    }
    int n = s.length();
    StringBuilder sb = new StringBuilder(n);
    int pos = 0;
    do {
      // All numeric entities and all named entities can be represented in less than 12 chars, so
      // avoid any O(n**2) problem on "&&&&&&&&&" by not looking for ; more than 12 chars out.
      int end = -1;
      int entityLimit = Math.min(n, amp + 12);
      for (int i = amp + 1; i < entityLimit; ++i) {
        if (s.charAt(i) == ';') {
          end = i + 1;
          break;
        }
      }
      int cp = -1;
      if (end == -1) {
        cp = -1;
      } else {
        if (s.charAt(amp + 1) == '#') { // Decode a numeric entity
          char ch = s.charAt(amp + 2);
          try {
            if (ch == 'x' || ch == 'X') { // hex
              //         & # x A B C D ;
              //         ^ ^ ^ ^       ^
              // amp +   0 1 2 3       end - 1
              cp = Integer.parseInt(s.substring(amp + 3, end - 1), 16);
            } else { // decimal
              //         & # 1 6 0 ;
              //         ^ ^ ^     ^
              // amp +   0 1 2     end - 1
              cp = Integer.parseInt(s.substring(amp + 2, end - 1), 10);
            }
          } catch (NumberFormatException ex) {
            cp = -1; // Malformed numeric entity
          }
        } else {
          //     & q u o t ;
          //     ^           ^
          //   amp           end
          Integer cpI = HTML_ENTITY_TO_CODEPOINT.get(s.substring(amp, end));
          cp = cpI != null ? cpI.intValue() : -1;
        }
      }
      if (cp == -1) { // Don't decode
        end = amp + 1;
      } else {
        sb.append(s, pos, amp);
        sb.appendCodePoint(cp);
        pos = end;
      }
      amp = s.indexOf('&', end);
    } while (amp >= 0);
    return sb.append(s, pos, n).toString();
  }
1263192
private String urlEncode(Object value)
	{
		try {
			return URLEncoder.encode(value.toString(), UTF8.name());
		} catch (UnsupportedEncodingException e) { throw new RuntimeException(e); }
	}
223396
private static String decodeFormFields(final String content, final Charset charset) {
        if (content == null) {
            return null;
        }

        return urlDecode(content, (charset != null) ? charset : Charsets.UTF_8, true);
    }
792824
function loadEntities() {
		// Uncompress the base charmap
		charMap = require('./string_entities_map.js');

		HTMLEntities = {};

		for (key in charMap) {
			for (i = 0; i < charMap[key].length; i++) {
				HTMLEntities[charMap[key][i]] = key;
			}
		}
	}
520273
def xml_entity_escape(data):
    

    data = data.replace("&", "&amp;")
    data = data.replace(">", "&gt;")
    data = data.replace("<", "&lt;")
    return data
1009147
function getCodeFromNode(node, renameSources, options) {
    const code_map = getCodeMap(node);
    const rename = renameSources;
    const objMap = code_map.map.toJSON();
    let i, n;

    if (rename) {
        if ('string' === typeof rename) {
            for (i = 0, n = objMap.sources.length; i < n; i++) {
                objMap.sources[i] = rename + objMap.sources[i];
            }
        } else if ('function' === typeof rename) {
            for (i = 0, n = objMap.sources.length; i < n; i++) {
                objMap.sources[i] = rename(objMap.sources[i]);
            }
        } else {
            console.warn('unexpected type of rename: ' + typeof rename);
        }
    }

    return node.toString() +
        convert.fromObject(objMap)
            .toComment(options)
            .replace(/charset=utf-8;/gm, '')
            .replace('data:application/json;', 'data:application/json;charset=utf-8;') + '\n';
}
879526
public Object decode(Object o) {
        if (o == null) {
            return null;
        }
        return HtmlUtils.htmlUnescape(String.valueOf(o));
    }