strByteLength retunes wrong size for string with emojis (too big)
|
/** |
|
* Incorrect length (too big) for emojis |
|
* @param str |
|
*/ |
|
export function strByteLength(str: string) { |
|
let s = str.length; |
|
for (let i = str.length - 1; i >= 0; i--) { |
|
const code = str.charCodeAt(i); |
|
if (code > 0x7f && code <= 0x7ff) s++; |
|
else if (code > 0x7ff && code <= 0xffff) s += 2; |
|
} |
|
|
|
return s; |
|
} |
The output length needs to be compatible with the output of:
|
export function stringEncodeInto(uint8: Uint8Array, from: number, str: string) { |
Example for failing test:
#85
strByteLength retunes wrong size for string with emojis (too big)
objectbuffer/src/internal/utils.ts
Lines 69 to 82 in ab8ba96
The output length needs to be compatible with the output of:
objectbuffer/src/internal/stringEncodeInto.ts
Line 4 in 4dc8259
Example for failing test:
#85