switch parse buffer to UTF32
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
import { assert } from 'chai';
|
||||
import { fillFallback, concat, utf16ToString } from './TypedArrayUtils';
|
||||
import { fillFallback, concat, utf32ToString } from './TypedArrayUtils';
|
||||
|
||||
type TypedArray = Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray
|
||||
| Int8Array | Int16Array | Int32Array
|
||||
@@ -100,6 +100,6 @@ describe('typed array convenience functions', () => {
|
||||
for (let i = 0; i < s.length; ++i) {
|
||||
data[i] = s.charCodeAt(i);
|
||||
}
|
||||
assert.equal(utf16ToString(data), s);
|
||||
assert.equal(utf32ToString(data), s);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { stringFromCodePoint } from '../core/input/TextDecoder';
|
||||
|
||||
/**
|
||||
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
@@ -51,11 +53,18 @@ export function concat<T extends TypedArray>(a: T, b: T): T {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert UTF16 char codes into JS string.
|
||||
* Convert UTF32 char codes into JS string.
|
||||
* Note the typed array is not limited to Uint16Array, make sure to align
|
||||
* the values to 0-65535 integer for other typed array types, otherwise
|
||||
* the conversion will fail.
|
||||
*/
|
||||
export function utf16ToString<T extends TypedArray>(data: T): string {
|
||||
return String.fromCharCode.apply(null, data);
|
||||
export function utf32ToString<T extends TypedArray>(data: T): string {
|
||||
if ((String as any).fromCodePoint) {
|
||||
return (String as any).fromCodePoint.apply(null, data);
|
||||
}
|
||||
let result = '';
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
result += stringFromCodePoint(data[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user