[MacRuby-devel] [MacRuby] #116: "%s" inside of format statements in macruby doesn't work with multibyte characters

MacRuby ruby-noreply at macosforge.org
Sat Aug 30 14:33:18 PDT 2008


#116: "%s" inside of format statements in macruby doesn't work with multibyte
characters
-------------------------------------+--------------------------------------
 Reporter:  jordan.breeding at mac.com  |        Owner:  lsansonetti at apple.com
     Type:  defect                   |       Status:  new                  
 Priority:  blocker                  |    Milestone:  MacRuby 1.0          
Component:  MacRuby                  |   Resolution:                       
 Keywords:                           |  
-------------------------------------+--------------------------------------

Comment(by jordan.breeding at mac.com):

 as an experiment this morning I compiled the following:

 {{{
 #import <Cocoa/Cocoa.h>
 #import <stdio.h>

 int main(int argc, char *argv[])
 {
     NSString *testString;

     NSLog(@"TEST 1\n");
     testString = @"Jördan";
     NSLog(@"%s", [testString UTF8String]);
     NSLog(@"%@", testString);
     printf("%s\n", [testString UTF8String]);

     NSLog(@"TEST 2\n");
     testString = [NSString stringWithFormat: @"%s", [@"Jördan"
 UTF8String]];
     NSLog(@"%@", testString);

     NSLog(@"TEST 3\n");
     testString = [NSString stringWithFormat: @"%@", @"Jördan"];
     NSLog(@"%@", testString);

     return(0);
 }
 }}}

 with this:

 {{{
 gcc -fobjc-gc -o test test.m -framework Cocoa
 }}}

 here is the output I got:

 {{{
 2008-08-30 16:13:35.977 test[42236:10b] TEST 1
 2008-08-30 16:13:35.980 test[42236:10b] Jördan
 2008-08-30 16:13:35.981 test[42236:10b] Jördan
 Jördan
 2008-08-30 16:13:35.982 test[42236:10b] TEST 2
 2008-08-30 16:13:35.982 test[42236:10b] Jördan
 2008-08-30 16:13:35.983 test[42236:10b] TEST 3
 2008-08-30 16:13:35.983 test[42236:10b] Jördan
 }}}

 So I think that this is a problem only with NSString (not with say
 printf), and I don't know if it is fixable or not because when digging
 around here:

 http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265

 I saw this:

 {{{
 %s Null-terminated array of 8-bit unsigned characters. %s interprets its
 input in the system encoding rather than, for example, UTF-8.
 }}}

 So other than passing Ruby strings directly using "%@" I don't know if
 there is a way to specify a format containing %s and have it picked up in
 something other than ASCII/system encoding.

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/116#comment:2>
MacRuby <http://macruby.org/>



More information about the MacRuby-devel mailing list