Skip to content

Tracking Issue for extra UTF-16 methods #94919

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
1 of 3 tasks
clarfonthey opened this issue Mar 13, 2022 · 5 comments
Open
1 of 3 tasks

Tracking Issue for extra UTF-16 methods #94919

clarfonthey opened this issue Mar 13, 2022 · 5 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@clarfonthey
Copy link
Contributor

clarfonthey commented Mar 13, 2022

Feature gate: #![feature(utf16_extra)]

This is a tracking issue for extra UTF-16 methods, which currently just includes u16::is_utf16_surrogate.

Public API

impl u16 {
    pub const fn is_utf16_surrogate(self) -> bool;
}

Steps / History

Unresolved Questions

  • What other useful UTF-16 methods should be exposed?
@clarfonthey clarfonthey added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Mar 13, 2022
@bjoernager
Copy link
Contributor

Could we also add the is_utf16_surrogate method to u32? I feel that it would be natural given the existing relationship between char and u32.

@clarfonthey
Copy link
Contributor Author

What value do you see that method offering over just char::try_from?

@bjoernager
Copy link
Contributor

bjoernager commented Apr 4, 2025

There is the explicitness aspect to having a specifically-named function, but there is also the fact that <char as TryFrom<u32>>::try_from additionally trips on values greater than 0x10FFFF (and not just surrogates). It it also worth pointing out that TryFrom::try_from cannot be called from constant expressions.

@clarfonthey
Copy link
Contributor Author

That's fair.

I'm mostly just thinking from the perspective of when it would be useful to know if a u32 is a UTF-16 surrogate value and not just when it's an invalid character, since I can't think of any.

@bjoernager
Copy link
Contributor

It could be used for the sake of more verbose diagnostics in e.g. a conversion error, but I agree that the use cases may not be all that plentiful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants