Last active
December 29, 2015 13:19
-
-
Save jonelf/7676612 to your computer and use it in GitHub Desktop.
Testing the string operations mentioned in http://mortoray.com/2013/11/27/the-string-type-is-broken/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = "lëon" | |
puts "Precomposed #{s}" | |
puts "Reverse #{s.reverse!}" | |
puts "First three #{s[0..2]}" | |
puts "Length: #{s.length.to_s}" | |
puts | |
s = "noe\u0308l" | |
puts "Decomposed #{s}" | |
puts "Reverse #{s.reverse!}" | |
puts "First three #{s[0..2]}" | |
puts "Length: #{s.length.to_s}" | |
puts | |
cats = "😸😾" | |
puts cats | |
puts "Length #{cats.length}" | |
puts "Substring after the first character #{cats.slice(1)}" | |
puts "Reverse #{cats.reverse}" | |
puts | |
s = "baffle" | |
puts s | |
puts "Upcase #{s.upcase}" | |
puts | |
puts "precomposed == decomposed" | |
s1 = "\u00F6" | |
s2 = "\u006F\u0308" | |
puts "=> #{s1 == s2}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs: https://dl.dropboxusercontent.com/u/26840/strings_output.png
Ruby knows nothing about the decomposed form but it's good with cats. :)
http://en.wikipedia.org/wiki/Precomposed_character