> On 7 Apr 2015, at 00:15, Quincey Morris <quinceymor...@rivergatesoftware.com> 
> wrote:
> 
> On Apr 6, 2015, at 09:19 , Gerriet M. Denkmann <gerr...@mdenkmann.de> 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 (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