File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -380,6 +380,8 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo<Value>& args) {
380380 }
381381}
382382
383+ static uint32_t * tWindows1252x2 = 0 ;
384+
383385void BindingData::DecodeSingleByte (const FunctionCallbackInfo<Value>& args) {
384386 Environment* env = Environment::GetCurrent (args);
385387
@@ -416,6 +418,25 @@ void BindingData::DecodeSingleByte(const FunctionCallbackInfo<Value>& args) {
416418 if (encoding == 28 ) {
417419 // x-user-defined
418420 for (size_t i = 0 ; i < length; i++) dst[i] = data[i] >= 0x80 ? data[i] + 0xf700 : data[i];
421+ } else if (encoding == 21 ) {
422+ const uint16_t * table = tSingleByteEncodings[encoding];
423+ if (!tWindows1252x2) {
424+ tWindows1252x2 = (uint32_t *) malloc (256 * 256 * 4 ); // 256 KiB
425+ for (uint16_t i = 0 ; i < 256 ; i++) {
426+ for (uint16_t j = 0 ; j < 256 ; j++) {
427+ tWindows1252x2[(i << 8 ) + j] = (((uint32_t ) table[i]) << 16 ) + table[j];
428+ }
429+ }
430+ }
431+
432+ // TODO: alignment checks
433+ size_t length2 = length / 2 ;
434+ size_t i = 0 ;
435+ const uint16_t * data2 = reinterpret_cast <const uint16_t *>(data);
436+ uint32_t * dst2 = reinterpret_cast <uint32_t *>(dst);
437+ for (; i < length2; i++) dst2[i] = tWindows1252x2[data2[i]];
438+ i *= 2 ;
439+ for (; i < length; i++) dst[i] = table[data[i]];
419440 } else {
420441 bool has_fatal = args[2 ]->IsTrue ();
421442
You can’t perform that action at this time.
0 commit comments