/* Copyright Joshua Bell (chromium)
http://code.google.com/p/stringencoding/
license Apache 2.0 */

/* modif Ayms
global
*/

function inRange(c,d,b){return d<=c&&c<=b}function div(b,a){return Math.floor(b/a)}var EOF_byte=-1;var EOF_code_point=-1;function ByteInputStream(a){var b=0;this.get=function(){return(b>=a.length)?EOF_byte:Number(a[b])};this.offset=function(c){b+=c;if(b<0){throw new Error("Seeking past start of the buffer")}if(b>a.length){throw new Error("Seeking past EOF")}};this.match=function(d){if(d.length>b+a.length){return false}var c;for(c=0;c<d.length;c+=1){if(Number(a[b+c])!==d[c]){return false}}return true}}function ByteOutputStream(a){var b=0;this.emit=function(e){var d=EOF_byte;var c;for(c=0;c<arguments.length;++c){d=Number(arguments[c]);a[b++]=d}return d}}function CodePointInputStream(a){function b(g){var k=[];var h=0,m=g.length;while(h<g.length){var l=g.charCodeAt(h);if(!inRange(l,55296,57343)){k.push(l)}else{if(inRange(l,56320,57343)){k.push(65533)}else{if(h===m-1){k.push(65533)}else{var j=g.charCodeAt(h+1);if(inRange(j,56320,57343)){var f=l&1023;var e=j&1023;h+=1;k.push(65536+(f<<10)+e)}else{k.push(65533)}}}}h+=1}return k}var d=0;var c=b(a);this.offset=function(e){d+=e;if(d<0){throw new Error("Seeking past start of the buffer")}if(d>c.length){throw new Error("Seeking past EOF")}};this.get=function(){if(d>=c.length){return EOF_code_point}return c[d]}}function CodePointOutputStream(){var a="";this.string=function(){return a};this.emit=function(b){if(b<=65535){a+=String.fromCharCode(b)}else{b-=65536;a+=String.fromCharCode(55296+((b>>10)&1023));a+=String.fromCharCode(56320+(b&1023))}}}function EncodingError(a){this.name="EncodingError";this.message=a;this.code=0}EncodingError.prototype=Error.prototype;function decoderError(b,a){if(b){throw new EncodingError("Decoder error")}return a||65533}function encoderError(a){throw new EncodingError("The code point "+a+" could not be encoded.")}function getEncoding(a){a=String(a).trim().toLowerCase();if(Object.prototype.hasOwnProperty.call(label_to_encoding,a)){return label_to_encoding[a]}return null}var encodings=[{encodings:[{labels:["unicode-1-1-utf-8","utf-8","utf8"],name:"utf-8"}],heading:"The Encoding"},{encodings:[{labels:["cp864","ibm864"],name:"ibm864"},{labels:["cp866","ibm866"],name:"ibm866"},{labels:["csisolatin2","iso-8859-2","iso-ir-101","iso8859-2","iso_8859-2","l2","latin2"],name:"iso-8859-2"},{labels:["csisolatin3","iso-8859-3","iso_8859-3","iso-ir-109","l3","latin3"],name:"iso-8859-3"},{labels:["csisolatin4","iso-8859-4","iso_8859-4","iso-ir-110","l4","latin4"],name:"iso-8859-4"},{labels:["csisolatincyrillic","cyrillic","iso-8859-5","iso_8859-5","iso-ir-144"],name:"iso-8859-5"},{labels:["arabic","csisolatinarabic","ecma-114","iso-8859-6","iso_8859-6","iso-ir-127"],name:"iso-8859-6"},{labels:["csisolatingreek","ecma-118","elot_928","greek","greek8","iso-8859-7","iso_8859-7","iso-ir-126"],name:"iso-8859-7"},{labels:["csisolatinhebrew","hebrew","iso-8859-8","iso-8859-8-i","iso-ir-138","iso_8859-8","visual"],name:"iso-8859-8"},{labels:["csisolatin6","iso-8859-10","iso-ir-157","iso8859-10","l6","latin6"],name:"iso-8859-10"},{labels:["iso-8859-13"],name:"iso-8859-13"},{labels:["iso-8859-14","iso8859-14"],name:"iso-8859-14"},{labels:["iso-8859-15","iso_8859-15"],name:"iso-8859-15"},{labels:["iso-8859-16"],name:"iso-8859-16"},{labels:["koi8-r","koi8_r"],name:"koi8-r"},{labels:["koi8-u"],name:"koi8-u"},{labels:["csmacintosh","mac","macintosh","x-mac-roman"],name:"macintosh"},{labels:["iso-8859-11","tis-620","windows-874"],name:"windows-874"},{labels:["windows-1250","x-cp1250"],name:"windows-1250"},{labels:["windows-1251","x-cp1251"],name:"windows-1251"},{labels:["ascii","ansi_x3.4-1968","csisolatin1","iso-8859-1","iso8859-1","iso_8859-1","l1","latin1","us-ascii","windows-1252"],name:"windows-1252"},{labels:["cp1253","windows-1253"],name:"windows-1253"},{labels:["csisolatin5","iso-8859-9","iso-ir-148","l5","latin5","windows-1254"],name:"windows-1254"},{labels:["cp1255","windows-1255"],name:"windows-1255"},{labels:["cp1256","windows-1256"],name:"windows-1256"},{labels:["windows-1257"],name:"windows-1257"},{labels:["cp1258","windows-1258"],name:"windows-1258"},{labels:["x-mac-cyrillic","x-mac-ukrainian"],name:"x-mac-cyrillic"}],heading:"Legacy single-byte encodings"},{encodings:[{labels:["chinese","csgb2312","csiso58gb231280","gb2312","gbk","gb_2312","gb_2312-80","iso-ir-58","x-gbk"],name:"gbk"},{labels:["gb18030"],name:"gb18030"},{labels:["hz-gb-2312"],name:"hz-gb-2312"}],heading:"Legacy multi-byte Chinese (simplified) encodings"},{encodings:[{labels:["big5","big5-hkscs","cn-big5","csbig5","x-x-big5"],name:"big5"}],heading:"Legacy multi-byte Chinese (traditional) encodings"},{encodings:[{labels:["cseucpkdfmtjapanese","euc-jp","x-euc-jp"],name:"euc-jp"},{labels:["csiso2022jp","iso-2022-jp"],name:"iso-2022-jp"},{labels:["csshiftjis","ms_kanji","shift-jis","shift_jis","sjis","windows-31j","x-sjis"],name:"shift_jis"}],heading:"Legacy multi-byte Japanese encodings"},{encodings:[{labels:["cseuckr","csksc56011987","euc-kr","iso-ir-149","korean","ks_c_5601-1987","ks_c_5601-1989","ksc5601","ksc_5601","windows-949"],name:"euc-kr"},{labels:["csiso2022kr","iso-2022-kr"],name:"iso-2022-kr"}],heading:"Legacy multi-byte Korean encodings"},{encodings:[{labels:["utf-16","utf-16le"],name:"utf-16"},{labels:["utf-16be"],name:"utf-16be"}],heading:"Legacy utf-16 encodings"}];var name_to_encoding={};var label_to_encoding={};encodings.forEach(function(a){a.encodings.forEach(function(b){name_to_encoding[b.name]=b;b.labels.forEach(function(c){label_to_encoding[c]=b})})});function indexCodePointFor(b,a){return(a||[])[b]||null}function indexPointerFor(b,a){var c=a.indexOf(b);return c===-1?null:c}var indexes={};function indexGB18030CodePointFor(f){if((f>39419&&f<189000)||(f>1237575)){return null}var e=0,c=0,a=indexes.gb18030;var b;for(b=0;b<a.length;++b){var d=a[b];if(d[0]<=f){e=d[0];c=d[1]}else{break}}return c+f-e}function indexGB18030PointerFor(d){var f=0,c=0,a=indexes.gb18030;var b;for(b=0;b<a.length;++b){var e=a[b];if(e[1]<=d){f=e[1];c=e[0]}else{break}}return c+d-f}function UTF8Decoder(a){var e=a.fatal;var c=0,f=0,b=0,d=0;this.decode=function(g){var j=g.get();if(j===EOF_byte){if(f!==0){return decoderError(e)}return EOF_code_point}g.offset(1);if(f===0){if(inRange(j,0,127)){return j}if(inRange(j,194,223)){f=1;d=128;c=j-192}else{if(inRange(j,224,239)){f=2;d=2048;c=j-224}else{if(inRange(j,240,244)){f=3;d=65536;c=j-240}else{return decoderError(e)}}}c=c*Math.pow(64,f);return null}if(!inRange(j,128,191)){c=0;f=0;b=0;d=0;g.offset(-1);return decoderError(e)}b+=1;c=c+(j-128)*Math.pow(64,f-b);if(b!==f){return null}var h=c;var i=d;c=0;f=0;b=0;d=0;if(inRange(h,i,1114111)&&!inRange(h,55296,57343)){return h}return decoderError(e)}}function UTF8Encoder(a){var b=a.fatal;this.encode=function(i,d){var f=d.get();if(f===EOF_code_point){return EOF_byte}d.offset(1);if(inRange(f,55296,57343)){return encoderError(f)}if(inRange(f,0,127)){return i.emit(f)}var g,h;if(inRange(f,128,2047)){g=1;h=192}else{if(inRange(f,2048,65535)){g=2;h=224}else{if(inRange(f,65536,1114111)){g=3;h=240}}}var c=i.emit(div(f,Math.pow(64,g))+h);while(g>0){var e=div(f,Math.pow(64,g-1));c=i.emit(128+(e%64));g-=1}return c}}name_to_encoding["utf-8"].getEncoder=function(a){return new UTF8Encoder(a)};name_to_encoding["utf-8"].getDecoder=function(a){return new UTF8Decoder(a)};function SingleByteDecoder(b,a){var c=a.fatal;this.decode=function(d){var f=d.get();if(f===EOF_byte){return EOF_code_point}d.offset(1);if(inRange(f,0,127)){return f}var e=b[f-128];if(e===null){return decoderError(c)}return e}}function SingleByteEncoder(b,a){var c=a.fatal;this.encode=function(g,d){var e=d.get();if(e===EOF_code_point){return EOF_byte}d.offset(1);if(inRange(e,0,127)){return g.emit(e)}var f=indexPointerFor(e,b);if(f===null){encoderError(e)}return g.emit(f+128)}}(function(){["ibm864","ibm866","iso-8859-2","iso-8859-3","iso-8859-4","iso-8859-5","iso-8859-6","iso-8859-7","iso-8859-8","iso-8859-10","iso-8859-13","iso-8859-14","iso-8859-15","iso-8859-16","koi8-r","koi8-u","macintosh","windows-874","windows-1250","windows-1251","windows-1252","windows-1253","windows-1254","windows-1255","windows-1256","windows-1257","windows-1258","x-mac-cyrillic"].forEach(function(b){var c=name_to_encoding[b];var a=indexes[b];c.getDecoder=function(d){return new SingleByteDecoder(a,d)};c.getEncoder=function(d){return new SingleByteEncoder(a,d)}})}());function GBKDecoder(c,b){var f=b.fatal;var a=0,e=0,d=0;this.decode=function(g){var l=g.get();if(l===EOF_byte&&a===0&&e===0&&d===0){return EOF_code_point}if(l===EOF_byte&&(a!==0||e!==0||d!==0)){a=0;e=0;d=0;decoderError(f)}g.offset(1);var i;if(d!==0){i=null;if(inRange(l,48,57)){i=indexGB18030CodePointFor((((a-129)*10+(e-48))*126+(d-129))*10+l-48)}a=0;e=0;d=0;if(i===null){g.offset(-3);return decoderError(f)}return i}if(e!==0){if(inRange(l,129,254)){d=l;return null}g.offset(-2);a=0;e=0;return decoderError(f)}if(a!==0){if(inRange(l,48,57)&&c){e=l;return null}var h=a;var k=null;a=0;var j=l<127?64:65;if(inRange(l,64,126)||inRange(l,128,254)){k=(h-129)*190+(l-j)}i=k===null?null:indexCodePointFor(k,indexes.gbk);if(k===null){g.offset(-1)}if(i===null){return decoderError(f)}return i}if(inRange(l,0,127)){return l}if(l===128){return 8364}if(inRange(l,129,254)){a=l;return null}return decoderError(f)}}function GBKEncoder(b,a){var c=a.fatal;this.encode=function(h,k){var g=k.get();if(g===EOF_code_point){return EOF_byte}k.offset(1);if(inRange(g,0,127)){return h.emit(g)}var d=indexPointerFor(g,indexes.gbk);if(d!==null){var i=div(d,190)+129;var e=d%190;var f=e<63?64:65;return h.emit(i,e+f)}if(d===null&&!b){return encoderError(g)}d=indexGB18030PointerFor(g);var n=div(div(div(d,10),126),10);d=d-n*10*126*10;var m=div(div(d,10),126);d=d-m*10*126;var l=div(d,10);var j=d-l*10;return h.emit(n+129,m+48,l+129,j+48)}}name_to_encoding.gbk.getEncoder=function(a){return new GBKEncoder(false,a)};name_to_encoding.gbk.getDecoder=function(a){return new GBKDecoder(false,a)};name_to_encoding.gb18030.getEncoder=function(a){return new GBKEncoder(true,a)};name_to_encoding.gb18030.getDecoder=function(a){return new GBKDecoder(true,a)};function HZGB2312Decoder(c){var d=c.fatal;var b=false,a=0;this.decode=function(e){var h=e.get();if(h===EOF_byte&&a===0){return EOF_code_point}if(h===EOF_byte&&a!==0){a=0;return decoderError(d)}e.offset(1);if(a===126){a=0;if(h===123){b=true;return null}if(h===125){b=false;return null}if(h===126){return 126}if(h===10){return null}e.offset(-1);return decoderError(d)}if(a!==0){var f=a;a=0;var g=null;if(inRange(h,33,126)){g=indexCodePointFor((f-1)*190+(h+63),indexes.gbk)}if(h===10){b=false}if(g===null){return decoderError(d)}return g}if(h===126){a=126;return null}if(b){if(inRange(h,32,127)){a=h;return null}if(h===10){b=false}return decoderError(d)}if(inRange(h,0,127)){return h}return decoderError(d)}}function HZGB2312Encoder(b){var c=b.fatal;var a=false;this.encode=function(i,d){var g=d.get();if(g===EOF_code_point){return EOF_byte}d.offset(1);if(inRange(g,0,127)&&a){d.offset(-1);a=false;return i.emit(126,125)}if(g===126){return i.emit(126,126)}if(inRange(g,0,127)){return i.emit(g)}if(!a){d.offset(-1);a=true;return i.emit(126,123)}var h=indexPointerFor(g,indexes.gbk);if(h===null){return encoderError(g)}var f=div(h,190)+1;var e=h%190-63;if(!inRange(f,33,126)||!inRange(e,33,126)){return encoderError(g)}return i.emit(f,e)}}name_to_encoding["hz-gb-2312"].getEncoder=function(a){return new HZGB2312Encoder(a)};name_to_encoding["hz-gb-2312"].getDecoder=function(a){return new HZGB2312Decoder(a)};function Big5Decoder(b){var d=b.fatal;var a=0,c=null;this.decode=function(e){if(c!==null){var j=c;c=null;return j}var k=e.get();if(k===EOF_byte&&a===0){return EOF_code_point}if(k===EOF_byte&&a!==0){a=0;return decoderError(d)}e.offset(1);if(a!==0){var f=a;var i=null;a=0;var h=k<127?64:98;if(inRange(k,64,126)||inRange(k,161,254)){i=(f-129)*157+(k-h)}if(i===1133){c=772;return 202}if(i===1135){c=780;return 202}if(i===1164){c=772;return 234}if(i===1166){c=780;return 234}var g=(i===null)?null:indexCodePointFor(i,indexes.big5);if(i===null){e.offset(-1)}if(g===null){return decoderError(d)}return g}if(inRange(k,0,127)){return k}if(inRange(k,129,254)){a=k;return null}return decoderError(d)}}function Big5Encoder(a){var b=a.fatal;this.encode=function(i,c){var f=c.get();if(f===EOF_code_point){return EOF_byte}c.offset(1);if(inRange(f,0,127)){return i.emit(f)}var h=indexPointerFor(f,indexes.big5);if(h===null){return encoderError(f)}var e=div(h,157)+129;var d=h%157;var g=d<63?64:98;return i.emit(e,d+g)}}name_to_encoding.big5.getEncoder=function(a){return new Big5Encoder(a)};name_to_encoding.big5.getDecoder=function(a){return new Big5Decoder(a)};function EUCJPDecoder(a){var c=a.fatal;var b=0,d=0;this.decode=function(e){var h=e.get();if(h===EOF_byte){if(b===0&&d===0){return EOF_code_point}b=0;d=0;return decoderError(c)}e.offset(1);var f,g;if(d!==0){f=d;d=0;g=null;if(inRange(f,161,254)&&inRange(h,161,254)){g=indexCodePointFor((f-161)*94+h-161,indexes.jis0212)}if(!inRange(h,161,254)){e.offset(-1)}if(g===null){return decoderError(c)}return g}if(b===142&&inRange(h,161,223)){b=0;return 65377+h-161}if(b===143&&inRange(h,161,254)){b=0;d=h;return null}if(b!==0){f=b;b=0;g=null;if(inRange(f,161,254)&&inRange(h,161,254)){g=indexCodePointFor((f-161)*94+h-161,indexes.jis0208)}if(!inRange(h,161,254)){e.offset(-1)}if(g===null){return decoderError(c)}return g}if(inRange(h,0,127)){return h}if(h===142||h===143||(inRange(h,161,254))){b=h;return null}return decoderError(c)}}function EUCJPEncoder(a){var b=a.fatal;this.encode=function(h,c){var f=c.get();if(f===EOF_code_point){return EOF_byte}c.offset(1);if(inRange(f,0,127)){return h.emit(f)}if(f===165){return h.emit(92)}if(f===8254){return h.emit(126)}if(inRange(f,65377,65439)){return h.emit(142,f-65377+161)}var g=indexPointerFor(f,indexes.jis0208);if(g===null){return encoderError(f)}var e=div(g,94)+161;var d=g%94+161;return h.emit(e,d)}}name_to_encoding["euc-jp"].getEncoder=function(a){return new EUCJPEncoder(a)};name_to_encoding["euc-jp"].getDecoder=function(a){return new EUCJPDecoder(a)};function ISO2022JPDecoder(a){var d=a.fatal;var c={ASCII:0,escape_start:1,escape_middle:2,escape_final:3,lead:4,trail:5,Katakana:6};var e=c.ASCII,f=false,b=0;this.decode=function(g){var k=g.get();if(k!==EOF_byte){g.offset(1)}switch(e){default:case c.ASCII:if(k===27){e=c.escape_start;return null}if(inRange(k,0,127)){return k}if(k===EOF_byte){return EOF_code_point}return decoderError(d);case c.escape_start:if(k===36||k===40){b=k;e=c.escape_middle;return null}if(k!==EOF_byte){g.offset(-1)}e=c.ASCII;return decoderError(d);case c.escape_middle:var h=b;b=0;if(h===36&&(k===64||k===66)){f=false;e=c.lead;return null}if(h===36&&k===40){e=c.escape_final;return null}if(h===40&&(k===66||k===74)){e=c.ASCII;return null}if(h===40&&k===73){e=c.Katakana;return null}if(k===EOF_byte){g.offset(-1)}else{g.offset(-2)}e=c.ASCII;return decoderError(d);case c.escape_final:if(k===68){f=true;e=c.lead;return null}if(k===EOF_byte){g.offset(-2)}else{g.offset(-3)}e=c.ASCII;return decoderError(d);case c.lead:if(k===10){e=c.ASCII;return decoderError(d,10)}if(k===27){e=c.escape_start;return null}if(k===EOF_byte){return EOF_code_point}b=k;e=c.trail;return null;case c.trail:e=c.lead;if(k===EOF_byte){return decoderError(d)}var i=null;var j=(b-33)*94+k-33;if(inRange(b,33,126)&&inRange(k,33,126)){i=(f===false)?indexCodePointFor(j,indexes.jis0208):indexCodePointFor(j,indexes.jis0212)}if(i===null){return decoderError(d)}return i;case c.Katakana:if(k===27){e=c.escape_start;return null}if(inRange(k,33,95)){return 65377+k-33}if(k===EOF_byte){return EOF_code_point}return decoderError(d)}}}function ISO2022JPEncoder(a){var c=a.fatal;var b={ASCII:0,lead:1,Katakana:2};var d=b.ASCII;this.encode=function(j,e){var h=e.get();if(h===EOF_code_point){return EOF_byte}e.offset(1);if((inRange(h,0,127)||h===165||h===8254)&&d!==b.ASCII){e.offset(-1);d=b.ASCII;return j.emit(27,40,66)}if(inRange(h,0,127)){return j.emit(h)}if(h===165){return j.emit(92)}if(h===8254){return j.emit(126)}if(inRange(h,65377,65439)&&d!==b.Katakana){e.offset(-1);d=b.Katakana;return j.emit(27,40,73)}if(inRange(h,65377,65439)){return j.emit(h-65377-33)}if(d!==b.lead){e.offset(-1);d=b.lead;return j.emit(27,36,66)}var i=indexPointerFor(h,indexes.jis0208);if(i===null){return encoderError(h)}var g=div(i,94)+33;var f=i%94+33;return j.emit(g,f)}}name_to_encoding["iso-2022-jp"].getEncoder=function(a){return new ISO2022JPEncoder(a)};name_to_encoding["iso-2022-jp"].getDecoder=function(a){return new ISO2022JPDecoder(a)};function ShiftJISDecoder(a){var c=a.fatal;var b=0;this.decode=function(d){var i=d.get();if(i===EOF_byte&&b===0){return EOF_code_point}if(i===EOF_byte&&b!==0){b=0;return decoderError(c)}d.offset(1);if(b!==0){var e=b;b=0;if(inRange(i,64,126)||inRange(i,128,252)){var g=(i<127)?64:65;var h=(e<160)?129:193;var f=indexCodePointFor((e-h)*188+i-g,indexes.jis0208);if(f===null){return decoderError(c)}return f}d.offset(-1);return decoderError(c)}if(inRange(i,0,128)){return i}if(inRange(i,161,223)){return 65377+i-161}if(inRange(i,129,159)||inRange(i,224,252)){b=i;return null}return decoderError(c)}}function ShiftJISEncoder(a){var b=a.fatal;this.encode=function(i,c){var f=c.get();if(f===EOF_code_point){return EOF_byte}c.offset(1);if(inRange(f,0,128)){return i.emit(f)}if(f===165){return i.emit(92)}if(f===8254){return i.emit(126)}if(inRange(f,65377,65439)){return i.emit(f-65377+161)}var h=indexPointerFor(f,indexes.jis0208);if(h===null){return encoderError(f)}var e=div(h,188);var j=e<31?129:193;var d=h%188;var g=d<63?64:65;return i.emit(e+j,d+g)}}name_to_encoding.shift_jis.getEncoder=function(a){return new ShiftJISEncoder(a)};name_to_encoding.shift_jis.getDecoder=function(a){return new ShiftJISDecoder(a)};function EUCKRDecoder(b){var c=b.fatal;var a=0;this.decode=function(e){var i=e.get();if(i===EOF_byte&&a===0){return EOF_code_point}if(i===EOF_byte&&a!==0){a=0;return decoderError(c)}e.offset(1);if(a!==0){var f=a;var h=null;a=0;if(inRange(f,129,198)){var d=(26+26+126)*(f-129);if(inRange(i,65,90)){h=d+i-65}else{if(inRange(i,97,122)){h=d+26+i-97}else{if(inRange(i,129,254)){h=d+26+26+i-129}}}}if(inRange(f,199,253)&&inRange(i,161,254)){h=(26+26+126)*(199-129)+(f-199)*94+(i-161)}var g=(h===null)?null:indexCodePointFor(h,indexes["euc-kr"]);if(h===null){e.offset(-1)}if(g===null){return decoderError(c)}return g}if(inRange(i,0,127)){return i}if(inRange(i,129,253)){a=i;return null}return decoderError(c)}}function EUCKREncoder(a){var b=a.fatal;this.encode=function(i,c){var f=c.get();if(f===EOF_code_point){return EOF_byte}c.offset(1);if(inRange(f,0,127)){return i.emit(f)}var h=indexPointerFor(f,indexes["euc-kr"]);if(h===null){return encoderError(f)}var e,d;if(h<((26+26+126)*(199-129))){e=div(h,(26+26+126))+129;d=h%(26+26+126);var g=d<26?65:d<26+26?71:77;return i.emit(e,d+g)}h=h-(26+26+126)*(199-129);e=div(h,94)+199;d=h%94+161;return i.emit(e,d)}}name_to_encoding["euc-kr"].getEncoder=function(a){return new EUCKREncoder(a)};name_to_encoding["euc-kr"].getDecoder=function(a){return new EUCKRDecoder(a)};function ISO2022KRDecoder(b){var e=b.fatal;var c={ASCII:0,escape_start:1,escape_middle:2,escape_end:3,lead:4,trail:5};var a=c.ASCII,d=0;this.decode=function(f){var h=f.get();if(h!==EOF_byte){f.offset(1)}switch(a){default:case c.ASCII:if(h===14){a=c.lead;return null}if(h===15){return null}if(h===27){a=c.escape_start;return null}if(inRange(h,0,127)){return h}if(h===EOF_byte){return EOF_code_point}return decoderError(e);case c.escape_start:if(h===36){a=c.escape_middle;return null}if(h!==EOF_byte){f.offset(-1)}a=c.ASCII;return decoderError(e);case c.escape_middle:if(h===41){a=c.escape_end;return null}if(h===EOF_byte){f.offset(-1)}else{f.offset(-2)}a=c.ASCII;return decoderError(e);case c.escape_end:if(h===67){a=c.ASCII;return null}if(h===EOF_byte){f.offset(-2)}else{f.offset(-3)}a=c.ASCII;return decoderError(e);case c.lead:if(h===10){a=c.ASCII;return decoderError(e,10)}if(h===14){return null}if(h===15){a=c.ASCII;return null}if(h===EOF_byte){return EOF_code_point}d=h;a=c.trail;return null;case c.trail:a=c.lead;if(h===EOF_byte){return decoderError(e)}var g=null;if(inRange(d,33,70)&&inRange(h,33,126)){g=indexCodePointFor((26+26+126)*(d-1)+26+26+h-1,indexes["euc-kr"])}else{if(inRange(d,71,126)&&inRange(h,33,126)){g=indexCodePointFor((26+26+126)*(199-129)+(d-71)*94+(h-33),indexes["euc-kr"])}}if(g!==null){return g}return decoderError(e)}}}function ISO2022KREncoder(b){var e=b.fatal;var d={ASCII:0,lead:1};var c=false,a=d.ASCII;this.encode=function(k,f){var i=f.get();if(i===EOF_code_point){return EOF_byte}if(!c){c=true;k.emit(27,36,41,67)}f.offset(1);if(inRange(i,0,127)&&a!==d.ASCII){f.offset(-1);a=d.ASCII;return k.emit(15)}if(inRange(i,0,127)){return k.emit(i)}if(a!==d.lead){f.offset(-1);a=d.lead;return k.emit(14)}var j=indexPointerFor(i,indexes["euc-kr"]);if(j===null){return encoderError(i)}var h,g;if(j<(26+26+126)*(199-129)){h=div(j,(26+26+126))+1;g=j%(26+26+126)-26-26+1;if(!inRange(h,33,70)||!inRange(g,33,126)){return encoderError(i)}return k.emit(h,g)}j=j-(26+26+126)*(199-129);h=div(j,94)+71;g=j%94+33;if(!inRange(h,71,126)||!inRange(g,33,126)){return encoderError(i)}return k.emit(h,g)}}name_to_encoding["iso-2022-kr"].getEncoder=function(a){return new ISO2022KREncoder(a)};name_to_encoding["iso-2022-kr"].getDecoder=function(a){return new ISO2022KRDecoder(a)};function UTF16Decoder(e,b){var d=b.fatal;var c=null,a=null;this.decode=function(f){var i=f.get();if(i===EOF_byte&&c===null&&a===null){return EOF_code_point}if(i===EOF_byte&&(c!==null||a!==null)){return decoderError(d)}f.offset(1);if(c===null){c=i;return null}var g;if(e){g=(c<<8)+i}else{g=(i<<8)+c}c=null;if(a!==null){var h=a;a=null;if(inRange(g,56320,57343)){return 65536+(h-55296)*1024+(g-56320)}f.offset(-2);return decoderError(d)}if(inRange(g,55296,56319)){a=g;return null}if(inRange(g,56320,57343)){return decoderError(d)}return g}}function UTF16Encoder(c,a){var b=a.fatal;this.encode=function(i,e){function d(l){var k=l>>8;var j=l&255;if(c){return i.emit(k,j)}return i.emit(j,k)}var h=e.get();if(h===EOF_code_point){return EOF_byte}e.offset(1);if(inRange(h,55296,57343)){encoderError(h)}if(h<=65535){return d(h)}var g=div((h-65536),1024)+55296;var f=((h-65536)%1024)+56320;d(g);return d(f)}}name_to_encoding["utf-16"].getEncoder=function(a){return new UTF16Encoder(false,a)};name_to_encoding["utf-16"].getDecoder=function(a){return new UTF16Decoder(false,a)};name_to_encoding["utf-16be"].getEncoder=function(a){return new UTF16Encoder(true,a)};name_to_encoding["utf-16be"].getDecoder=function(a){return new UTF16Decoder(true,a)};function detectEncoding(a,b){if(b.match([255,254])){b.offset(2);return"utf-16"}if(b.match([254,255])){b.offset(2);return"utf-16be"}if(b.match([239,187,191])){b.offset(3);return"utf-8"}return a}function consumeBOM(a,b){if(b.match([255,254])&&a==="utf-16"){b.offset(2);return}if(b.match([254,255])&&a=="utf-16be"){b.offset(2);return}if(b.match([239,187,191])&&a=="utf-8"){b.offset(3);return}}var DEFAULT_ENCODING="utf-8";function TextEncoder(b,a){b=b?String(b):DEFAULT_ENCODING;a=Object(a);this._encoding=getEncoding(b);if(this._encoding===null||(this._encoding.name!=="utf-8"&&this._encoding.name!=="utf-16"&&this._encoding.name!=="utf-16be")){throw new TypeError("Unknown encoding: "+b)}this._streaming=false;this._encoder=null;this._options={fatal:Boolean(a.fatal)};if(Object.defineProperty){Object.defineProperty(this,"encoding",{get:function(){return this._encoding.name}})}else{this.encoding=this._encoding.name}return this}TextEncoder.prototype={encode:function encode(b,e){b=b?String(b):"";e=Object(e);if(!this._streaming){this._encoder=this._encoding.getEncoder(this._options)}this._streaming=Boolean(e.stream);var c=[];var d=new ByteOutputStream(c);var f=new CodePointInputStream(b);while(f.get()!==EOF_code_point){this._encoder.encode(d,f)}if(!this._streaming){var a;do{a=this._encoder.encode(d,f)}while(a!==EOF_byte);this._encoder=null}return new Uint8Array(c)}};function TextDecoder(b,a){b=b?String(b):DEFAULT_ENCODING;a=Object(a);this._encoding=getEncoding(b);if(this._encoding===null){throw new TypeError("Unknown encoding: "+b)}this._streaming=false;this._decoder=null;this._options={fatal:Boolean(a.fatal)};if(Object.defineProperty){Object.defineProperty(this,"encoding",{get:function(){return this._encoding.name}})}else{this.encoding=this._encoding.name}return this}TextDecoder.prototype={decode:function decode(e,c){if(e&&!("buffer" in e&&"byteOffset" in e&&"byteLength" in e)){throw new TypeError("Expected ArrayBufferView")}else{if(!e){e=new Uint8Array(0)}}c=Object(c);if(!this._streaming){this._decoder=this._encoding.getDecoder(this._options)}this._streaming=Boolean(c.stream);var a=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);var f=new ByteInputStream(a);if(!this._BOMseen){this._BOMseen=true;consumeBOM(this._encoding.name,f)}var b=new CodePointOutputStream(),d;while(f.get()!==EOF_byte){d=this._decoder.decode(f);if(d!==null&&d!==EOF_code_point){b.emit(d)}}if(!this._streaming){do{d=this._decoder.decode(f);if(d!==null&&d!==EOF_code_point){b.emit(d)}}while(d!==EOF_code_point&&f.get()!=EOF_byte);this._decoder=null}return b.string()}};