Skip to content

feat: Add lossy conversion between QJS string and Rust string #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

richarddd
Copy link
Contributor

"🌍🌎🌏".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
Contributor

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
Contributor 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

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