import{isHexDigit as t,isWhiteSpace as e,isValidEscape as r}from"../tokenizer/char-code-definitions.mjs";import{consumeEscaped as o,decodeEscaped as n}from"../tokenizer/utils.mjs";import"../tokenizer/TokenStream.mjs";function i(t){const e=t.length,i=t.charCodeAt(0),c=34===i||39===i?1:0,s=1===c&&e>1&&t.charCodeAt(e-1)===i?e-2:e-1;let a="";for(let i=c;i<=s;i++){let c=t.charCodeAt(i);if(92===c){if(i===s){i!==e-1&&(a=t.substr(i+1));break}if(c=t.charCodeAt(++i),r(92,c)){const e=i-1,r=o(t,e);i=r-1,a+=n(t.substring(e+1,r))}else 13===c&&10===t.charCodeAt(i+1)&&i++}else a+=t[i]}return a}function c(r,o){const n=o?"'":'"',i=o?39:34;let c="",s=!1;for(let o=0;o<r.length;o++){const n=r.charCodeAt(o);0!==n?n<=31||127===n?(c+="\\"+n.toString(16),s=!0):n===i||92===n?(c+="\\"+r.charAt(o),s=!1):(s&&(t(n)||e(n))&&(c+=" "),c+=r.charAt(o),s=!1):c+="�"}return n+c+n}export{i as decode,c as encode};