Skip to content

Improve writeCodePointValue KDoc #314

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

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/common/src/Utf8.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ internal fun String.utf8Size(startIndex: Int = 0, endIndex: Int = length): Long
* Without such a conversion, data written to a [Sink] can not be converted back
* to a string from which a surrogate pair was retrieved.
*
* More specifically, all code points mapping to UTF-16 surrogates (`U+d800`..`U+dfff`)
* will be written as `?` characters (`U+0063`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this JVM-only behavior or common one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, it's a common one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it inconsistent with String.encodeToByteArray where the replacement is unspecified, but different.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encodeToByteArray call on a string with a low surrogate only results in a byte array containing ?: https://pl.kotl.in/uFX3YULin

*
* @param codePoint the codePoint to be written.
*
* @throws IllegalStateException when the sink is closed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to document that IllegalArgumentException can be thrown.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand Down