[MacRuby] #116: "%s" inside of format statements in macruby doesn't work with multibyte characters
#116: "%s" inside of format statements in macruby doesn't work with multibyte characters -------------------------------------+-------------------------------------- Reporter: jordan.breeding@mac.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- this: {{{ printf("straight puts: ") puts(p["name"]) printf("straight printf: ") printf("%s\n", p["name"]) printf("string formatted puts: ") puts("%s" % [p["name"]]) printf("nsstring printf: ") printf("%@\n", p["name"]) printf("nsstring formatted puts: ") puts("%@" % [p["name"]]) printf("format using nsstring, then puts: ") puts(NSString.stringWithFormat("%@", p["name"])) }}} will produce this: {{{ straight puts: Surgeon’s Girl straight printf: Surgeon‚Äôs Girl string formatted puts: Surgeon‚Äôs Girl nsstring printf: Surgeon’s Girl nsstring formatted puts: Surgeon’s Girl format using nsstring, then puts: Surgeon’s Girl }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/116> MacRuby <http://macruby.org/>
#116: "%s" inside of format statements in macruby doesn't work with multibyte characters -------------------------------------+-------------------------------------- Reporter: jordan.breeding@mac.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Resolution: Keywords: | -------------------------------------+-------------------------------------- Changes (by lsansonetti@apple.com): * milestone: => MacRuby 1.0 Comment: Actually, it looks like it's not related to MacRuby. {{{ $ cat t.m #import <Foundation/Foundation.h> int main(void) { NSLog(@"test1: %s\n", [@"あいうえお" UTF8String]); NSLog(@"test2: %@\n", @"あいうえお"); return 0; } $ gcc t.m -o t -framework Foundation $ ./t 2008-08-30 01:26:59.491 t[25923:10b] *** _NSAutoreleaseNoPool(): Object 0x1050a0 of class NSCFData autoreleased with no pool in place - just leaking Stack: (0x961d1cdf 0x960de562 0x960f2c35 0x960f2811) 2008-08-30 01:26:59.493 t[25923:10b] test1: „ÅÇ„ÅÑ„ÅÜ„Åà„Åä 2008-08-30 01:26:59.494 t[25923:10b] test2: あいうえお $ }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/116#comment:1> MacRuby <http://macruby.org/>
#116: "%s" inside of format statements in macruby doesn't work with multibyte characters -------------------------------------+-------------------------------------- Reporter: jordan.breeding@mac.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Resolution: Keywords: | -------------------------------------+-------------------------------------- Comment(by jordan.breeding@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/f... 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/>
#116: "%s" inside of format statements in macruby doesn't work with multibyte characters -------------------------------------+-------------------------------------- Reporter: jordan.breeding@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.6 Component: MacRuby | Resolution: fixed Keywords: | -------------------------------------+-------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.6 Comment: This should be fixed as of trunk. {{{ $ ./miniruby -e "p 'foo %s bar' % 'あいえうお'" "foo あいえうお bar" }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/116#comment:4> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby