{"version":3,"file":"string.mjs","names":[],"sources":["../../../../src/common/bin/lib0/string.ts"],"sourcesContent":["/**\n * Original at https://github.com/dmonad/lib0\n *\n * Utility module to work with strings.\n */\n\n// export const fromCharCode = String.fromCharCode\n// export const fromCodePoint = String.fromCodePoint\n\nfunction toLowerCase(s: string): string {\n  return s.toLowerCase()\n}\n\nconst trimLeftRegex = /^\\s*/g\n\nexport function trimLeft(s: string): string {\n  return s.replace(trimLeftRegex, '')\n}\n\nconst fromCamelCaseRegex = /([A-Z])/g\n\nexport function fromCamelCase(s: string, separator: string): string {\n  return trimLeft(s.replace(fromCamelCaseRegex, match => `${separator}${toLowerCase(match)}`))\n}\n\n/**\n * Compute the utf8ByteLength\n */\nexport function utf8ByteLength(str: string): number {\n  return unescape(encodeURIComponent(str)).length\n}\n\nexport function _encodeUtf8Polyfill(str: string): Uint8Array {\n  const encodedString = unescape(encodeURIComponent(str))\n  const len = encodedString.length\n  const buf = new Uint8Array(len)\n  for (let i = 0; i < len; i++)\n    buf[i] = (encodedString.codePointAt(i) as number)\n\n  return buf\n}\n\nlet utf8TextEncoder: TextEncoder | undefined | null\n\nexport function getUtf8TextEncoder(): TextEncoder | null {\n  if (utf8TextEncoder === undefined)\n    utf8TextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null)\n  return utf8TextEncoder\n}\n\nexport function encodeUtf8(str: string): Uint8Array {\n  return getUtf8TextEncoder()\n    ? utf8TextEncoder!.encode(str)\n    : _encodeUtf8Polyfill(str)\n}\n\nfunction _decodeUtf8Polyfill(buf: Uint8Array): string {\n  let remainingLen = buf.length\n  let encodedString = ''\n  let bufPos = 0\n  while (remainingLen > 0) {\n    const nextLen = remainingLen < 10000 ? remainingLen : 10000\n    const bytes = buf.subarray(bufPos, bufPos + nextLen)\n    bufPos += nextLen\n    // Starting with ES5.1 we can supply a generic array-like object as arguments\n    encodedString += String.fromCodePoint(...bytes as any)\n    remainingLen -= nextLen\n  }\n  return decodeURIComponent(escape(encodedString))\n}\n\nlet utf8TextDecoder: any\n\nexport function getUtf8TextDecoder(): TextDecoder | undefined {\n  if (utf8TextDecoder === undefined) {\n    utf8TextDecoder = (typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })) ?? null\n    if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {\n      // Safari doesn't handle BOM correctly.\n      // This fixes a bug in Safari 13.0.5 where it produces a BOM the first time it is called.\n      // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the first call and\n      // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the second call\n      // Another issue is that from then on no BOM chars are recognized anymore\n      utf8TextDecoder = null\n    }\n  }\n  return utf8TextDecoder\n}\n\nexport function decodeUtf8(buf: Uint8Array): string {\n  return getUtf8TextDecoder()\n    ? utf8TextDecoder.decode(buf)\n    : _decodeUtf8Polyfill(buf)\n}\n\nexport function splice(str: string, index: number, remove: number, insert = '') {\n  return str.slice(0, index) + insert + str.slice(index + remove)\n}\n"],"mappings":";;;;;;AASA,SAAS,YAAY,GAAmB;AACtC,QAAO,EAAE,aAAa;;AAGxB,MAAM,gBAAgB;AAEtB,SAAgB,SAAS,GAAmB;AAC1C,QAAO,EAAE,QAAQ,eAAe,GAAG;;AAGrC,MAAM,qBAAqB;AAE3B,SAAgB,cAAc,GAAW,WAA2B;AAClE,QAAO,SAAS,EAAE,QAAQ,qBAAoB,UAAS,GAAG,YAAY,YAAY,MAAM,GAAG,CAAC;;;;;AAM9F,SAAgB,eAAe,KAAqB;AAClD,QAAO,SAAS,mBAAmB,IAAI,CAAC,CAAC;;AAG3C,SAAgB,oBAAoB,KAAyB;CAC3D,MAAM,gBAAgB,SAAS,mBAAmB,IAAI,CAAC;CACvD,MAAM,MAAM,cAAc;CAC1B,MAAM,MAAM,IAAI,WAAW,IAAI;AAC/B,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IACvB,KAAI,KAAM,cAAc,YAAY,EAAE;AAExC,QAAO;;A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