Structure

CharacterSet

A set of Unicode character values for use in search operations.

Overview

A CharacterSet represents a set of Unicode-compliant characters. Foundation types use CharacterSet to group characters together for searching operations, so that they can find any of a particular set of characters during a search.

This type provides “copy-on-write” behavior, and is also bridged to the Objective-C NSCharacterSet class.

Topics

Getting Standard Character Sets

static var alphanumerics: CharacterSet

Returns a character set containing the characters in Unicode General Categories L*, M*, and N*.

static var capitalizedLetters: CharacterSet

Returns a character set containing the characters in Unicode General Category Lt.

static var controlCharacters: CharacterSet

Returns a character set containing the characters in Unicode General Category Cc and Cf.

static var decimalDigits: CharacterSet

Returns a character set containing the characters in the category of Decimal Numbers.

static var decomposables: CharacterSet

Returns a character set containing individual Unicode characters that can also be represented as composed character sequences (such as for letters with accents), by the definition of “standard decomposition” in version 3.2 of the Unicode character encoding standard.

static var illegalCharacters: CharacterSet

Returns a character set containing values in the category of Non-Characters or that have not yet been defined in version 3.2 of the Unicode standard.

static var letters: CharacterSet

Returns a character set containing the characters in Unicode General Category L* & M*.

static var lowercaseLetters: CharacterSet

Returns a character set containing the characters in Unicode General Category Ll.

static var newlines: CharacterSet

Returns a character set containing the newline characters (U+000A ~ U+000D, U+0085, U+2028, and U+2029).

static var nonBaseCharacters: CharacterSet

Returns a character set containing the characters in Unicode General Category M*.

static var punctuationCharacters: CharacterSet

Returns a character set containing the characters in Unicode General Category P*.

static var symbols: CharacterSet

Returns a character set containing the characters in Unicode General Category S*.

static var uppercaseLetters: CharacterSet

Returns a character set containing the characters in Unicode General Category Lu and Lt.

static var whitespaces: CharacterSet

Returns a character set containing the characters in Unicode General Category Zs and CHARACTER TABULATION (U+0009).

static var whitespacesAndNewlines: CharacterSet

Returns a character set containing characters in Unicode General Category Z*, U+000A ~ U+000D, and U+0085.

Getting Character Sets for URL Encoding

static var urlFragmentAllowed: CharacterSet

Returns the character set for characters allowed in a fragment URL component.

static var urlHostAllowed: CharacterSet

Returns the character set for characters allowed in a host URL subcomponent.

static var urlPasswordAllowed: CharacterSet

Returns the character set for characters allowed in a password URL subcomponent.

static var urlPathAllowed: CharacterSet

Returns the character set for characters allowed in a path URL component.

static var urlQueryAllowed: CharacterSet

Returns the character set for characters allowed in a query URL component.

static var urlUserAllowed: CharacterSet

Returns the character set for characters allowed in a user URL subcomponent.

Creating a Custom Character Set

init()

Initialize an empty instance.

init<S>(S)

Creates a new set from a finite sequence of items.

init(charactersIn: String)

Initialize with the characters in the given string.

Creating and Managing Bitmap Representations

init(bitmapRepresentation: Data)

Initialize with a bitmap representation.

init?(contentsOfFile: String)

Initialize with the contents of a file.

var bitmapRepresentation: Data

Returns a representation of the CharacterSet in binary format.

Inverting a Character Set

func invert()

Invert the contents of the CharacterSet.

var inverted: CharacterSet

Returns an inverted copy of the receiver.

Combining Character Sets

func formIntersection(CharacterSet)

Sets the value to an intersection of the CharacterSet with another CharacterSet.

func formSymmetricDifference(CharacterSet)

Sets the value to an exclusive or of the CharacterSet with another CharacterSet.

func formUnion(CharacterSet)

Sets the value to a union of the CharacterSet with another CharacterSet.

func hasMember(inPlane: UInt8)

Returns true if the CharacterSet has a member in the specified plane.

func insert(charactersIn: String)

Insert the values from the specified string into the CharacterSet.

func intersection(CharacterSet)

Returns an intersection of the CharacterSet with another CharacterSet.

func invert()

Invert the contents of the CharacterSet.

func isDisjoint(with: CharacterSet)

Returns a Boolean value that indicates whether the set has no members in common with the given set.

func isStrictSubset(of: CharacterSet)

Returns a Boolean value that indicates whether this set is a strict subset of the given set.

func isStrictSuperset(of: CharacterSet)

Returns a Boolean value that indicates whether this set is a strict superset of the given set.

func isSubset(of: CharacterSet)

Returns a Boolean value that indicates whether the set is a subset of another set.

func isSuperset(of: CharacterSet)

Returns true if self is a superset of other.

func remove(charactersIn: String)

Remove the values from the specified string from the CharacterSet.

func subtracting(CharacterSet)

Returns a CharacterSet created by removing elements in other from self.

func symmetricDifference(CharacterSet)

Returns an exclusive or of the CharacterSet with another CharacterSet.

func union(CharacterSet)

Returns a union of the CharacterSet with another CharacterSet.

Adding Characters

func insert(charactersIn: String)

Insert the values from the specified string into the CharacterSet.

Removing Characters

func remove(charactersIn: String)

Remove the values from the specified string from the CharacterSet.

func subtracting(CharacterSet)

Returns a CharacterSet created by removing elements in other from self.

Testing Set Membership

func hasMember(inPlane: UInt8)

Returns true if the CharacterSet has a member in the specified plane.

func isDisjoint(with: CharacterSet)

Returns a Boolean value that indicates whether the set has no members in common with the given set.

func isStrictSubset(of: CharacterSet)

Returns a Boolean value that indicates whether this set is a strict subset of the given set.

func isStrictSuperset(of: CharacterSet)

Returns a Boolean value that indicates whether this set is a strict superset of the given set.

func isSubset(of: CharacterSet)

Returns a Boolean value that indicates whether the set is a subset of another set.

func isSuperset(of: CharacterSet)

Returns true if self is a superset of other.

var isEmpty: Bool

A Boolean value that indicates whether the set has no elements.

Comparing Character Sets

Describing a Character Set

var description: String

A textual description of the character set.

var debugDescription: String

A textual description of the character set suitable for debugging.

var hashValue: Int

The computed hash value for the date interval.

Using Reference Types

class NSCharacterSet

An object representing a fixed set of Unicode character values that bridges to a CharacterSet; use NSCharacterSet when you need reference semantics or other Foundation-specific behavior.

class NSMutableCharacterSet

An object representing a mutable set of Unicode character values that bridges to CharacterSet; use NSMutableCharacterSet when you need reference semantics or other Foundation-specific behavior.

typealias CharacterSet.ReferenceType

An alias for this value type's equivalent reference type.

See Also