@@ -38,7 +38,7 @@ export function utf8Count(str: string): number {
3838 return byteLength ;
3939}
4040
41- export function utf8Encode ( str : string , output : DataView , outputOffset : number ) : void {
41+ export function utf8Encode ( str : string , output : Uint8Array , outputOffset : number ) : void {
4242 const strLength = str . length ;
4343 let offset = outputOffset ;
4444 let pos = 0 ;
@@ -47,11 +47,11 @@ export function utf8Encode(str: string, output: DataView, outputOffset: number):
4747
4848 if ( ( value & 0xffffff80 ) === 0 ) {
4949 // 1-byte
50- output . setUint8 ( offset ++ , value ) ;
50+ output [ offset ++ ] = value ;
5151 continue ;
5252 } else if ( ( value & 0xfffff800 ) === 0 ) {
5353 // 2-bytes
54- output . setUint8 ( offset ++ , ( ( value >> 6 ) & 0x1f ) | 0xc0 ) ;
54+ output [ offset ++ ] = ( ( value >> 6 ) & 0x1f ) | 0xc0 ;
5555 } else {
5656 // handle surrogate pair
5757 if ( value >= 0xd800 && value <= 0xdbff ) {
@@ -67,17 +67,17 @@ export function utf8Encode(str: string, output: DataView, outputOffset: number):
6767
6868 if ( ( value & 0xffff0000 ) === 0 ) {
6969 // 3-byte
70- output . setUint8 ( offset ++ , ( ( value >> 12 ) & 0x0f ) | 0xe0 ) ;
71- output . setUint8 ( offset ++ , ( ( value >> 6 ) & 0x3f ) | 0x80 ) ;
70+ output [ offset ++ ] = ( ( value >> 12 ) & 0x0f ) | 0xe0 ;
71+ output [ offset ++ ] = ( ( value >> 6 ) & 0x3f ) | 0x80 ;
7272 } else {
7373 // 4-byte
74- output . setUint8 ( offset ++ , ( ( value >> 18 ) & 0x07 ) | 0xf0 ) ;
75- output . setUint8 ( offset ++ , ( ( value >> 12 ) & 0x3f ) | 0x80 ) ;
76- output . setUint8 ( offset ++ , ( ( value >> 6 ) & 0x3f ) | 0x80 ) ;
74+ output [ offset ++ ] = ( ( value >> 18 ) & 0x07 ) | 0xf0 ;
75+ output [ offset ++ ] = ( ( value >> 12 ) & 0x3f ) | 0x80 ;
76+ output [ offset ++ ] = ( ( value >> 6 ) & 0x3f ) | 0x80 ;
7777 }
7878 }
7979
80- output . setUint8 ( offset ++ , ( value & 0x3f ) | 0x80 ) ;
80+ output [ offset ++ ] = ( value & 0x3f ) | 0x80 ;
8181 }
8282}
8383
0 commit comments