Return to the Alphabetic Index
Return to the Class Browser
Return to the Picture Browser
Copyright (c) 1994 by NeXT Computer, Inc. All Rights
Reserved.
NSCharacterSet
Inherits From: NSObject
Conforms To: NSCoding, NSCopying, NSMutableCopying
NSObject (NSObject)
Declared In: Foundation/NSCharacterSet.h
Class Description
The NSCharacterSet class declares the programmatic interface to objects that
construct immutable descriptions of character sets in the Unicode
character encoding. Using NSCharacterSet objects, you can determine if a given
Unicode character belongs to a specified set. See NSMutableCharacterSet for a
class that constructs descriptions of character sets that can be modified
dynamically. NSCharacterSet's primitive methods are characterIsMember:
and bitmapRepresentation. Subclasses of NSCharacterSet must implement
these two methods.
NSCharacterSet objects can be thought of as loosely analogous to the
is1/4 macros (such as isupper())available in the ctype
collection of most standard C libraries. NSCharacterSet objects, however, offer
much greater flexibility in that you can dynamically construct your own custom
character sets against which you can test characters.
The term bitmap in the descriptions below does
not refer to bitmap characters in the sense of
screen fonts for display. The bitmaps referred
to here are compact ordered bit set representations of Unicode character
positions or ranges of Unicode characters.
You create standard character setssuch as
a set of alphanumerics, or a set of decimal digitsby invoking the
NSCharacterSet class object with one of the methods described in
Creating a Standard Character Set. These methods
provide convenient means to create a standard set without needing to specify
the character positons explicitly.
You can also create your own custom character
sets by using one of the methods described under Creating a
Custom Character Set. To create a character set with multiple
disjoint ranges, see the add1/4 methods described in
NSMutableCharacterSet.
Creating a Standard Character Set
- + (NSCharacterSet *)alphanumericCharacterSet Returns a character set
containing the uppercase and lowercase alphabetic characters (a-z, A-Z, other
alphabetic characters such as [[Yacute]], , Û, , and so on)
and the decimal digit characters (0-9).
- + (NSCharacterSet *)controlCharacterSet Returns a character set
containing the control characters (characters with decimal Unicode values 0 to
31 and 127 to 159).
- + (NSCharacterSet *)decimalDigitCharacterSet Returns a character set
containing only decimal digit characters (0-9).
- + (NSCharacterSet *)decomposableCharacterSet Returns a character set
containing all individual Unicode characters that can also be represented as
composed character sequences.
- + (NSCharacterSet *)illegalCharacterSet Returns a character set
containing the illegal Unicode values.
- + (NSCharacterSet *)letterCharacterSet Returns a character set
containing the uppercase and lowercase alphabetic characters (a-z, A-Z, other
alphabetic characters such as [[Yacute]], , Û, , and so
on).
- + (NSCharacterSet *)lowercaseLetterCharacterSet
Returns a character set containing only lowercase alphabetic characters
(a-z, other alphabetic characters such as [[Yacute]], Û, and so on).
- + (NSCharacterSet *)nonBaseCharacterSet Returns a set containing all
characters which are not defined to be base characters for purposes of dynamic
character composition.
- + (NSCharacterSet *)uppercaseLetterCharacterSet
Returns a character set containing only uppercase alphabetic characters
(A-Z, other alphabetic characters such as , , and so on).
- + (NSCharacterSet *)whitespaceAndNewlineCharacterSet
Returns a character set containing only whitespace characters (space
and tab) and the newline character.
- + (NSCharacterSet *)whitespaceCharacterSet Returns a character set
containing only in-line whitespace characters (space and tab). This set doesn't
contain the newline or carriage return characters.
Creating a Custom Character Set
- + (NSCharacterSet *)characterSetWithBitmapRepresentation:(NSData
*)data
Returns a character set containing characters determined by the bitmap
representation data.
- + (NSCharacterSet *)characterSetWithCharactersInString:(NSString
*)aString
Returns a character set containing the characters in aString. If
aString is empty, an empty character set is returned. aString
must not be nil.
- + (NSCharacterSet *)characterSetWithRange:(NSRange)aRange
Returns a character set containing characters whose Unicode values are
given by aRange.
Getting a Binary Representation
- - (NSData *)bitmapRepresentation Returns an NSData object encoding the
receiving character set in binary format. This format is suitable for saving to
a file or otherwise transmitting or archiving.
Testing Set Membership
- - (BOOL)characterIsMember:(unichar)aCharacter Returns YES if
aCharacter is in the receiving character set, NO if it isn't.
Inverting a Character Set
- - (NSCharacterSet *)invertedSet Returns a character set containing only
characters that don't exist in the receiver.