Skip to content

Fix strByteLength with emojis  #105

Description

@Bnaya

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions