Skip to content
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

Merged

Conversation

straight-shoota
Copy link
Member

This allows handling null-terminated wchar strings.

Copy link
Member

@asterite asterite left a 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.

# ```
# 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"
Copy link
Member

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

@@ -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.
Copy link
Member

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?

@straight-shoota
Copy link
Member Author

merge?

@asterite asterite merged commit 295ddc3 into crystal-lang:master Jan 16, 2018
@asterite asterite added this to the Next milestone Jan 16, 2018
@straight-shoota straight-shoota deleted the jm/string-from-utf16-pointer branch January 16, 2018 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants