-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add overload to String.from_utf16 with pointer #5583
Add overload to String.from_utf16 with pointer #5583
Conversation
b7e03e1
to
82ea8cc
Compare
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.
Looks good! Just minor comments for the docs.
src/string/utf16.cr
Outdated
# ``` | ||
# slice = Slice[104_u16, 105_u16, 32_u16, 0_u16, 55296_u16, 56485_u16] | ||
# String.from_utf16(slice) # => "hi \0000𐂥" | ||
# String.from_utf16(slice.to_unsafe) # => "hi" |
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.
I think the result is missing a space
src/string/utf16.cr
Outdated
@@ -53,7 +53,15 @@ class String | |||
# slice = Slice[104_u16, 105_u16, 32_u16, 55296_u16, 56485_u16] | |||
# String.from_utf16(slice) # => "hi 𐂥" | |||
# ``` | |||
def self.from_utf16(slice : Slice(UInt16)) : String | |||
# | |||
# If *slice* is a pointer, the string is interpreted as null-terminated. |
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 input pointer could be interpreted as a string, but maybe it's better to say that it ends when a value of zero is found?
82ea8cc
to
d7d75a8
Compare
merge? |
This allows handling null-terminated wchar strings.