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 String#to_utf16 and String.from_utf16 #5541

Merged
merged 1 commit into from
Jan 5, 2018
Merged

Add String#to_utf16 and String.from_utf16 #5541

merged 1 commit into from
Jan 5, 2018

Conversation

asterite
Copy link
Member

@asterite asterite commented Jan 5, 2018

This will be useful to interface with Windows functions that expect/return UTF-16 values.

@asterite asterite changed the title Add UTF16 module Add String#to_utf16 and String.from_utf16 Jan 5, 2018
elsif ord >= 0x10000
# Needs surrogate pair
ord -= 0x10000
slice[i] = 0xd800_u16 + ((ord >> 10) & 0x3ff) # Keep top 10 bytes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

top 10 bits?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed (did amend)

@@ -0,0 +1,47 @@
require "spec"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utf16_spec.cr

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, thanks

RX14
RX14 previously approved these changes Jan 5, 2018
@RX14 RX14 added this to the Next milestone Jan 5, 2018
# unicode replacement char value `0xfffd`.
#
# ```
# UTF16.encode("hi 𐂥") # => Slice[104_u16, 105_u16, 32_u16, 55296_u16, 56485_u16]
Copy link
Contributor

@Sija Sija Jan 5, 2018

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

Copy link
Member Author

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

@RX14 RX14 merged commit 50b563c into crystal-lang:master Jan 5, 2018
@asterite asterite deleted the feature/utf16 branch January 5, 2018 19:47
@asterite asterite mentioned this pull request Jan 12, 2018
22 tasks
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

4 participants