-
Notifications
You must be signed in to change notification settings - Fork 28
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
Handle array access syntax on strings with emoji #34
base: master
Are you sure you want to change the base?
Conversation
jbender
commented
Apr 11, 2016
I'm nervous about overriding |
Few questions:
|
@@ -101,4 +101,33 @@ def last(limit = 1) | |||
from(-limit) | |||
end | |||
end | |||
|
|||
# Emojis pose a problem for array-like access of a string. If you try to | |||
# grab one register you'll get am error: "You can't cut a surrogate in two in |
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.
Typo: "you'll get am error"
@tkadauke can't speak to the performance of it except to say that I've been using it in production for a few months now with no complaints. Do you have any specific tests you'd like to perform on it? I'm a proponent of the "it should just work" principle, so I'd be opposed to making this its own method. In doing so you're forcing people to know if a string may contain an emoji at any point rather than just making sure they're always safe. It'd be perfectly reasonable for this to be handled by RubyMotion itself (indeed probably preferred), but I happen to have an inside track to fix it here so thought I'd propose. 😁 |
Sorry to not get back to you in a long time. It just occurred to me that as a compromise, we can make this opt-in. E.g. we can have a class method on class String
def self.enable_emoji_support
@@emoji_support = true
end
def [](*args)
return bracket_access_original(*args) unless @@emoji_support
# ...
end
end The reason for that is a behavior change in getting the n-th character from a string can lead to catastrophic results. Ruby was plagued with this ever since Unicode encodings became popular. |