-
-
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 String#to_utf16 and String.from_utf16 #5541
Conversation
src/string/utf16.cr
Outdated
elsif ord >= 0x10000 | ||
# Needs surrogate pair | ||
ord -= 0x10000 | ||
slice[i] = 0xd800_u16 + ((ord >> 10) & 0x3ff) # Keep top 10 bytes |
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.
top 10 bits
?
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.
Thanks, fixed (did amend)
spec/std/string/utf16.cr
Outdated
@@ -0,0 +1,47 @@ | |||
require "spec" |
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.
utf16_spec.cr
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.
fixed, thanks
src/string/utf16.cr
Outdated
# unicode replacement char value `0xfffd`. | ||
# | ||
# ``` | ||
# UTF16.encode("hi 𐂥") # => Slice[104_u16, 105_u16, 32_u16, 55296_u16, 56485_u16] |
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.
UTF16.encode("hi 𐂥")
=> "hi 𐂥".to_utf16
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.
thanks, I forgot to update the docs
This will be useful to interface with Windows functions that expect/return UTF-16 values.