public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Add ActiveSupport::Multibyte::Chars#ord method so that it returns correct 
Unicode value instead of falling back on String#ord in CoreExtensions, which is 
not multibyte compatible

[#1483 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Jason Cheow (author)
Wed Nov 26 06:16:28 -0800 2008
jeremy (committer)
Mon Dec 08 16:02:57 -0800 2008
commit  4e60eebae05aeec65e4894e3901c9d61c9b32910
tree    45cc75a790161a76c55da6db97a69cea56f95c42
parent  9b22e56d89a55460a18d5f38adf9fee919f52266
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.3.0 [Edge]*
0
 
0
+* Multibyte: add multibyte-safe Chars#ord rather than falling back to String#ord.  #1483 [Jason Cheow]
0
+
0
 * I18n support for Array#to_sentence. Introduces support.array.words_connector, .two_words_connector, and .last_word_connector translation keys.  #1397 [Akira Matsuda]
0
 
0
 * Added ActiveSupport::OrderedHash#each_key and ActiveSupport::OrderedHash#each_value #1410 [Christoffer Sawicki]
...
344
345
346
 
 
 
 
 
 
 
 
347
348
349
...
344
345
346
347
348
349
350
351
352
353
354
355
356
357
0
@@ -344,6 +344,14 @@ module ActiveSupport #:nodoc:
0
       end
0
       alias_method :[], :slice
0
 
0
+      # Converts first character in the string to Unicode value
0
+      #
0
+      # Example:
0
+      #   'こんにちは'.mb_chars.ord #=> 12371
0
+      def ord
0
+        self.class.u_unpack(@wrapped_string)[0]
0
+      end
0
+
0
       # Convert characters in the string to uppercase.
0
       #
0
       # Example:
...
397
398
399
 
 
 
 
400
401
402
...
397
398
399
400
401
402
403
404
405
406
0
@@ -397,6 +397,10 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
0
     assert_raise(ArgumentError) { @chars.slice(1, 1, 1) }
0
   end
0
 
0
+  def test_ord_should_return_unicode_value_for_first_character
0
+    assert_equal 12371, @chars.ord
0
+  end
0
+
0
   def test_upcase_should_upcase_ascii_characters
0
     assert_equal '', ''.mb_chars.upcase
0
     assert_equal 'ABC', 'aBc'.mb_chars.upcase

Comments