Repository navigation
Add Uchar.{utf_8_decode_length_of_byte,max_utf_8_decode_length} - #13796
Merged
Merged
Conversation
nojb
approved these changes
Feb 13, 2025
nojb
left a comment
Contributor
There was a problem hiding this comment.
LGTM
"since" annotations need to be added.
A second approval is needed before merging.
dbuenzli
force-pushed
the
utf-8-decode-tools
branch
from
February 13, 2025 08:46
af58b78 to
d87cf0f
Compare
Octachron
reviewed
Feb 13, 2025
Octachron
reviewed
Feb 13, 2025
Octachron
approved these changes
Feb 13, 2025
Octachron
left a comment
Member
There was a problem hiding this comment.
I agree that this is the kind of bit counting which is better written down once and for all.
dbuenzli
force-pushed
the
utf-8-decode-tools
branch
from
February 13, 2025 10:43
d87cf0f to
9593e5a
Compare
Octachron
reviewed
Feb 13, 2025
| (** [utf_8_decode_length_of_byte byte] is the number of bytes, from 1 | ||
| to {!max_utf8_decode_length}, that a valid UTF-8 decode starting | ||
| with byte [byte] would consume or [0] if [byte] cannot start a | ||
| valid decode. |
Member
There was a problem hiding this comment.
Thanks this rewording address my fear that a reader might be surprised that
utf_8_decode_length_of_byte s.(0) (* ≠ 0 *) might be different from Uchar.decode_length (String.get_utf_8_uchar s 0).
Explaining the 0 exceptional case at the end is also nice.
Contributor
Author
There was a problem hiding this comment.
Yes that became my worry too.
nojb
reviewed
Feb 13, 2025
|
|
||
| val utf_8_decode_length_of_byte : char -> int | ||
| (** [utf_8_decode_length_of_byte byte] is the number of bytes, from 1 | ||
| to {!max_utf8_decode_length}, that a valid UTF-8 decode starting |
Contributor
Author
There was a problem hiding this comment.
Can someone push a fix directly perhaps ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As said in #13760 I'm moving and exposing some UTF-8 decoding functionality from
string.mltoUchar.In general
Uchar.utf_8_decode_length_of_byteis useful when you arrive in the lastUchar.max_utf_8_decode_lengthbytes of a fixed sized buffer and want to determine if decodes will stay in the current buffer or not.(There's a also a commit that moves the Pqueue changes entry in the working version, it was added to 5.3)