Handle array access syntax on strings with emoji#34
Handle array access syntax on strings with emoji#34jbender wants to merge 1 commit intorubymotion-community:masterfrom
Conversation
jbender
commented
Apr 11, 2016
|
I'm nervous about overriding |
|
Few questions:
|
| 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.
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
endThe 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. |