Re: Where is my bicycle?
Re: Where is my bicycle?
- Subject: Re: Where is my bicycle?
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Tue, 07 Apr 2015 16:21:08 +0700
> On 7 Apr 2015, at 00:15, Quincey Morris <email@hidden> wrote:
>
> On Apr 6, 2015, at 09:19 , Gerriet M. Denkmann <email@hidden> wrote:
>
> A suggestion, though:
>
> Try building your character set using ‘characterSetWithRange:’ and/or the NSMutableCharacterSet methods that add ranges, instead of using NSStrings. Maybe NSCharacterSet really is UTF-32-based, but not — for code compatibility reasons — when using NSStrings explicitly.
This turned out to be an excellent idea - it allowed me to create a replacement for characterSetWithCharactersInString: which actually works:
// bug work-around
+ (NSCharacterSet *)gmdCharacterSetWithCharactersInString: (NSString *)string
{
if ( string.length == 0 ) // return nil
{
NSLog(@"%s string \"%@\" is empty or nil → no CharacterSet.",__FUNCTION__, string);
return nil;
};
NSData *dat = [ string dataUsingEncoding: NSUTF32StringEncoding ];
const UTF32Char *bytes = dat.bytes;
NSUInteger length = dat.length / sizeof(UTF32Char);
NSMutableCharacterSet *mus = [ [ NSMutableCharacterSet alloc ] init ];
for( NSUInteger i = 1; i < length; i++ ) // ignore initial kUnicodeByteOrderMark
{
UTF32Char codePoint = bytes[i];
[ mus addCharactersInRange: NSMakeRange( codePoint, 1 ) ];
};
return mus;
}
Thanks very much for your suggestion!
Kind regards,
Gerriet.
_______________________________________________
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