mol_charset_ucf_lib 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > [UCF](https://page.hyoo.ru/#!=1woher_nlk5d3) - Simple compact unicode text binarization format.
4
4
 
5
- ![](https://habrastorage.org/webt/vt/dh/un/vtdhunkbk7tztverhjedla2bzhi.png)
5
+ ![](https://habrastorage.org/webt/hj/r6/lr/hjr6lrivvtdevnuwa99v8__njn0.png)
6
6
 
7
7
  # Usage
8
8
 
@@ -24,8 +24,14 @@ import {
24
24
 
25
25
  # Benchmarks
26
26
 
27
+ System: Chrome 143, Win 10, i7-6600U 2.60GHz
28
+
27
29
  ## Encoding perf
28
- ![](https://habrastorage.org/webt/4j/nh/iz/4jnhizmmtjbomjwq45_p8vhab-i.png)
30
+ [Online](https://perf.js.hyoo.ru/#!bench=yl2hcs_rfamzi)
31
+
32
+ ![](https://habrastorage.org/webt/xy/0w/qn/xy0wqnvz9vlc2uwmcbbwm98a3v0.png)
29
33
 
30
34
  ## Decoding perf
31
- ![](https://habrastorage.org/webt/9u/xp/hb/9uxphba95qedw9wdyyd0rueesww.png)
35
+ [Online](https://perf.js.hyoo.ru/#!bench=hlj49x_hdq7va)
36
+
37
+ ![](https://habrastorage.org/webt/t5/lj/7l/t5lj7lwg97tzih7cpukqg7k6j88.png)
package/node.d.ts CHANGED
@@ -20,6 +20,7 @@ declare namespace $ {
20
20
 
21
21
  declare namespace $ {
22
22
  function $mol_charset_ucf_encode(str: string): Uint8Array<ArrayBuffer>;
23
+ function $mol_charset_ucf_encode_to(str: string, buf: Uint8Array<ArrayBuffer>, from?: number): number;
23
24
  }
24
25
 
25
26
  declare namespace $ {
package/node.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../mam.d.ts","../../../buffer/buffer.d.ts","../../encode/encode.d.ts","../../decode/decode.d.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACfA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA","sourcesContent":[null,null,null,null]}
1
+ {"version":3,"sources":["../../../../../mam.d.ts","../../../buffer/buffer.d.ts","../../encode/encode.d.ts","../../decode/decode.d.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACfA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;AACA;ACJA;AACA;AACA;AACA","sourcesContent":[null,null,null,null]}
package/node.deps.json CHANGED
@@ -1 +1 @@
1
- {"files":["mam.ts","LICENSE","README.md","mam.jam.js","tsfmt.json","package.json","tsconfig.json","lang.lang.tree","meta.lang.tree","sandbox.config.json","mol/CNAME","mol/LICENSE","mol/readme.md","mol/mol.meta.tree","mol/CONTRIBUTING.md","mol/CODE_OF_CONDUCT.md","mol/charset/ucf/readme.md","mol/charset/buffer/buffer.ts","mol/charset/ucf/encode/encode.ts","mol/charset/ucf/decode/decode.ts","mol/charset/ucf/lib/lib.meta.tree"],"mods":{},"deps_in":{"mol/charset/ucf":{"mol/charset/ucf/lib":-999,"mol/charset/ucf/encode":-999,"mol/charset/ucf/decode":-999},"mol/charset":{"mol/charset/ucf":-999,"mol/charset/buffer":-999},"mol":{"mol/charset":-999},"":{"mol":-999},"mol/charset/ucf/encode":{"mol/charset/ucf/lib":-999},"mol/charset/buffer":{"mol/charset/ucf/encode":-2},"mol/charset/ucf/decode":{"mol/charset/ucf/lib":-999}},"deps_out":{"mol/charset/ucf/lib":{"mol/charset/ucf":-999,"mol/charset/ucf/encode":-999,"mol/charset/ucf/decode":-999},"mol/charset/ucf":{"mol/charset":-999},"mol/charset":{"mol":-999},"mol":{"":-999},"mol/charset/ucf/encode":{"mol/charset/ucf":-999,"mol/charset/buffer":-2},"mol/charset/buffer":{"mol/charset":-999},"mol/charset/ucf/decode":{"mol/charset/ucf":-999}},"sloc":{"ts":97,"LICENSE":113,"md":486,"js":9,"json":82,"tree":43,"CNAME":1},"deps":{"mol/charset/ucf/lib":{"..":-999,"/mol/charset/ucf/encode":-999,"/mol/charset/ucf/decode":-999},"mol/charset/ucf":{"..":-999},"mol/charset":{"..":-999},"mol":{"..":-999},"":{},"mol/charset/ucf/encode":{"..":-999,"/mol/charset/ucf/encode":-1,"/mol/charset/buffer":-2,"/mol/charset/ucf/encode/to":-1},"mol/charset/buffer":{"..":-999,"/mol/charset/buffer":-1},"mol/charset/ucf/decode":{"..":-999,"/mol/charset/ucf/decode":-1}}}
1
+ {"files":["mam.ts","LICENSE","README.md","mam.jam.js","tsfmt.json","package.json","tsconfig.json","lang.lang.tree","meta.lang.tree","sandbox.config.json","mol/CNAME","mol/LICENSE","mol/readme.md","mol/mol.meta.tree","mol/CONTRIBUTING.md","mol/CODE_OF_CONDUCT.md","mol/charset/ucf/readme.md","mol/charset/buffer/buffer.ts","mol/charset/ucf/encode/encode.ts","mol/charset/ucf/decode/decode.ts","mol/charset/ucf/lib/lib.meta.tree"],"mods":{},"deps_in":{"mol/charset/ucf":{"mol/charset/ucf/lib":-999,"mol/charset/ucf/encode":-999,"mol/charset/ucf/decode":-999},"mol/charset":{"mol/charset/ucf":-999,"mol/charset/buffer":-999},"mol":{"mol/charset":-999},"":{"mol":-999},"mol/charset/ucf/encode":{"mol/charset/ucf/lib":-999},"mol/charset/buffer":{"mol/charset/ucf/encode":-2},"mol/charset/ucf/decode":{"mol/charset/ucf/lib":-999}},"deps_out":{"mol/charset/ucf/lib":{"mol/charset/ucf":-999,"mol/charset/ucf/encode":-999,"mol/charset/ucf/decode":-999},"mol/charset/ucf":{"mol/charset":-999},"mol/charset":{"mol":-999},"mol":{"":-999},"mol/charset/ucf/encode":{"mol/charset/ucf":-999,"mol/charset/buffer":-2},"mol/charset/buffer":{"mol/charset":-999},"mol/charset/ucf/decode":{"mol/charset/ucf":-999}},"sloc":{"ts":92,"LICENSE":113,"md":489,"js":9,"json":82,"tree":43,"CNAME":1},"deps":{"mol/charset/ucf/lib":{"..":-999,"/mol/charset/ucf/encode":-999,"/mol/charset/ucf/decode":-999},"mol/charset/ucf":{"..":-999},"mol/charset":{"..":-999},"mol":{"..":-999},"":{},"mol/charset/ucf/encode":{"..":-999,"/mol/charset/ucf/encode":-1,"/mol/charset/buffer":-2,"/mol/charset/ucf/encode/to":-1},"mol/charset/buffer":{"..":-999,"/mol/charset/buffer":-1},"mol/charset/ucf/decode":{"..":-999,"/mol/charset/ucf/decode":-1}}}
package/node.js CHANGED
@@ -45,96 +45,91 @@ var $;
45
45
  "use strict";
46
46
  var $;
47
47
  (function ($) {
48
- let buf = new Uint8Array(2 ** 12);
49
48
  function $mol_charset_ucf_encode(str) {
50
49
  const buf = $mol_charset_buffer(str.length * 3);
51
50
  return buf.slice(0, $mol_charset_ucf_encode_to(str, buf));
52
51
  }
53
52
  $.$mol_charset_ucf_encode = $mol_charset_ucf_encode;
53
+ const fast_char = `0123456789.,:;()?!-'" \n`;
54
+ const fast_map = new Array(0x80).fill(0);
55
+ for (let i = 0; i < fast_char.length; ++i)
56
+ fast_map[fast_char[i].charCodeAt(0)] = i | 0x80;
54
57
  function $mol_charset_ucf_encode_to(str, buf, from = 0) {
55
58
  let pos = from;
56
- let mode = 0xF;
59
+ let mode = 0x9C;
57
60
  for (let i = 0; i < str.length; i++) {
58
61
  let code = str.charCodeAt(i);
59
62
  if (code >= 0xd800 && code < 0xe000)
60
63
  code = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
61
- if (code < 0x20) {
62
- if (code > 0x08 && code < 0x0E) {
63
- buf[pos++] = code;
64
- }
65
- else {
66
- if (mode !== 0x0E)
67
- buf[pos++] = mode = 0x0E;
68
- buf[pos++] = code | 0x80;
64
+ if (code < 0x80) {
65
+ if (mode !== 0x9C) {
66
+ const fast = fast_map[code];
67
+ if (fast)
68
+ code = fast;
69
+ else
70
+ buf[pos++] = mode = 0x9C;
69
71
  }
72
+ buf[pos++] = code;
73
+ }
74
+ else if (code < 0x32_00) {
75
+ const page = (code >> 7) + 0x9C;
76
+ if (mode !== page)
77
+ buf[pos++] = mode = page;
78
+ buf[pos++] = code & 0x7F;
79
+ }
80
+ else if (code < 0x04_20_00) {
81
+ code -= 0x2000;
82
+ const page = (code >> 15) + 0x98;
83
+ if (mode !== page)
84
+ buf[pos++] = mode = page;
85
+ buf[pos++] = code & 0x7F;
86
+ buf[pos++] = code >> 7;
70
87
  }
71
88
  else {
72
- if (code < 0xFF) {
73
- buf[pos++] = code;
74
- }
75
- else if (code < 0x09_00) {
76
- const page = (code >> 7) + 0x0E;
77
- if (mode !== page)
78
- buf[pos++] = mode = page;
79
- buf[pos++] = (code & 0x7F) | 0x80;
80
- }
81
- else if (code < 0x04_00_00) {
82
- const page = code >> 15;
83
- if (mode !== page)
84
- buf[pos++] = mode = page;
85
- buf[pos++] = (code & 0x7F) | 0x80;
86
- buf[pos++] = code >> 7;
87
- }
88
- else {
89
- if (mode !== 0x08)
90
- buf[pos++] = mode = 0x08;
91
- buf[pos++] = (code & 0x7F) | 0x80;
92
- buf[pos++] = code >> 7;
93
- buf[pos++] = code >> 15;
94
- }
89
+ if (mode !== 0x97)
90
+ buf[pos++] = mode = 0x97;
91
+ buf[pos++] = code & 0x7F;
92
+ buf[pos++] = code >> 7;
93
+ buf[pos++] = code >> 15;
95
94
  }
96
95
  }
97
96
  return pos - from;
98
97
  }
98
+ $.$mol_charset_ucf_encode_to = $mol_charset_ucf_encode_to;
99
99
  })($ || ($ = {}));
100
100
 
101
101
  ;
102
102
  "use strict";
103
103
  var $;
104
104
  (function ($) {
105
- function $mol_charset_ucf_decode(buffer, mode = 0x0F) {
105
+ const fast_char = `0123456789.,:;()?!-'" \n`;
106
+ function $mol_charset_ucf_decode(buffer, mode = 0x9C) {
106
107
  let text = '';
107
108
  let pos = 0;
108
109
  let page_offset = 0;
109
110
  while (pos < buffer.length) {
110
111
  let code = buffer[pos++];
111
- if (code < 0x20) {
112
- if (code >= 0x0E) {
113
- mode = code;
114
- page_offset = (mode - 0x0E) << 7;
115
- }
116
- else if (code > 0x08) {
117
- text += String.fromCodePoint(code);
118
- }
119
- else if (code === 0x08) {
120
- mode = 0x08;
121
- page_offset = 0;
122
- }
123
- else {
124
- mode = code;
125
- page_offset = mode << 15;
126
- }
112
+ if (code < 0x80) {
113
+ if (mode < 0x9C)
114
+ code |= buffer[pos++] << 7;
115
+ if (mode === 0x97)
116
+ code |= buffer[pos++] << 15;
117
+ text += String.fromCodePoint(page_offset + code);
127
118
  }
128
- else if (code < 0x80) {
129
- text += String.fromCodePoint(code);
119
+ else if (code < 0x97) {
120
+ text += fast_char[code - 0x80];
121
+ }
122
+ else if (code >= 0x9C) {
123
+ mode = code;
124
+ page_offset = (mode - 0x9C) << 7;
125
+ }
126
+ else if (code === 0x97) {
127
+ mode = code;
128
+ page_offset = 0;
130
129
  }
131
130
  else {
132
- code &= 0x7F;
133
- if (mode <= 0x08)
134
- code |= buffer[pos++] << 7;
135
- if (mode === 0x08)
136
- code |= buffer[pos++] << 15;
137
- text += String.fromCodePoint(page_offset | code);
131
+ mode = code;
132
+ page_offset = ((mode - 0x98) << 15) + 0x20_00;
138
133
  }
139
134
  }
140
135
  return text;
package/node.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["-","../../../../../mam.ts","../../../../../mol/charset/buffer/buffer.ts","../../../../../mol/charset/ucf/encode/encode.ts","../../../../../mol/charset/ucf/decode/decode.ts"],"names":[],"mappings":";;;AAAA;AACA;AACA;AACA;;ACHA,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;AAK3B,IAAU,CAAC,CAQV;AARD,WAAU,CAAC;AAQX,CAAC,EARS,CAAC,KAAD,CAAC,QAQV;AAED,MAAM,CAAC,OAAO,GAAG,CAAC,CAAA;;;ADflB;AACA;AACA;;;;;;;;;;;;;;;AEFA,IAAU,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A;oBACX,WAAW,GAAG,IAAI,IAAI,EAAE,CAAA;gBACzB,CAAC;YAEF,CAAC;iBAAM,IAAI,IAAI,GAAG,IAAI,EAAG,CAAC;gBAEzB,IAAI,IAAI,MAAM,CAAC,aAAa,CAAE,IAAI,CAAE,CAAA;YAErC,CAAC;iBAAM,CAAC;gBAEP,IAAI,IAAI,IAAI,CAAA;gBACZ,IAAI,IAAI,IAAI,IAAI;oBAAG,IAAI,IAAI,MAAM,CAAE,GAAG,EAAG,CAAE,IAAI,CAAC,CAAA;gBAChD,IAAI,IAAI,KAAK,IAAI;oBAAG,IAAI,IAAI,MAAM,CAAE,GAAG,EAAG,CAAE,IAAI,EAAE,CAAA;gBAClD,IAAI,IAAI,MAAM,CAAC,aAAa,CAAE,WAAW,GAAG,IAAI,CAAE,CAAA;YAEnD,CAAC;QAEF,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;IAzCe,yBAAuB,0BAyCtC,CAAA;AAEF,CAAC,EA9CS,CAAC,KAAD,CAAC,QA8CV;;","sourcesContent":[null,"Error.stackTraceLimit = 50;\n\ndeclare let _$_: { new(): {} } & typeof globalThis\ndeclare class $ extends _$_ {}\n\nnamespace $ {\n\texport type $ = typeof $$\n\texport declare class $$ extends $ {\n\t\tstatic $: $\n\t}\n\tnamespace $$ {\n\t\texport type $$ = $\n\t}\n}\n\nmodule.exports = $\n","namespace $ {\n\t\n\tlet buf = new Uint8Array( 2**12 ) // 4KB Mem Page\n\t\n\t/** Temporary buffer. Recursive usage isn't supported. */\n\texport function $mol_charset_buffer( size: number ) {\n\t\tif( buf.byteLength < size ) buf = new Uint8Array( size )\n\t\treturn buf\n\t}\n\t\n}\n","namespace $ {\n\t\n\tlet buf = new Uint8Array( 2**12 ) // 4KB Mem Page\n\n\t/** Encode text to Unicode Compact Format. */\n\texport function $mol_charset_ucf_encode( str: string ) {\n\t\tconst buf = $mol_charset_buffer( str.length * 3 )\n\t\treturn buf.slice( 0, $mol_charset_ucf_encode_to( str, buf ) )\n\t}\n\n\tfunction $mol_charset_ucf_encode_to( str: string, buf: Uint8Array< ArrayBuffer >, from = 0 ) {\n\n\t\tlet pos = from\n\t\tlet mode = 0xF\n\n\t\tfor( let i = 0; i < str.length; i++ ) {\n\t\t\t\n\t\t\tlet code = str.charCodeAt( i )\n\t\t\tif( code >= 0xd800 && code < 0xe000 ) code = ( ( code - 0xd800 ) << 10 ) + str.charCodeAt( ++ i ) + 0x2400\n\t\t\t\n\t\t\tif( code < 0x20 ) {\n\t\t\t\t\n\t\t\t\tif( code > 0x08 && code < 0x0E ) { // ASCII Printable\n\t\t\t\t\tbuf[ pos ++ ] = code\n\t\t\t\t} else { // ASCII Invisible\n\t\t\t\t\tif( mode !== 0x0E ) buf[ pos ++ ] = mode = 0x0E\n\t\t\t\t\tbuf[ pos ++ ] = code | 0x80\n\t\t\t\t}\n\t\t\t\t\n\t\t\t} else {\n\t\t\t\t\n\t\t\t\tif( code < 0xFF ) { // ASCII Latin\n\t\t\t\t\tbuf[ pos ++ ] = code\n\t\t\t\t} else if( code < 0x09_00 ) { // Tiny\n\t\t\t\t\tconst page = ( code >> 7 ) + 0x0E\n\t\t\t\t\tif( mode !== page ) buf[ pos ++ ] = mode = page\n\t\t\t\t\tbuf[ pos ++ ] = ( code & 0x7F ) | 0x80\n\t\t\t\t} else if( code < 0x04_00_00 ) { // Wide\n\t\t\t\t\tconst page = code >> 15\n\t\t\t\t\tif( mode !== page ) buf[ pos ++ ] = mode = page\n\t\t\t\t\tbuf[ pos ++ ] = ( code & 0x7F ) | 0x80\n\t\t\t\t\tbuf[ pos ++ ] = code >> 7\n\t\t\t\t} else { // Full\n\t\t\t\t\tif( mode !== 0x08 ) buf[ pos ++ ] = mode = 0x08\n\t\t\t\t\tbuf[ pos ++ ] = ( code & 0x7F ) | 0x80\n\t\t\t\t\tbuf[ pos ++ ] = code >> 7\n\t\t\t\t\tbuf[ pos ++ ] = code >> 15\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\n\t\t}\n\n\t\treturn pos - from\n\t}\n\t\n}\n","namespace $ {\n\n\t/** Decode text from Unicode Compact Format. */\n\texport function $mol_charset_ucf_decode( buffer: Uint8Array< ArrayBuffer >, mode = 0x0F ) {\n\t\t\n\t\tlet text = ''\n\t\tlet pos = 0\n\t\tlet page_offset = 0\n\t\t\n\t\twhile( pos < buffer.length ) {\n\t\t\t\n\t\t\tlet code = buffer[ pos ++ ]\n\t\t\t\n\t\t\tif( code < 0x20 ) {\n\t\t\t\t\n\t\t\t\tif( code >= 0x0E ) {\n\t\t\t\t\tmode = code\n\t\t\t\t\tpage_offset = ( mode - 0x0E ) << 7\n\t\t\t\t} else if( code > 0x08 ) {\n\t\t\t\t\ttext += String.fromCodePoint( code )\n\t\t\t\t} else if( code === 0x08 ) {\n\t\t\t\t\tmode = 0x08\n\t\t\t\t\tpage_offset = 0\n\t\t\t\t} else {\n\t\t\t\t\tmode = code\n\t\t\t\t\tpage_offset = mode << 15\n\t\t\t\t}\n\t\t\t\t\n\t\t\t} else if( code < 0x80 ) {\n\t\t\t\t\n\t\t\t\ttext += String.fromCodePoint( code )\n\t\t\t\t\n\t\t\t} else {\n\t\t\t\t\n\t\t\t\tcode &= 0x7F\n\t\t\t\tif( mode <= 0x08 ) code |= buffer[ pos ++ ] << 7\n\t\t\t\tif( mode === 0x08 ) code |= buffer[ pos ++ ] << 15\n\t\t\t\ttext += String.fromCodePoint( page_offset | code )\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn text\n\t}\n\n}\n"]}
1
+ {"version":3,"sources":["-","../../../../../mam.ts","../../../../../mol/charset/buffer/buffer.ts","../../../../../mol/charset/ucf/encode/encode.ts","../../../../../mol/charset/ucf/decode/decode.ts"],"names":[],"mappings":";;;AAAA;AACA;AACA;AACA;;ACHA,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;AAK3B,IAAU,CAAC,CAQV;AARD,WAAU,CAAC;AAQX,CAAC,EARS,CAAC,KAAD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AAA;gBAClD,IAAI,IAAI,MAAM,CAAC,aAAa,CAAE,WAAW,GAAG,IAAI,CAAE,CAAA;YAEnD,CAAC;iBAAM,IAAI,IAAI,GAAG,IAAI,EAAG,CAAC;gBAEzB,IAAI,IAAI,SAAS,CAAE,IAAI,GAAG,IAAI,CAAE,CAAA;YAEjC,CAAC;iBAAM,IAAI,IAAI,IAAI,IAAI,EAAG,CAAC;gBAE1B,IAAI,GAAG,IAAI,CAAA;gBACX,WAAW,GAAG,CAAE,IAAI,GAAG,IAAI,CAAE,IAAI,CAAC,CAAA;YAEnC,CAAC;iBAAM,IAAI,IAAI,KAAK,IAAI,EAAG,CAAC;gBAE3B,IAAI,GAAG,IAAI,CAAA;gBACX,WAAW,GAAG,CAAC,CAAA;YAEhB,CAAC;iBAAM,CAAC;gBAEP,IAAI,GAAG,IAAI,CAAA;gBACX,WAAW,GAAG,CAAE,CAAE,IAAI,GAAG,IAAI,CAAE,IAAI,EAAE,CAAE,GAAG,OAAO,CAAA;YAElD,CAAC;QAEF,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;IAxCe,yBAAuB,0BAwCtC,CAAA;AAEF,CAAC,EA/CS,CAAC,KAAD,CAAC,QA+CV;;","sourcesContent":[null,"Error.stackTraceLimit = 50;\n\ndeclare let _$_: { new(): {} } & typeof globalThis\ndeclare class $ extends _$_ {}\n\nnamespace $ {\n\texport type $ = typeof $$\n\texport declare class $$ extends $ {\n\t\tstatic $: $\n\t}\n\tnamespace $$ {\n\t\texport type $$ = $\n\t}\n}\n\nmodule.exports = $\n","namespace $ {\n\t\n\tlet buf = new Uint8Array( 2**12 ) // 4KB Mem Page\n\t\n\t/** Temporary buffer. Recursive usage isn't supported. */\n\texport function $mol_charset_buffer( size: number ) {\n\t\tif( buf.byteLength < size ) buf = new Uint8Array( size )\n\t\treturn buf\n\t}\n\t\n}\n","namespace $ {\n\t\n\t/** Encode text to Unicode Compact Format. */\n\texport function $mol_charset_ucf_encode( str: string ) {\n\t\tconst buf = $mol_charset_buffer( str.length * 3 )\n\t\treturn buf.slice( 0, $mol_charset_ucf_encode_to( str, buf ) )\n\t}\n\t\n\tconst fast_char = `0123456789.,:;()?!-'\" \\n`\n\tconst fast_map = new Array( 0x80 ).fill( 0 )\n\tfor( let i = 0; i < fast_char.length; ++i ) fast_map[ fast_char[ i ].charCodeAt(0) ] = i | 0x80\n\n\texport function $mol_charset_ucf_encode_to( str: string, buf: Uint8Array< ArrayBuffer >, from = 0 ) {\n\n\t\tlet pos = from\n\t\tlet mode = 0x9C\n\n\t\tfor( let i = 0; i < str.length; i++ ) {\n\t\t\t\n\t\t\tlet code = str.charCodeAt( i )\n\t\t\tif( code >= 0xd800 && code < 0xe000 ) code = ( ( code - 0xd800 ) << 10 ) + str.charCodeAt( ++ i ) + 0x2400\n\t\t\t\n\t\t\tif( code < 0x80 ) { // ASCII\n\t\t\t\t\n\t\t\t\tif( mode !== 0x9C ) {\n\t\t\t\t\tconst fast = fast_map[ code ]\n\t\t\t\t\tif( fast ) code = fast\n\t\t\t\t\telse buf[ pos ++ ] = mode = 0x9C\n\t\t\t\t}\n\t\t\t\tbuf[ pos ++ ] = code\n\t\t\t\t\n\t\t\t} else if( code < 0x32_00 ) { // Tiny\n\t\t\t\t\n\t\t\t\tconst page = ( code >> 7 ) + 0x9C\n\t\t\t\tif( mode !== page ) buf[ pos ++ ] = mode = page\n\t\t\t\tbuf[ pos ++ ] = code & 0x7F\n\t\t\t\t\n\t\t\t} else if( code < 0x04_20_00 ) { // Wide\n\t\t\t\t\n\t\t\t\tcode -= 0x2000\n\t\t\t\tconst page = ( code >> 15 ) + 0x98\n\t\t\t\tif( mode !== page ) buf[ pos ++ ] = mode = page\n\t\t\t\tbuf[ pos ++ ] = code & 0x7F\n\t\t\t\tbuf[ pos ++ ] = code >> 7\n\t\t\t\t\n\t\t\t} else { // Full\n\t\t\t\t\n\t\t\t\tif( mode !== 0x97 ) buf[ pos ++ ] = mode = 0x97\n\t\t\t\tbuf[ pos ++ ] = code & 0x7F\n\t\t\t\tbuf[ pos ++ ] = code >> 7\n\t\t\t\tbuf[ pos ++ ] = code >> 15\n\t\t\t\t\n\t\t\t}\n\n\t\t}\n\n\t\treturn pos - from\n\t}\n\t\n}\n","namespace $ {\n\n\tconst fast_char = `0123456789.,:;()?!-'\" \\n`\n\t\n\t/** Decode text from Unicode Compact Format. */\n\texport function $mol_charset_ucf_decode( buffer: Uint8Array< ArrayBuffer >, mode = 0x9C ) {\n\t\t\n\t\tlet text = ''\n\t\tlet pos = 0\n\t\tlet page_offset = 0\n\t\t\n\t\twhile( pos < buffer.length ) {\n\t\t\t\n\t\t\tlet code = buffer[ pos ++ ]\n\t\t\t\n\t\t\tif( code < 0x80 ) { // Char Code\n\t\t\t\t\n\t\t\t\tif( mode < 0x9C ) code |= buffer[ pos ++ ] << 7\n\t\t\t\tif( mode === 0x97 ) code |= buffer[ pos ++ ] << 15\n\t\t\t\ttext += String.fromCodePoint( page_offset + code )\n\t\t\t\t\n\t\t\t} else if( code < 0x97 ) { // ASCII\n\t\t\t\t\n\t\t\t\ttext += fast_char[ code - 0x80 ]\n\t\t\t\t\n\t\t\t} else if( code >= 0x9C ) { // Tiny Set\n\t\t\t\t\n\t\t\t\tmode = code\n\t\t\t\tpage_offset = ( mode - 0x9C ) << 7\n\t\t\t\t\n\t\t\t} else if( code === 0x97 ) { // Full Set\n\t\t\t\t\n\t\t\t\tmode = code\n\t\t\t\tpage_offset = 0\n\t\t\t\t\n\t\t\t} else { // Wide Set\n\t\t\t\t\n\t\t\t\tmode = code\n\t\t\t\tpage_offset = ( ( mode - 0x98 ) << 15 ) + 0x20_00\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn text\n\t}\n\n}\n"]}
package/node.mjs CHANGED
@@ -45,96 +45,91 @@ var $;
45
45
  "use strict";
46
46
  var $;
47
47
  (function ($) {
48
- let buf = new Uint8Array(2 ** 12);
49
48
  function $mol_charset_ucf_encode(str) {
50
49
  const buf = $mol_charset_buffer(str.length * 3);
51
50
  return buf.slice(0, $mol_charset_ucf_encode_to(str, buf));
52
51
  }
53
52
  $.$mol_charset_ucf_encode = $mol_charset_ucf_encode;
53
+ const fast_char = `0123456789.,:;()?!-'" \n`;
54
+ const fast_map = new Array(0x80).fill(0);
55
+ for (let i = 0; i < fast_char.length; ++i)
56
+ fast_map[fast_char[i].charCodeAt(0)] = i | 0x80;
54
57
  function $mol_charset_ucf_encode_to(str, buf, from = 0) {
55
58
  let pos = from;
56
- let mode = 0xF;
59
+ let mode = 0x9C;
57
60
  for (let i = 0; i < str.length; i++) {
58
61
  let code = str.charCodeAt(i);
59
62
  if (code >= 0xd800 && code < 0xe000)
60
63
  code = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
61
- if (code < 0x20) {
62
- if (code > 0x08 && code < 0x0E) {
63
- buf[pos++] = code;
64
- }
65
- else {
66
- if (mode !== 0x0E)
67
- buf[pos++] = mode = 0x0E;
68
- buf[pos++] = code | 0x80;
64
+ if (code < 0x80) {
65
+ if (mode !== 0x9C) {
66
+ const fast = fast_map[code];
67
+ if (fast)
68
+ code = fast;
69
+ else
70
+ buf[pos++] = mode = 0x9C;
69
71
  }
72
+ buf[pos++] = code;
73
+ }
74
+ else if (code < 0x32_00) {
75
+ const page = (code >> 7) + 0x9C;
76
+ if (mode !== page)
77
+ buf[pos++] = mode = page;
78
+ buf[pos++] = code & 0x7F;
79
+ }
80
+ else if (code < 0x04_20_00) {
81
+ code -= 0x2000;
82
+ const page = (code >> 15) + 0x98;
83
+ if (mode !== page)
84
+ buf[pos++] = mode = page;
85
+ buf[pos++] = code & 0x7F;
86
+ buf[pos++] = code >> 7;
70
87
  }
71
88
  else {
72
- if (code < 0xFF) {
73
- buf[pos++] = code;
74
- }
75
- else if (code < 0x09_00) {
76
- const page = (code >> 7) + 0x0E;
77
- if (mode !== page)
78
- buf[pos++] = mode = page;
79
- buf[pos++] = (code & 0x7F) | 0x80;
80
- }
81
- else if (code < 0x04_00_00) {
82
- const page = code >> 15;
83
- if (mode !== page)
84
- buf[pos++] = mode = page;
85
- buf[pos++] = (code & 0x7F) | 0x80;
86
- buf[pos++] = code >> 7;
87
- }
88
- else {
89
- if (mode !== 0x08)
90
- buf[pos++] = mode = 0x08;
91
- buf[pos++] = (code & 0x7F) | 0x80;
92
- buf[pos++] = code >> 7;
93
- buf[pos++] = code >> 15;
94
- }
89
+ if (mode !== 0x97)
90
+ buf[pos++] = mode = 0x97;
91
+ buf[pos++] = code & 0x7F;
92
+ buf[pos++] = code >> 7;
93
+ buf[pos++] = code >> 15;
95
94
  }
96
95
  }
97
96
  return pos - from;
98
97
  }
98
+ $.$mol_charset_ucf_encode_to = $mol_charset_ucf_encode_to;
99
99
  })($ || ($ = {}));
100
100
 
101
101
  ;
102
102
  "use strict";
103
103
  var $;
104
104
  (function ($) {
105
- function $mol_charset_ucf_decode(buffer, mode = 0x0F) {
105
+ const fast_char = `0123456789.,:;()?!-'" \n`;
106
+ function $mol_charset_ucf_decode(buffer, mode = 0x9C) {
106
107
  let text = '';
107
108
  let pos = 0;
108
109
  let page_offset = 0;
109
110
  while (pos < buffer.length) {
110
111
  let code = buffer[pos++];
111
- if (code < 0x20) {
112
- if (code >= 0x0E) {
113
- mode = code;
114
- page_offset = (mode - 0x0E) << 7;
115
- }
116
- else if (code > 0x08) {
117
- text += String.fromCodePoint(code);
118
- }
119
- else if (code === 0x08) {
120
- mode = 0x08;
121
- page_offset = 0;
122
- }
123
- else {
124
- mode = code;
125
- page_offset = mode << 15;
126
- }
112
+ if (code < 0x80) {
113
+ if (mode < 0x9C)
114
+ code |= buffer[pos++] << 7;
115
+ if (mode === 0x97)
116
+ code |= buffer[pos++] << 15;
117
+ text += String.fromCodePoint(page_offset + code);
127
118
  }
128
- else if (code < 0x80) {
129
- text += String.fromCodePoint(code);
119
+ else if (code < 0x97) {
120
+ text += fast_char[code - 0x80];
121
+ }
122
+ else if (code >= 0x9C) {
123
+ mode = code;
124
+ page_offset = (mode - 0x9C) << 7;
125
+ }
126
+ else if (code === 0x97) {
127
+ mode = code;
128
+ page_offset = 0;
130
129
  }
131
130
  else {
132
- code &= 0x7F;
133
- if (mode <= 0x08)
134
- code |= buffer[pos++] << 7;
135
- if (mode === 0x08)
136
- code |= buffer[pos++] << 15;
137
- text += String.fromCodePoint(page_offset | code);
131
+ mode = code;
132
+ page_offset = ((mode - 0x98) << 15) + 0x20_00;
138
133
  }
139
134
  }
140
135
  return text;
package/node.test.js CHANGED
@@ -36,96 +36,91 @@ var $;
36
36
  "use strict";
37
37
  var $;
38
38
  (function ($) {
39
- let buf = new Uint8Array(2 ** 12);
40
39
  function $mol_charset_ucf_encode(str) {
41
40
  const buf = $mol_charset_buffer(str.length * 3);
42
41
  return buf.slice(0, $mol_charset_ucf_encode_to(str, buf));
43
42
  }
44
43
  $.$mol_charset_ucf_encode = $mol_charset_ucf_encode;
44
+ const fast_char = `0123456789.,:;()?!-'" \n`;
45
+ const fast_map = new Array(0x80).fill(0);
46
+ for (let i = 0; i < fast_char.length; ++i)
47
+ fast_map[fast_char[i].charCodeAt(0)] = i | 0x80;
45
48
  function $mol_charset_ucf_encode_to(str, buf, from = 0) {
46
49
  let pos = from;
47
- let mode = 0xF;
50
+ let mode = 0x9C;
48
51
  for (let i = 0; i < str.length; i++) {
49
52
  let code = str.charCodeAt(i);
50
53
  if (code >= 0xd800 && code < 0xe000)
51
54
  code = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
52
- if (code < 0x20) {
53
- if (code > 0x08 && code < 0x0E) {
54
- buf[pos++] = code;
55
- }
56
- else {
57
- if (mode !== 0x0E)
58
- buf[pos++] = mode = 0x0E;
59
- buf[pos++] = code | 0x80;
55
+ if (code < 0x80) {
56
+ if (mode !== 0x9C) {
57
+ const fast = fast_map[code];
58
+ if (fast)
59
+ code = fast;
60
+ else
61
+ buf[pos++] = mode = 0x9C;
60
62
  }
63
+ buf[pos++] = code;
64
+ }
65
+ else if (code < 0x32_00) {
66
+ const page = (code >> 7) + 0x9C;
67
+ if (mode !== page)
68
+ buf[pos++] = mode = page;
69
+ buf[pos++] = code & 0x7F;
70
+ }
71
+ else if (code < 0x04_20_00) {
72
+ code -= 0x2000;
73
+ const page = (code >> 15) + 0x98;
74
+ if (mode !== page)
75
+ buf[pos++] = mode = page;
76
+ buf[pos++] = code & 0x7F;
77
+ buf[pos++] = code >> 7;
61
78
  }
62
79
  else {
63
- if (code < 0xFF) {
64
- buf[pos++] = code;
65
- }
66
- else if (code < 0x09_00) {
67
- const page = (code >> 7) + 0x0E;
68
- if (mode !== page)
69
- buf[pos++] = mode = page;
70
- buf[pos++] = (code & 0x7F) | 0x80;
71
- }
72
- else if (code < 0x04_00_00) {
73
- const page = code >> 15;
74
- if (mode !== page)
75
- buf[pos++] = mode = page;
76
- buf[pos++] = (code & 0x7F) | 0x80;
77
- buf[pos++] = code >> 7;
78
- }
79
- else {
80
- if (mode !== 0x08)
81
- buf[pos++] = mode = 0x08;
82
- buf[pos++] = (code & 0x7F) | 0x80;
83
- buf[pos++] = code >> 7;
84
- buf[pos++] = code >> 15;
85
- }
80
+ if (mode !== 0x97)
81
+ buf[pos++] = mode = 0x97;
82
+ buf[pos++] = code & 0x7F;
83
+ buf[pos++] = code >> 7;
84
+ buf[pos++] = code >> 15;
86
85
  }
87
86
  }
88
87
  return pos - from;
89
88
  }
89
+ $.$mol_charset_ucf_encode_to = $mol_charset_ucf_encode_to;
90
90
  })($ || ($ = {}));
91
91
 
92
92
  ;
93
93
  "use strict";
94
94
  var $;
95
95
  (function ($) {
96
- function $mol_charset_ucf_decode(buffer, mode = 0x0F) {
96
+ const fast_char = `0123456789.,:;()?!-'" \n`;
97
+ function $mol_charset_ucf_decode(buffer, mode = 0x9C) {
97
98
  let text = '';
98
99
  let pos = 0;
99
100
  let page_offset = 0;
100
101
  while (pos < buffer.length) {
101
102
  let code = buffer[pos++];
102
- if (code < 0x20) {
103
- if (code >= 0x0E) {
104
- mode = code;
105
- page_offset = (mode - 0x0E) << 7;
106
- }
107
- else if (code > 0x08) {
108
- text += String.fromCodePoint(code);
109
- }
110
- else if (code === 0x08) {
111
- mode = 0x08;
112
- page_offset = 0;
113
- }
114
- else {
115
- mode = code;
116
- page_offset = mode << 15;
117
- }
103
+ if (code < 0x80) {
104
+ if (mode < 0x9C)
105
+ code |= buffer[pos++] << 7;
106
+ if (mode === 0x97)
107
+ code |= buffer[pos++] << 15;
108
+ text += String.fromCodePoint(page_offset + code);
109
+ }
110
+ else if (code < 0x97) {
111
+ text += fast_char[code - 0x80];
112
+ }
113
+ else if (code >= 0x9C) {
114
+ mode = code;
115
+ page_offset = (mode - 0x9C) << 7;
118
116
  }
119
- else if (code < 0x80) {
120
- text += String.fromCodePoint(code);
117
+ else if (code === 0x97) {
118
+ mode = code;
119
+ page_offset = 0;
121
120
  }
122
121
  else {
123
- code &= 0x7F;
124
- if (mode <= 0x08)
125
- code |= buffer[pos++] << 7;
126
- if (mode === 0x08)
127
- code |= buffer[pos++] << 15;
128
- text += String.fromCodePoint(page_offset | code);
122
+ mode = code;
123
+ page_offset = ((mode - 0x98) << 15) + 0x20_00;
129
124
  }
130
125
  }
131
126
  return text;
@@ -4140,11 +4135,12 @@ var $;
4140
4135
  (function ($$) {
4141
4136
  $mol_test({
4142
4137
  "Complex UCF encoding"($) {
4143
- $mol_assert_equal($mol_charset_ucf_encode('hi мир, 你好 世界 🏴‍☠\t\n'), new Uint8Array([
4138
+ $mol_assert_equal($mol_charset_ucf_encode('hi мир, 美しい 世界 🏴‍☠\t\n'), new Uint8Array([
4144
4139
  0x68, 0x69, 0x20,
4145
- 0x16, 0xBC, 0xB8, 0xC0, 0x2C, 0x20,
4146
- 0x00, 0xE0, 0x9E, 0xFD, 0xB2, 0x20, 0x96, 0x9C, 0xCC, 0xEA, 0x20,
4147
- 0x03, 0xF4, 0xE7, 0x00, 0x8D, 0x40, 0xA0, 0x4C, 0x09, 0x0A,
4140
+ 0xA4, 0x3C, 0x38, 0x40, 0x8B, 0x95,
4141
+ 0x98, 0x0E, 0xBF, 0xFC, 0x57, 0x44, 0x95,
4142
+ 0x98, 0x16, 0x5C, 0x4C, 0xAA, 0x95,
4143
+ 0x9B, 0x74, 0xA7, 0xDC, 0x0D, 0xE8, 0x20, 0x9C, 0x09, 0x0A,
4148
4144
  ]));
4149
4145
  },
4150
4146
  });
@@ -4159,11 +4155,12 @@ var $;
4159
4155
  (function ($$) {
4160
4156
  $mol_test({
4161
4157
  "Complex UCF eecoding"($) {
4162
- $mol_assert_equal('hi мир, 你好 世界 🏴‍☠\t\n', $mol_charset_ucf_decode(new Uint8Array([
4158
+ $mol_assert_equal('hi мир, 美しい 世界 🏴‍☠\t\n', $mol_charset_ucf_decode(new Uint8Array([
4163
4159
  0x68, 0x69, 0x20,
4164
- 0x16, 0xBC, 0xB8, 0xC0, 0x2C, 0x20,
4165
- 0x00, 0xE0, 0x9E, 0xFD, 0xB2, 0x20, 0x96, 0x9C, 0xCC, 0xEA, 0x20,
4166
- 0x03, 0xF4, 0xE7, 0x00, 0x8D, 0x40, 0xA0, 0x4C, 0x09, 0x0A,
4160
+ 0xA4, 0x3C, 0x38, 0x40, 0x8B, 0x95,
4161
+ 0x98, 0x0E, 0xBF, 0xFC, 0x57, 0x44, 0x95,
4162
+ 0x98, 0x16, 0x5C, 0x4C, 0xAA, 0x95,
4163
+ 0x9B, 0x74, 0xA7, 0xDC, 0x0D, 0xE8, 0x20, 0x9C, 0x09, 0x0A,
4167
4164
  ])));
4168
4165
  },
4169
4166
  });