import { unescapeAll as f } from "../common/utils.js";
function u(n, l, t, c) {
  let o, r = l;
  const e = {
    // if `true`, this is a valid link title
    ok: !1,
    // if `true`, this link can be continued on the next line
    can_continue: !1,
    // if `ok`, it's the position of the first character after the closing marker
    pos: 0,
    // if `ok`, it's the unescaped title
    str: "",
    // expected closing marker character code
    marker: 0
  };
  if (c)
    e.str = c.str, e.marker = c.marker;
  else {
    if (r >= t)
      return e;
    let i = n.charCodeAt(r);
    if (i !== 34 && i !== 39 && i !== 40)
      return e;
    l++, r++, i === 40 && (i = 41), e.marker = i;
  }
  for (; r < t; ) {
    if (o = n.charCodeAt(r), o === e.marker)
      return e.pos = r + 1, e.str += f(n.slice(l, r)), e.ok = !0, e;
    if (o === 40 && e.marker === 41)
      return e;
    o === 92 && r + 1 < t && r++, r++;
  }
  return e.can_continue = !0, e.str += f(n.slice(l, r)), e;
}
export {
  u as default
};
