import{n as e}from"./chunk-3THT3N7L-B1WzJUh4.mjs";import{r as t,t as n}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as r}from"./chunk-HWKDQ44K-BJxdK4fT.mjs";var i={name:`tr`,summary:`translate or delete characters`,usage:`tr [OPTION]... SET1 [SET2]`,options:[`-c, -C, --complement   use the complement of SET1`,`-d, --delete           delete characters in SET1`,`-s, --squeeze-repeats  squeeze repeated characters`,`    --help             display this help and exit`],description:`SET syntax:
  a-z         character range
  [:alnum:]   all letters and digits
  [:alpha:]   all letters
  [:digit:]   all digits
  [:lower:]   all lowercase letters
  [:upper:]   all uppercase letters
  [:space:]   all whitespace
  [:blank:]   horizontal whitespace
  [:punct:]   all punctuation
  [:print:]   all printable characters
  [:graph:]   all printable characters except space
  [:cntrl:]   all control characters
  [:xdigit:]  all hexadecimal digits
  \\n, \\t, \\r  escape sequences`},a=new Map([[`[:alnum:]`,`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`],[`[:alpha:]`,`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`],[`[:blank:]`,` 	`],[`[:cntrl:]`,Array.from({length:32},(e,t)=>String.fromCharCode(t)).join(``).concat(``)],[`[:digit:]`,`0123456789`],[`[:graph:]`,Array.from({length:94},(e,t)=>String.fromCharCode(33+t)).join(``)],[`[:lower:]`,`abcdefghijklmnopqrstuvwxyz`],[`[:print:]`,Array.from({length:95},(e,t)=>String.fromCharCode(32+t)).join(``)],[`[:punct:]`,`!"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~`],[`[:space:]`,` 	
\r\f\v`],[`[:upper:]`,`ABCDEFGHIJKLMNOPQRSTUVWXYZ`],[`[:xdigit:]`,`0123456789ABCDEFabcdef`]]);function o(e){let t=``,n=0;for(;n<e.length;){if(e[n]===`[`&&e[n+1]===`:`){let r=!1;for(let[i,o]of a)if(e.slice(n).startsWith(i)){t+=o,n+=i.length,r=!0;break}if(r)continue}if(e[n]===`\\`&&n+1<e.length){let r=e[n+1];r===`n`?t+=`
`:r===`t`?t+=`	`:r===`r`?t+=`\r`:t+=r,n+=2;continue}if(n+2<e.length&&e[n+1]===`-`){let r=e.charCodeAt(n),i=e.charCodeAt(n+2);if(i-r>65536)throw Error(`tr: character range too large: '${e[n]}-${e[n+2]}'`);for(let e=r;e<=i;e++)t+=String.fromCharCode(e);n+=3;continue}t+=e[n],n++}return t}var s={complement:{short:`c`,long:`complement`,type:`boolean`},complementUpper:{short:`C`,type:`boolean`},delete:{short:`d`,long:`delete`,type:`boolean`},squeeze:{short:`s`,long:`squeeze-repeats`,type:`boolean`}},c={name:`tr`,async execute(a,c){if(n(a))return t(i);let l=r(`tr`,a,s);if(!l.ok)return l.error;let u=l.result.flags.complement||l.result.flags.complementUpper,d=l.result.flags.delete,f=l.result.flags.squeeze,p=l.result.positional;if(p.length<1)return{stdout:``,stderr:`tr: missing operand
`,exitCode:1};if(!d&&!f&&p.length<2)return{stdout:``,stderr:`tr: missing operand after SET1
`,exitCode:1};let m,h;try{m=o(p[0]),h=p.length>1?o(p[1]):``}catch(t){return{stdout:``,stderr:`${e(t.message)}
`,exitCode:1}}let g=c.stdin,_=e=>{let t=m.includes(e);return u?!t:t},v=``;if(d)for(let e of g)_(e)||(v+=e);else if(f&&p.length===1){let e=``;for(let t of g)_(t)&&t===e||(v+=t,e=t)}else{if(u){let e=h.length>0?h[h.length-1]:``;for(let t of g)m.includes(t)?v+=t:v+=e}else{let e=new Map;for(let t=0;t<m.length;t++){let n=t<h.length?h[t]:h[h.length-1];e.set(m[t],n)}for(let t of g)v+=e.get(t)??t}if(f){let e=``,t=``;for(let n of v)h.includes(n)&&n===t||(e+=n,t=n);v=e}}return{stdout:v,stderr:``,exitCode:0}}},l={name:`tr`,flags:[{flag:`-c`,type:`boolean`},{flag:`-C`,type:`boolean`},{flag:`-d`,type:`boolean`},{flag:`-s`,type:`boolean`}],stdinType:`text`,needsArgs:!0};export{c as n,l as t};
//# sourceMappingURL=chunk-62RKD26F-DebCAz0V.mjs.map