CharClass Class
Stores information about a character class.
public class CharClass : ICollection<CharInterval>, IEnumerable<CharInterval>, IEnumerable
- Inheritance:
- Object Object
Constructors
CharClass()
Initializes a new instance of the CharClass
class.
public CharClass()
CharClass(CharClass)
Initializes a new instance of the CharClass
class with another CharClass.
public CharClass(CharClass charClass)
Parameter | Type | Description |
---|---|---|
charClass | CharClass | The CharClass whose items should be added. |
CharClass(CharInterval[])
Initializes a new instance of the CharClass
class with an array of CharInterval objects.
public CharClass(CharInterval[] intervals)
Parameter | Type | Description |
---|---|---|
intervals | CharInterval[] | The array of CharInterval objects that should be added. |
CharClass(Char)
Initializes a new instance of the CharClass
class with a character.
public CharClass(char ch)
Parameter | Type | Description |
---|---|---|
ch | Char | A character to add to the character class. |
CharClass(Char, Boolean)
Initializes a new instance of the CharClass
class with a character and an optional complement.
public CharClass(char ch, bool isNegated)
Parameter | Type | Description |
---|---|---|
ch | Char | A character to add to the character class. |
isNegated | Boolean | Whether to negate the character class after adding the initial character. |
CharClass(Char, Char)
Initializes a new instance of the CharClass
class with an interval of characters.
public CharClass(char start, char end)
Parameter | Type | Description |
---|---|---|
start | Char | The start character in the interval. |
end | Char | The end character in the interval. |
CharClass(Char, Char, Boolean)
Initializes a new instance of the CharClass
class with an interval of characters and an optional complement.
public CharClass(char start, char end, bool isNegated)
Parameter | Type | Description |
---|---|---|
start | Char | The start character in the interval. |
end | Char | The end character in the interval. |
isNegated | Boolean | Whether to negate the character class after adding the initial character range. |
CharClass(String)
Initializes a new instance of the CharClass
class with a string of characters.
public CharClass(string characters)
Parameter | Type | Description |
---|---|---|
characters | String | The string of characters to add to the character class. |
Properties
All
Gets a CharClass that contains all Unicode characters.
public static CharClass All { get; }
Property Value
Remarks
This character class is the equivalent of [\u0000-\uFFFF]
.
Alpha
Gets a CharClass that contains all alphabetic characters.
public static CharClass Alpha { get; }
Property Value
Remarks
This character class is the equivalent of \p{L}
(all letters).
CharacterCount
Gets the number of characters contained in the CharClass intervals, excluding any Unicode general categories specified.
public int CharacterCount { get; }
Property Value
Count
Gets the number of elements contained in the CharClass instance.
public int Count { get; }
Property Value
Digit
Gets a CharClass that contains all Unicode decimal digits.
public static CharClass Digit { get; }
Property Value
Remarks
This character class is the equivalent of \d
and \p{Nd}
.
HasCategorySpecification
Gets whether there is at least one Unicode generate category specification in the character class.
public bool HasCategorySpecification { get; }
Property Value
- Boolean:
true
if there is at least one Unicode generate category specification in the character class; otherwise,false
.
Remarks
Use the GetCategorySpecification(UnicodeCategory) method to test whether a specific UnicodeCategory is specified, and whether it is positive or negative.
HexDigit
Gets a CharClass that contains all Unicode hexidecimal digits.
public static CharClass HexDigit { get; }
Property Value
Remarks
This character class is the equivalent of [0-9a-fA-F]
.
IsNegated
Gets whether the character class is negated.
public bool IsNegated { get; set; }
Property Value
- Boolean:
true
if the character class is negated; otherwise,false
.
Remarks
The negation is the opposite of the character class, specified by a ^
character after the open square brace.
When negated, the return value of Contains(Char) is toggled.
IsReadOnly
Gets whether the collection is read-only.
public bool IsReadOnly { get; }
Property Value
- Boolean:
true
if the colletion is read-only; otherwise,false
.
IsSingleCharacter
Gets whether the character class only contains an interval for a single character.
public bool IsSingleCharacter { get; }
Property Value
- Boolean:
true
if the character class only contains an interval for a single character; otherwise,false
.
Item[Int32]
Gets the interval at the specified index.
[C#] In C#, this property is the indexer for the CharClass
class.
public CharInterval this[int index] { get; }
Parameter | Type | Description |
---|---|---|
index | Int32 | The index of the interval to return. |
Property Value
- CharInterval:
The CharInterval at the specified index.
LineTerminator
Gets a CharClass that contains all Unicode line terminators.
public static CharClass LineTerminator { get; }
Property Value
Remarks
This character class is the equivalent of [\n\r\p{Zl}\p{Zp}]
.
LineTerminatorWhitespace
Gets a CharClass that contains all Unicode line terminators and whitespace characters.
public static CharClass LineTerminatorWhitespace { get; }
Property Value
Remarks
This character class is the equivalent of \s
or [\f\n\r\t\v\x85\p{Z}]
.
NonAlpha
Gets a CharClass that contains no alphabetic digits.
public static CharClass NonAlpha { get; }
Property Value
Remarks
This character class is the equivalent of \P{L}
(no letters).
NonDigit
Gets a CharClass that contains no Unicode decimal digits.
public static CharClass NonDigit { get; }
Property Value
Remarks
This character class is the equivalent of \D
.
None
Gets a CharClass that contains no characters.
public static CharClass None { get; }
Property Value
NonHexDigit
Gets a CharClass that contains no Unicode hexidecimal digits.
public static CharClass NonHexDigit { get; }
Property Value
NonLineTerminator
Gets a CharClass that contains no Unicode line terminators.
public static CharClass NonLineTerminator { get; }
Property Value
Remarks
This character class is the equivalent of [^\n\r\p{Zl}\p{Zp}]
.
NonLineTerminatorWhitespace
Gets a CharClass that contains no Unicode line terminators or whitespace characters.
public static CharClass NonLineTerminatorWhitespace { get; }
Property Value
Remarks
This character class is the equivalent of \S
or [^\f\n\r\t\v\x85\p{Z}]
.
NonWhitespace
Gets a CharClass that contains no Unicode whitespace characters.
public static CharClass NonWhitespace { get; }
Property Value
Remarks
This character class is the equivalent of [^\f\t\v\x85\p{Zs}]
.
NonWord
Gets a CharClass that contains no word characters.
public static CharClass NonWord { get; }
Property Value
Remarks
This character class is the equivalent of \W
and [^\p{L}\p{Nd}\p{Pc}]
(no letters, decimal digits, and connectors like underscore).
Whitespace
Gets a CharClass that contains all Unicode whitespace characters.
public static CharClass Whitespace { get; }
Property Value
Remarks
This character class is the equivalent of [\f\t\v\x85\p{Zs}]
.
Word
Gets a CharClass that contains all word characters.
public static CharClass Word { get; }
Property Value
Remarks
\w
and [\p{L}\p{Nd}\p{Pc}]
(all letters, decimal digits, and connectors like underscore).
Methods
Add(CharInterval)
Adds an interval of characters to the character class.
public void Add(CharInterval interval)
Parameter | Type | Description |
---|---|---|
interval | CharInterval | The interval of characters to add. |
Add(Char)
Adds a single character to the character class.
public void Add(char ch)
Parameter | Type | Description |
---|---|---|
ch | Char | The character to add. |
Add(Char, Char)
Adds an interval of characters to the character class.
public void Add(char start, char end)
Parameter | Type | Description |
---|---|---|
start | Char | The start character in the interval. |
end | Char | The end character in the interval. |
AddCategory(UnicodeCategory, Boolean)
Adds the specified Unicode general category to the character class.
public void AddCategory(UnicodeCategory category, bool negate)
Parameter | Type | Description |
---|---|---|
category | UnicodeCategory | A UnicodeCategory indicating the category. |
negate | Boolean | Whether to negate the category. |
AddCategory(String, Boolean)
Adds the specified Unicode general category to the character class.
public void AddCategory(string categoryName, bool negate)
Parameter | Type | Description |
---|---|---|
categoryName | String | The name of the category. For example, |
negate | Boolean | Whether to negate the category. |
AddRange(CharClass)
Adds the contents of a CharClass to the collection.
public void AddRange(CharClass charClass)
Parameter | Type | Description |
---|---|---|
charClass | CharClass | The CharClass whose values are to be added. |
AddRange(CharInterval[])
Adds the contents of a CharInterval array to the collection.
public void AddRange(CharInterval[] intervals)
Parameter | Type | Description |
---|---|---|
intervals | CharInterval[] | The CharInterval array whose values are to be added. |
Clear()
public void Clear()
Contains(CharClass)
Returns whether the specified character class is in the character class.
public bool Contains(CharClass charClass)
Parameter | Type | Description |
---|---|---|
charClass | CharClass | The CharClass to look for in the collection. |
Returns
- Boolean:
true
if the character class is in the collection; otherwise,false
.
Contains(CharInterval)
Returns whether the specified interval is in the character class.
public bool Contains(CharInterval interval)
Parameter | Type | Description |
---|---|---|
interval | CharInterval | The CharInterval to look for in the collection. |
Returns
- Boolean:
true
if the interval is in the collection; otherwise,false
.
Contains(Char)
Returns whether the specified character is in the character class.
public bool Contains(char ch)
Parameter | Type | Description |
---|---|---|
ch | Char | The character to look for in the collection. |
Returns
- Boolean:
true
if the character is in the collection; otherwise,false
.
Contains(Char, Char)
Returns whether the specified interval of characters is in the character class.
public bool Contains(char start, char end)
Parameter | Type | Description |
---|---|---|
start | Char | The start character in the interval. |
end | Char | The end character in the interval. |
Returns
- Boolean:
true
if the interval of characters is in the collection; otherwise,false
.
CopyTo(CharInterval[], Int32)
Copies the entire collection to a compatible one-dimensional Array
,
starting at the specified index of the target array.
public void CopyTo(CharInterval[] array, int arrayIndex)
Parameter | Type | Description |
---|---|---|
array | CharInterval[] | The one-dimensional CharInterval array that is the destination of the elements copied from the collection. The array must have zero-based indexing. |
arrayIndex | Int32 | The zero-based index in |
Equals(Object)
Determines whether the specified Object
is equal to the current Object
.
public override bool Equals(object obj)
Parameter | Type | Description |
---|---|---|
obj | Object | The |
Returns
- Boolean:
true
if the specifiedObject
is equal to the currentObject
; otherwise,false
.
GetCategorySpecification(UnicodeCategory)
Returns whether a certain Unicode general category is specified in this character class, and if so, whether it is positive or negative matching.
public bool? GetCategorySpecification(UnicodeCategory category)
Parameter | Type | Description |
---|---|---|
category | UnicodeCategory | A UnicodeCategory indicating the category. |
Returns
GetEnumerator()
Retrieves an IEnumerator
object for the entire collection.
public IEnumerator<CharInterval> GetEnumerator()
Returns
- IEnumerator<CharInterval>:
An
IEnumerator
object for the entire collection
Remarks
Enumerators are intended to be used only to read data in the collection. Enumerators cannot be used to modify the underlying collection.
The enumerator does not have exclusive access to the collection.
When an enumerator is instantiated, it takes a snapshot of the current state of the collection.
If changes are made to the collection, such as adding, modifying or deleting elements, the
snapshot gets out of sync and the enumerator throws an InvalidOperationException
.
Two enumerators instantiated from the same collection at the same time can have
different snapshots of the collection.
GetHashCode()
Returns a hash code for this object.
public override int GetHashCode()
Returns
- Int32:
An integer value that specifies a hash value for this object.
Remove(CharInterval)
Removes the specified character interval from the character class.
public bool Remove(CharInterval interval)
Parameter | Type | Description |
---|---|---|
interval | CharInterval | The character interval to remove. |
Returns
- Boolean:
true
if the character interval was removed; otherwise,false
.
Remove(Char)
Removes the specified character from the character class.
public bool Remove(char ch)
Parameter | Type | Description |
---|---|---|
ch | Char | The character to remove. |
Returns
- Boolean:
true
if the character was removed; otherwise,false
.
RemoveCategory(UnicodeCategory)
Removes the specified Unicode general category from the character class.
public void RemoveCategory(UnicodeCategory category)
Parameter | Type | Description |
---|---|---|
category | UnicodeCategory | A UnicodeCategory indicating the category. |
RemoveCategory(String)
Removes the specified Unicode general category from the character class.
public void RemoveCategory(string categoryName)
Parameter | Type | Description |
---|---|---|
categoryName | String | The name of the category. For example, |
ToString()
Converts the object to a String
.