On 31 Oct 2012, at 22:15, Ken Thomases <k...@codeweavers.com> wrote:

> On Oct 31, 2012, at 9:41 AM, Gerriet M. Denkmann wrote:
> 
>> I print strings like:
>>      NSString *s = @"ร่วมรส";
>>      fprintf(stderr, "%s\n", [ s UTF8String]);
>> and usually it just works.
>> 
>> But sometimes it does not and I get garbage like:
>> ร่ว\340\270\241รส
>> 
>> Converting these numbers to hex one gets: 0xe0 0xb8 0xa1 which is the 
>> Utf8-code for THAI CHARACTER MO MA.
>> So why does it not print (as it should):
>> ร่วมรส ?
>> 

When I run this in Xcode for a few times, I get sometimes good output, but 
sometimes not.
Bad output looks like:
2012-11-01 01:56:29.971 Writing[76838:303] strlen 1027
หหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหหห\340\270\253

Did run 10 times, got the bad output 3 times.

Did run 20 times in Terminal - never got bad output.

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
        #define REPEAT 7
        
        //      exactly one of these should be defined
        #define EINSx           //      no silly output here
        #define ZWEIx
        #define DREIx
        #define VIER

        @autoreleasepool 
        {
            NSMutableString *mu = [ NSMutableString string ];
                
                #ifdef EINS
                        #define NBR  1023       //      
                #endif
                #ifdef ZWEI
                        #define NBR  511        //      511 → strlen 1023 for 2 
bytes
                #endif
                #ifdef DREI
                        #define NBR  342        //      342 → strlen 1027 for 3 
bytes
                #endif
                #ifdef VIER
                        #define NBR  256        //      256 → strlen 1025 for 4 
bytes
                #endif
                
                for ( NSUInteger i = 0; i < NBR; i++ )  
                {
                        #ifdef EINS
                        [ mu appendString: @"a" ];      //      1 byte 
                        #endif
                        #ifdef ZWEI
                        [ mu appendString: @"§" ];      //      2 bytes SECTION 
SIGN
                        #endif
                        #ifdef DREI
                        [ mu appendString: @"ห" ];      //      3 bytes
                        #endif
                        #ifdef VIER
                        [ mu appendString: @"🚴" ];      //      4 bytes 
BICYCLIST
                        #endif
                };
                
                [ mu appendString: @"\n" ];
                const char *a = [ mu UTF8String ];
                NSLog(@"strlen %lu", strlen(a));
                for( NSUInteger i = 0; i < REPEAT; i++ ) fprintf(stderr,"%2lu 
%s", i, a);
        }
        return 0;
}

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to