• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: printing Utf8
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printing Utf8


  • Subject: Re: printing Utf8
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Thu, 01 Nov 2012 02:42:12 +0700

On 31 Oct 2012, at 22:15, Ken Thomases <email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: printing Utf8
      • From: Ken Thomases <email@hidden>
References: 
 >printing Utf8 (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: printing Utf8 (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: App rejection due to app-sandboxing invalid entitlement
  • Next by Date: Re: Drawing customized window
  • Previous by thread: Re: printing Utf8
  • Next by thread: Re: printing Utf8
  • Index(es):
    • Date
    • Thread