• 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: adding charactersets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: adding charactersets


  • Subject: Re: adding charactersets
  • From: Christian Brunschen <email@hidden>
  • Date: Sat, 1 Mar 2003 19:12:28 +0000

On Saturday, Mar 1, 2003, at 18:36 Europe/London, Koen van der Drift wrote:

Hi,

Is there a way to "add" character sets? For instance, I want to test if a
character is a letter of the alphabet or a space, tab, or newline. Or
should I just test against lowercaseLetterCharacterset,
uppercaseLetterCharacterset and whitespaceAndNewlineCharatcerSet:

if ([lowercaseSet characterIsMember:aChar] || [uppercaseSet
characterIsMember:aChar] || [whitespaceSet characterIsMember:aChar])
{
do someting...

You might want to investigate NSMutableCharacterSet, which allows you to create unions and intersections between other NSCharacterSets using the method

- (void)formIntersectionWithCharacterSet:(NSCharacterSet *)otherSet;

Something like the following code might work (this is entirely untested, just typed into mail)

NSCharacterSet *characterSetFromUnionOfSets(NSArray *sets) {
NSCharacterSet *combinedSet;
NSEnuemerator *e = [sets objectEnumerator];
NSCharacterSet *set = [e nextObject];
NSMutableCharacterSet *tmp = [set mutableCopy];
while ((set = [e nextObject]) != nil) {
[tmp formUnionWithCharacterSet:set];
}
combinedSet = [tmp copy];
[tmp release];
return combinedSet;
}


/* You could even add a Category on NSCharacterSet to give you this functionality */

@interface NSCharacterSet (CharacterSetUnion)
+ (NSCharacterSet *)characterSetFromUnionOfSets:(NSSrray *)sets;
- (NSCharacterSet *)characterSetFromUnionWithSet:(NSCharacterSet *)set;
@end

@implementation NSCharacterSet (CharacterSetUnion)
+ (NSCharacterSet *)characterSetFromUnionOfSets:(NSSrray *)sets {
return characterSetsFromUnionOfSets(sets);
}
- (NSCharacterSet *)characterSetFromUnionWithSet:(NSCharacterSet *)set {
return [self characterSetFromUnionOfSets:[NSArray arrayWithObjects:self, set, nil]];
}
@end

/* in your own code */

NSCharacterSet *combinedSet = [NSCharacterSet characterSetFromUnionOfSets:[NSArray arrayWithObjects:
lowercaseSet, uppercaseSet, whitespaceSet, nil]];

/* or */

NSCharacterSet *combinedSet = [[lowercaseSet characterSetFromUnionWithSet:uppercaseSet]
characterSetFromUnionWithSet:whitespaceSet];

if ([combinedSet characterIsMember:aChar]) {
/* do something ... */
}

should work :)

thanks,

Hope this helps,

- Koen.

// Christian
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >adding charactersets (From: Koen van der Drift <email@hidden>)

  • Prev by Date: discards qualifiers from pointer target type
  • Next by Date: Re: NSTextView and Line Numbering
  • Previous by thread: adding charactersets
  • Next by thread: Unusual drag and drop problem
  • Index(es):
    • Date
    • Thread