whisper.cat/weboasis/text/cleaner/js/modules/unorm.js

2 lines
133 KiB
JavaScript
Raw Permalink Normal View History

2023-10-05 23:28:32 +11:00
!function(t){"use strict";for(var i=[null,0,{}],a=44032,h=4352,c=function(t,r){this.codepoint=t,this.feature=r},o={},s=[],r=0;r<=255;++r)s[r]=0;var e=[function(t,r,e){return r<60||13311<r&&r<42607?new c(r,i):t(r,e)},function(t,r,e){var n=o[r];return n||(n=t(r,e)).feature&&10<++s[r>>8&255]&&(o[r]=n),n},function(t,r,e){return e?t(r,e):new c(r,null)},function(t,r,e){var n;if(r<h||4371<=r&&r<a||55204<r)return t(r,e);if(h<=r&&r<4371){var i={},o=21*(r-h);for(n=0;n<21;++n)i[4449+n]=a+28*(n+o);return new c(r,[,,i])}var s=r-a,u=s%28,f=[];if(0!==u)f[0]=[a+s-u,4519+u];else for(f[0]=[h+Math.floor(s/588),4449+Math.floor(s%588/28)],f[2]={},n=1;n<28;++n)f[2][4519+n]=r+n;return new c(r,f)},function(t,r,e){var n=(c.udata[65280&r]||{})[r];return new c(r,n||i)}];c.fromCharCode=e.reduceRight(function(e,n){return function(t,r){return n(e,t,r)}},null),c.isHighSurrogate=function(t){return 55296<=t&&t<=56319},c.isLowSurrogate=function(t){return 56320<=t&&t<=57343},c.prototype.prepFeature=function(){this.feature||(this.feature=c.fromCharCode(this.codepoint,!0).feature)},c.prototype.toString=function(){if(this.codepoint<65536)return String.fromCharCode(this.codepoint);var t=this.codepoint-65536;return String.fromCharCode(Math.floor(t/1024)+55296,t%1024+56320)},c.prototype.getDecomp=function(){return this.prepFeature(),this.feature[0]||null},c.prototype.isCompatibility=function(){return this.prepFeature(),!!this.feature[1]&&256&this.feature[1]},c.prototype.isExclude=function(){return this.prepFeature(),!!this.feature[1]&&512&this.feature[1]},c.prototype.getCanonicalClass=function(){return this.prepFeature(),this.feature[1]?255&this.feature[1]:0},c.prototype.getComposite=function(t){if(this.prepFeature(),!this.feature[2])return null;var r=this.feature[2][t.codepoint];return r?c.fromCharCode(r):null};var u=function(t){this.str=t,this.cursor=0};u.prototype.next=function(){if(this.str&&this.cursor<this.str.length){var t,r=this.str.charCodeAt(this.cursor++);return c.isHighSurrogate(r)&&this.cursor<this.str.length&&c.isLowSurrogate(t=this.str.charCodeAt(this.cursor))&&(r=1024*(r-55296)+(t-56320)+65536,++this.cursor),c.fromCharCode(r)}return this.str=null};var f=function(t,r){this.it=t,this.canonical=r,this.resBuf=[]};f.prototype.next=function(){if(0===this.resBuf.length){var t=this.it.next();if(!t)return null;this.resBuf=function t(r,e){var n=e.getDecomp();if(!n||r&&e.isCompatibility())return[e];for(var i=[],o=0;o<n.length;++o){var s=t(r,c.fromCharCode(n[o]));i=i.concat(s)}return i}(this.canonical,t)}return this.resBuf.shift()};var p=function(t){this.it=t,this.resBuf=[]};p.prototype.next=function(){var t;if(0===this.resBuf.length)do{var r=this.it.next();if(!r)break;t=r.getCanonicalClass();var e=this.resBuf.length;if(0!==t)for(;0<e;--e){if(this.resBuf[e-1].getCanonicalClass()<=t)break}this.resBuf.splice(e,0,r)}while(0!==t);return this.resBuf.shift()};var l=function(t){this.it=t,this.procBuf=[],this.resBuf=[],this.lastClass=null};l.prototype.next=function(){for(;0===this.resBuf.length;){var t=this.it.next();if(!t){this.resBuf=this.procBuf,this.procBuf=[];break}if(0===this.procBuf.length)this.lastClass=t.getCanonicalClass(),this.procBuf.push(t);else{var r=this.procBuf[0].getComposite(t),e=t.getCanonicalClass();r&&(this.lastClass<e||0===this.lastClass)?this.procBuf[0]=r:(0===e&&(this.resBuf=this.procBuf,this.procBuf=[]),this.lastClass=e,this.procBuf.push(t))}}return this.resBuf.shift()};var n=function(t,r){for(var e,n=function(t,r){switch(t){case"NFD":return new p(new f(new u(r),!0));case"NFKD":return new p(new f(new u(r),!1));case"NFC":return new l(new p(new f(new u(r),!0)));case"NFKC":return new l(new p(new f(new u(r),!1)))}throw t+" is invalid"}(t,r),i="";e=n.next();)i+=e.toString();return i};c.udata={0:{60:[,,{824:8814}],61:[,,{824:8800}],62:[,,{824:8815}],65:[,,{768:192,769:193,770:194,771:195,772:256,774:258,775:550,776:196,777:7842,778:197,780:461,783:512,785:514,803:7840,805:7680,808:260}],66:[,,{775:7682,803:7684,817:7686}],67:[,,{769:262,770:264,775:266,780:268,807:199}],68:[,,{775:7690,780:270,803:7692,807:7696,813:7698,817:7694}],69:[,,{768:200