Read an HTML entity.
{@literal &identifier; } or {@literal &#digits; } or {@literal &#xhex-digits; }
973704
protected void entity() {
        nextChar();
        String name = null;
        if (ch == '#') {
            int namep = bp;
            nextChar();
            if (isDecimalDigit(ch)) {
                nextChar();
                while (isDecimalDigit(ch))
                    nextChar();
                name = new String(buf, namep, bp - namep);
            } else if (ch == 'x' || ch == 'X') {
                nextChar();
                if (isHexDigit(ch)) {
                    nextChar();
                    while (isHexDigit(ch))
                        nextChar();
                    name = new String(buf, namep, bp - namep);
                }
            }
        } else if (isIdentifierStart(ch)) {
            name = readIdentifier();
        }

        if (name != null) {
            if (ch != ';')
                return;
            nextChar();
        }
    }
791390
private String getContentCharSet(final HttpEntity entity) throws ParseException {
        if (entity == null) {
            return null;
        }
        String charset = null;
        if (entity.getContentType() != null) {
            HeaderElement values[] = entity.getContentType().getElements();
            if (values.length > 0) {
                NameValuePair param = values[0].getParameterByName("charset");
                if (param != null) {
                    charset = param.getValue();
                }
            }
        }        
        return charset;
    }
355555
private String parseJavaId() {
		StringBuilder sb = new StringBuilder();
		int ch;
		while (true) {
			ch = peekChar();
			if (ch == EOS || !isJavaIdentifierPart(ch)) {
				return sb.toString();
			}
			sb.append((char) ch);
			nextChar();
		}
	}
524542
def read(self, identifier, path):
        
        with open(path) as f:
            o = self.classes["text"](urn=identifier, resource=self.xmlparse(f))
        return o
642991
def html_entity_decode(self):
        
        pattern = re.compile(r"&#(\w+?);")
        string = pattern.sub(self.html_entity_decode_char, self.my_string)
        return pattern.sub(self.html_entity_decode_codepoint, string)
1166234
function getMarkedId (text) {
  return entities.decode(text)
    .toLowerCase()
    .trim()
    .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~_]/g, '')
    .replace(/\s/g, '-')
}
7479
function (scanner, inAttribute) {
  // look for `&` followed by alphanumeric
  if (! peekMatcher(scanner, getPossibleNamedEntityStart))
    return null;

  var matcher = getNamedEntityByFirstChar[scanner.rest().charAt(1)];
  var entity = null;
  if (matcher)
    entity = peekMatcher(scanner, matcher);

  if (entity) {
    if (entity.slice(-1) !== ';') {
      // Certain character references with no semi are an error, like `&lt`.
      // In attribute values, however, this is not fatal if the next character
      // is alphanumeric.
      //
      // This rule affects href attributes, for example, deeming "/?foo=bar&ltc=abc"
      // to be ok but "/?foo=bar&lt=abc" to not be.
      if (inAttribute && ALPHANUMERIC.test(scanner.rest().charAt(entity.length)))
        return null;
      scanner.fatal("Character reference requires semicolon: " + entity);
    } else {
      scanner.pos += entity.length;
      return entity;
    }
  } else {
    // we couldn't match any real entity, so see if this is a bad entity
    // or something we can overlook.
    var badEntity = peekMatcher(scanner, getApparentNamedEntity);
    if (badEntity)
      scanner.fatal("Invalid character reference: " + badEntity);
    // `&aaaa` is ok with no semicolon
    return null;
  }
}
846465
function decodeHTMLEntity(source) {
    return source
        .replace(/&#([0-9]+);/g, function (match, code) {
            return String.fromCharCode(+code);
        })
        .replace(/&#x([0-9a-f]+);/ig, function (match, code) {
            return String.fromCharCode(parseInt(code, 16));
        })
        .replace(/&([a-z]+);/ig, function (match, code) {
            return ENTITY_DECODE_MAP[code] || match;
        });
}
335682
def decode_entities(html):
    
    def decode(m):
        html = m.group(0)
        if html[:2] == "&#":
            try:
                if html[:3] == "&#x":
                    return chr(int(html[3:-1], 16))
                else:
                    return chr(int(html[2:-1]))
            except ValueError:
                pass
        else:
            try:
                html = chr(name2codepoint[html[1:-1]])
            except KeyError:
                pass
        return html
    return re.sub("&#?\w+;", decode, html.replace("&amp;", "&"))
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();
  }
410769
def htmlReadFd(fd, URL, encoding, options):
    
    ret = libxml2mod.htmlReadFd(fd, URL, encoding, options)
    if ret is None:raise treeError('htmlReadFd() failed')
    return xmlDoc(_obj=ret)
894170
function readOpenTag() {
		// Read tag name
		let start = getSourcePoint(),
			match = tagNameRegex.exec(source.substr(pos))
		if (!match) {
			throwSyntaxError('Invalid open tag')
		}
		let tagName = match[0].toLowerCase(),
			isVoid = voidElementsRegex.test(tagName)
		advanceTo(pos + tagName.length)

		// Keep reading content
		let selfClose = false,
			attributes = [],
			// Used to detect repeated attributes
			foundAttributeNames = []
		while (true) {
			// Match using anchored regex
			let match = tagOpenContentStartRegex.exec(source.substr(pos))
			if (!match) {
				throwSyntaxError('Invalid open tag')
			}

			advanceTo(pos + match[0].length)
			if (match[1] === '<%-') {
				throwSyntaxError('EJS unescaped tags are not allowed inside open tags')
			} else if (match[1] === '<%=') {
				throwSyntaxError('EJS escaped tags are not allowed inside open tags')
			} else if (match[1] === '<%') {
				throwSyntaxError('EJS eval tags are not allowed inside open tags')
			} else if (match[1] === '>') {
				break
			} else if (match[1] === '/>') {
				selfClose = true
				break
			} else {
				// Attribute start
				let lowerName = match[1].toLowerCase()
				if (foundAttributeNames.indexOf(lowerName) !== -1) {
					throwSyntaxError(`Repeated attribute ${match[1]} in open tag ${tagName}`)
				}
				foundAttributeNames.push(lowerName)
				attributes.push(readAttribute(lowerName))
			}
		}

		if (!isVoid && selfClose) {
			throwSyntaxError('Self-closed tags for non-void elements are not allowed')
		}

		return {
			type: 'element',
			start,
			end: getSourcePoint(),
			name: tagName,
			isVoid,
			attributes,
			children: []
		}
	}
168496
private void readDescription(TagValue tv) throws NumberFormatException, IOException {
    int index = 128;
    int tagCount = tv.getBytesBigEndian(index, 4);
    index += 4;
    for (int i = 0; i < tagCount; i++) {
      int signature = tv.getBytesBigEndian(index, 4);
      int tagOffset = tv.getBytesBigEndian(index + 4, 4);
      if (Integer.toHexString(signature).equals("64657363")) {
        String typedesc = Integer.toHexString(tv.getBytesBigEndian(tagOffset, 4));
        if (typedesc.equals("64657363")) {
          int size = tv.getBytesBigEndian(tagOffset + 8, 4) - 1;
          String s = "";
          int j = 0;
          int begin = tagOffset + 12;
          while (begin + j < begin + size) {
            int unicode_char = tv.getBytesBigEndian(begin + j, 1);
            s += Character.toString((char) unicode_char);
            j++;
          }
          description = s;
        } else {
          description = "";
        }
      }
      index += 12;
    }
  }
1136156
@Pure
	@SuppressWarnings("checkstyle:magicnumber")
	public static String parseHTML(String html) {
		if (html == null) {
			return null;
		}
		final Map<String, Integer> transTbl = getHtmlToJavaTranslationTable();
		assert transTbl != null;
		if (transTbl.isEmpty()) {
			return html;
		}
		final Pattern pattern = Pattern.compile("[&](([a-zA-Z]+)|(#x?[0-9]+))[;]"); //$NON-NLS-1$
		final Matcher matcher = pattern.matcher(html);
		final StringBuilder result = new StringBuilder();
		String entity;
		Integer isoCode;
		int lastIndex = 0;
		while (matcher.find()) {
			final int idx = matcher.start();
			result.append(html.substring(lastIndex, idx));
			lastIndex = matcher.end();
			entity = matcher.group(1);
			if (entity.startsWith("#x")) { //$NON-NLS-1$
				try {
					isoCode = Integer.valueOf(entity.substring(2), 16);
				} catch (Throwable exception) {
					isoCode = null;
				}
			} else if (entity.startsWith("#")) { //$NON-NLS-1$
				try {
					isoCode = Integer.valueOf(entity.substring(1));
				} catch (Throwable exception) {
					isoCode = null;
				}
			} else {
				isoCode = transTbl.get(entity);
			}

			if (isoCode == null) {
				result.append(matcher.group());
			} else {
				result.append((char) isoCode.intValue());
			}
		}
		if (lastIndex < html.length()) {
			result.append(html.substring(lastIndex));
		}
		return result.toString();
	}
1357843
function readKey ( parser ) {
  	var token;

  	if ( token = readStringLiteral( parser ) ) {
  		return identifier.test( token.v ) ? token.v : '"' + token.v.replace( /"/g, '\\"' ) + '"';
  	}

  	if ( token = readNumberLiteral$1( parser ) ) {
  		return token.v;
  	}

  	if ( token = parser.matchPattern( namePattern ) ) {
  		return token;
  	}

  	return null;
  }
368599
private Document parseInputSource(InputSource s) throws JspException {
        try {
            DocumentBuilder db = XmlUtil.newDocumentBuilder();
            db.setEntityResolver(entityResolver);
            return db.parse(s);
        } catch (SAXException e) {
            throw new JspException(e);
        } catch (IOException e) {
            throw new JspException(e);
        }
    }
182605
def _parse_entity(self):
        """"""
        reset = self._head
        try:
            self._push(contexts.HTML_ENTITY)
            self._really_parse_entity()
        except BadRoute:
            self._head = reset
            self._emit_text(self._read())
        else:
            self._emit_all(self._pop())