-
Notifications
You must be signed in to change notification settings - Fork 119
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
Use convertToZeroTerminatedString on both wasm and js targets #972
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.jetbrains.skia.impl | ||
|
||
/** | ||
* Converts String to zero-terminated utf-8 byte array. | ||
*/ | ||
internal fun convertToZeroTerminatedString(string: String): ByteArray { | ||
// C++ needs char* with zero byte at the end. So we need to copy array with an extra zero byte. | ||
|
||
val utf8 = string.encodeToByteArray() // encodeToByteArray encodes to utf8 | ||
// TODO Remove array copy, use `skString(data, length)` instead of `skString(data)` | ||
return utf8.copyOf(utf8.size + 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it guaranteed that the 1 extra byte would be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's guaranteed by spec for ByteArray.copyOf from Kotlin stdlib |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name is confusing - I thought that
toInterop
is recursive. It converts toByteArray
, not stringAlso better to include "utf8" in some form to the name