"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var spec_exports = {};
__export(spec_exports, {
  escapeRegExpFallback: () => escapeRegExpFallback,
  isSpecHexEscapeCp: () => isSpecHexEscapeCp
});
module.exports = __toCommonJS(spec_exports);
var import_map_set = require("../primordials/map-set");
var import_string = require("../primordials/string");
var import_hex = require("./hex");
const SYNTAX_CHARACTERS = new import_map_set.SetCtor("^$\\.*+?()[]{}|/");
const CONTROL_ESCAPES = new import_map_set.MapCtor([
  [9, "\\t"],
  [10, "\\n"],
  [11, "\\v"],
  [12, "\\f"],
  [13, "\\r"]
]);
const OTHER_PUNCTUATORS = new import_map_set.SetCtor(",-=<>#&!%:;@~'`\"");
function escapeRegExpFallback(str) {
  let out = "";
  let isFirst = true;
  for (const char of str) {
    const cp = (0, import_string.StringPrototypeCodePointAt)(char, 0);
    if (isFirst && (cp >= 48 && cp <= 57 || cp >= 65 && cp <= 90 || cp >= 97 && cp <= 122)) {
      out += "\\x" + (0, import_hex.hex2)(cp);
    } else if (SYNTAX_CHARACTERS.has(char)) {
      out += "\\" + char;
    } else {
      const ctrl = CONTROL_ESCAPES.get(cp);
      if (ctrl !== void 0) {
        out += ctrl;
      } else if (isSpecHexEscapeCp(cp)) {
        if (cp <= 255) {
          out += "\\x" + (0, import_hex.hex2)(cp);
        } else {
          for (let i = 0; i < char.length; i++) {
            out += "\\u" + (0, import_hex.hex4)((0, import_string.StringPrototypeCharCodeAt)(char, i));
          }
        }
      } else {
        out += char;
      }
    }
    isFirst = false;
  }
  return out;
}
function isSpecHexEscapeCp(cp) {
  if (OTHER_PUNCTUATORS.has((0, import_string.StringFromCodePoint)(cp))) {
    return true;
  }
  if (cp === 10 || cp === 13 || cp === 8232 || cp === 8233) {
    return true;
  }
  if (cp === 9 || cp === 11 || cp === 12 || cp === 32 || cp === 160 || cp === 65279) {
    return true;
  }
  if (cp >= 55296 && cp <= 57343) {
    return true;
  }
  return false;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  escapeRegExpFallback,
  isSpecHexEscapeCp
});
