-
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
Conversation
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Is it guaranteed that the 1 extra byte would be \0
? Or maybe we better set its value explicitly?
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.
it's guaranteed by spec for ByteArray.copyOf from Kotlin stdlib
@@ -23,6 +23,12 @@ class ManagedStringTest { | |||
assertEquals("你好", s3) | |||
} | |||
|
|||
@Test | |||
fun emptyStringTest() { |
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.
What do you think about adding a few more simple tests with intiially empty strings:
s.insert(0, "")
, s.append("")
.
Also I'm wondering what is going to happen if we call insert with an index out of bounds. Also remove
with an index out of bounds.
/** | ||
* Converts String to zero-terminated utf-8 byte array. | ||
*/ | ||
internal fun convertToZeroTerminatedString(string: String): ByteArray { |
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 to ByteArray
, not string
Also better to include "utf8" in some form to the name
This is supposed to be fix for #967
The idea is pass strings as (utf8) byte arrays directly through the border
just like we do it on native