[macruby-changes] [815] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Feb 27 04:44:58 PST 2009


Revision: 815
          http://trac.macosforge.org/projects/ruby/changeset/815
Author:   eloy.de.enige at gmail.com
Date:     2009-02-27 04:44:55 -0800 (Fri, 27 Feb 2009)
Log Message:
-----------
Use NSString#length for String#length which correctly returns the length of a string with multibyte characters. Patch by Vincent Isambart.

Modified Paths:
--------------
    MacRuby/trunk/insns.def
    MacRuby/trunk/test-macruby/cases/string_test.rb

Modified: MacRuby/trunk/insns.def
===================================================================
--- MacRuby/trunk/insns.def	2009-02-25 22:24:26 UTC (rev 814)
+++ MacRuby/trunk/insns.def	2009-02-27 12:44:55 UTC (rev 815)
@@ -1980,10 +1980,7 @@
 {
     if (!SPECIAL_CONST_P(recv) &&
 	BASIC_OP_UNREDEFINED_P(BOP_LENGTH)) {
-	if (HEAP_CLASS_OF(recv) == rb_cCFString) {
-	    val = rb_str_length(recv);
-	}
-	else if (HEAP_CLASS_OF(recv) == rb_cCFArray) {
+	if (HEAP_CLASS_OF(recv) == rb_cCFArray) {
 	    val = LONG2NUM(RARRAY_LEN(recv));
 	}
 	else if (HEAP_CLASS_OF(recv) == rb_cCFHash) {

Modified: MacRuby/trunk/test-macruby/cases/string_test.rb
===================================================================
--- MacRuby/trunk/test-macruby/cases/string_test.rb	2009-02-25 22:24:26 UTC (rev 814)
+++ MacRuby/trunk/test-macruby/cases/string_test.rb	2009-02-27 12:44:55 UTC (rev 815)
@@ -22,7 +22,7 @@
 @end
 EOS
       File.open('/tmp/_test_string.m', 'w') { |io| io.write(s) }
-      system("gcc /tmp/_test_string.m -bundle -o #{bundle} -framework Foundation -fobjc-gc-only") or exit 1
+      system("gcc /tmp/_test_string.m -bundle -o #{bundle} -arch i386 -arch x86_64 -framework Foundation -fobjc-gc-only") or exit 1
     end
     require 'dl'; DL.dlopen(bundle)
   end
@@ -43,6 +43,12 @@
     end
   end
   
+  it "should return the correct length for multibyte characters" do
+    assert_equal(3, 'あいう'.length)
+    assert_equal(2, 'aあ'.length)
+    assert_equal(1, 'a'.length)
+  end
+  
   #
   # Tests for UTF-16 surrogate pairs
   # These tests should be fixed in the future.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090227/ea410218/attachment.html>


More information about the macruby-changes mailing list