-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: interpret \u+xxxx and \m+1xxxx
- Loading branch information
Showing
3 changed files
with
35 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
const t={d:"°",c:"⌀",p:"±"} | ||
export const parseDxfTextContent=e=>{e=e.replace(/\\[uU]\+([0-9a-fA-F]{4})/g,(t,e)=>String.fromCodePoint(parseInt(e,16))) | ||
let o=0,n={text:""} | ||
const r=[n] | ||
for(const x of e.matchAll(/%%(\d\d\d|.)/g)){n.text+=e.slice(o,x.index) | ||
const s=x[1].toLowerCase(),c=t[s] | ||
c?n.text+=c:3===s.length?n.text+=String.fromCodePoint(+s):"k"===s||"o"===s||"u"===s?(n={...n,text:""},n[s]?delete n[s]:n[s]=1,r.push(n)):n.text+=s,o=x.index+x[0].length}return n.text+=e.slice(o),r.filter(t=>t.text)} | ||
const e={d:"°",c:"⌀",p:"±"} | ||
export const decodeDxfTextCharacterCodes=(e,t)=>(e=decodeDxfTextUnicodeCodePoints(e),t?decodeDxfTextMbcsCharacterCodes(e,t):e) | ||
export const decodeDxfTextUnicodeCodePoints=e=>e.replace(/\\[uU]\+([0-9a-fA-F]{4})/g,((e,t)=>String.fromCodePoint(parseInt(t,16)))) | ||
export const decodeDxfTextMbcsCharacterCodes=(e,t)=>{let o=t instanceof TextDecoder?t:void 0 | ||
return e.replace(/\\[mM]\+1([0-9a-fA-F]{2})([0-9a-fA-F]{2})/g,((e,d,n)=>(o=o||new TextDecoder(t)).decode(new Uint8Array([parseInt(d,16),parseInt(n,16)]))))} | ||
export const parseDxfTextContent=(t,o)=>{t=decodeDxfTextCharacterCodes(t,o?.encoding) | ||
let d=0,n={text:""} | ||
const c=[n] | ||
for(const o of t.matchAll(/%%(\d\d\d|.)/g)){n.text+=t.slice(d,o.index) | ||
const r=o[1].toLowerCase(),x=e[r] | ||
x?n.text+=x:3===r.length?n.text+=String.fromCodePoint(+r):"k"===r||"o"===r||"u"===r?(n={...n,text:""},n[r]?delete n[r]:n[r]=1,c.push(n)):n.text+=r,d=o.index+o[0].length}return n.text+=t.slice(d),c.filter((e=>e.text))} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters