Skip to content

Conversation

@richarddd
Copy link
Collaborator

"🌍🌎🌏".slice(1) currently produces a broken surrogate pair. When converting to a rust string, we get UTF8 error.
QJS handles this by just printing the invalid utf16 surrogate pair as a replacement char.

This PR introduces a new method to_string_lossy that will render a utf8 replacement char for broken surrogate pairs.

@Sytten
Copy link
Collaborator

Sytten commented Apr 3, 2025

@richarddd I would argue that we should probably start using the new UTF-16 API instead quickjs-ng/quickjs#992 and do all the conversion on the rust side.

@richarddd
Copy link
Collaborator Author

Would that work for existing strings tho? It would be better if we could expose if the string is wide or not and use String::from_utf8_lossy or String::from_utf16_lossy

@richarddd richarddd marked this pull request as draft October 21, 2025 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants