import { fromCodePoint as i, isValidEntityCode as f } from "../common/utils.js";
import { decodeHTML as p } from "../../../entities/lib/esm/decode.js";
const a = /^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));/i, u = /^&([a-z][a-z0-9]{1,31});/i;
function m(c, r) {
  const t = c.pos, s = c.posMax;
  if (c.src.charCodeAt(t) !== 38 || t + 1 >= s) return !1;
  if (c.src.charCodeAt(t + 1) === 35) {
    const o = c.src.slice(t).match(a);
    if (o) {
      if (!r) {
        const e = o[1][0].toLowerCase() === "x" ? parseInt(o[1].slice(1), 16) : parseInt(o[1], 10), n = c.push("text_special", "", 0);
        n.content = f(e) ? i(e) : i(65533), n.markup = o[0], n.info = "entity";
      }
      return c.pos += o[0].length, !0;
    }
  } else {
    const o = c.src.slice(t).match(u);
    if (o) {
      const e = p(o[0]);
      if (e !== o[0]) {
        if (!r) {
          const n = c.push("text_special", "", 0);
          n.content = e, n.markup = o[0], n.info = "entity";
        }
        return c.pos += o[0].length, !0;
      }
    }
  }
  return !1;
}
export {
  m as default
};
