Struct CodePoint
Represents a Unicode value ([ U+0000..U+10FFFF ], inclusive).
public readonly struct CodePoint : IComparable, IComparable<CodePoint>, IEquatable<CodePoint>
- Implements
- Inherited Members
Remarks
This type's constructors and conversion operators validate the input, so consumers can call the APIs assuming that the underlying CodePoint instance is well-formed.
Constructors
CodePoint(char)
Initializes a new instance of the CodePoint struct.
public CodePoint(char value)
Parameters
valuecharThe char representing the UTF-16 code unit
Exceptions
- ArgumentOutOfRangeException
If
valuerepresents a UTF-16 surrogate code point U+D800..U+DFFF, inclusive.
CodePoint(char, char)
Initializes a new instance of the CodePoint struct.
public CodePoint(char highSurrogate, char lowSurrogate)
Parameters
highSurrogatecharA char representing a UTF-16 high surrogate code unit.
lowSurrogatecharA char representing a UTF-16 low surrogate code unit.
Exceptions
- ArgumentOutOfRangeException
If
highSurrogatedoes not represent a UTF-16 high surrogate code unit orlowSurrogatedoes not represent a UTF-16 low surrogate code unit.
CodePoint(int)
Initializes a new instance of the CodePoint struct.
public CodePoint(int value)
Parameters
valueintThe value to create the codepoint.
Exceptions
- ArgumentOutOfRangeException
If
valuedoes not represent a value Unicode scalar value.
CodePoint(uint)
Initializes a new instance of the CodePoint struct.
public CodePoint(uint value)
Parameters
valueuintThe value to create the codepoint.
Exceptions
- ArgumentOutOfRangeException
If
valuedoes not represent a value Unicode scalar value.
Properties
IsAscii
Gets a value indicating whether this value is ASCII ([ U+0000..U+007F ]) and therefore representable by a single UTF-8 code unit.
public bool IsAscii { get; }
Property Value
IsBmp
Gets a value indicating whether this value is within the BMP ([ U+0000..U+FFFF ]) and therefore representable by a single UTF-16 code unit.
public bool IsBmp { get; }
Property Value
ObjectReplacementChar
Gets a CodePoint instance that represents the Unicode object replacement character U+FFFC.
public static CodePoint ObjectReplacementChar { get; }
Property Value
Plane
Gets the Unicode plane (0 to 16, inclusive) which contains this scalar.
public int Plane { get; }
Property Value
ReplacementChar
Gets a CodePoint instance that represents the Unicode replacement character U+FFFD.
public static CodePoint ReplacementChar { get; }
Property Value
Utf16SequenceLength
Gets the length in code units (char) of the UTF-16 sequence required to represent this scalar value.
public int Utf16SequenceLength { get; }
Property Value
Remarks
The return value will be 1 or 2.
Utf8SequenceLength
Gets the length in code units of the UTF-8 sequence required to represent this scalar value.
public int Utf8SequenceLength { get; }
Property Value
Remarks
The return value will be 1 through 4, inclusive.
Value
Gets the Unicode value as an integer.
public int Value { get; }
Property Value
Methods
CompareTo(CodePoint)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(CodePoint other)
Parameters
otherCodePointAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
Equals(CodePoint)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(CodePoint other)
Parameters
otherCodePointAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetArabicJoiningClass(in CodePoint)
Gets the ArabicJoiningClass for the given codepoint.
public static ArabicJoiningClass GetArabicJoiningClass(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
GetBidiClass(in CodePoint)
Gets the BidiClass for the given codepoint.
public static BidiClass GetBidiClass(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
GetCodePointCount(ReadOnlySpan<char>)
Returns the number of codepoints in a given string buffer.
public static int GetCodePointCount(ReadOnlySpan<char> source)
Parameters
sourceReadOnlySpan<char>The source buffer to parse.
Returns
GetEastAsianWidthClass(in CodePoint)
Gets the EastAsianWidthClass for the given codepoint.
public static EastAsianWidthClass GetEastAsianWidthClass(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
Remarks
This returns the Unicode East_Asian_Width property value from UAX #11. It does not resolve context-sensitive display-cell width; for example, Ambiguous may resolve as narrow or wide depending on language, script, source encoding, font, or explicit markup.
GetEmojiProperties(in CodePoint)
Gets the EmojiProperties for the given codepoint.
public static EmojiProperties GetEmojiProperties(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
GetGeneralCategory(in CodePoint)
Gets the UnicodeCategory for the given codepoint.
public static UnicodeCategory GetGeneralCategory(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
GetGraphemeClusterClass(in CodePoint)
Gets the GraphemeClusterClass for the given codepoint.
public static GraphemeClusterClass GetGraphemeClusterClass(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
GetIndicConjunctBreakClass(in CodePoint)
Gets the IndicConjunctBreakClass for the given codepoint.
public static IndicConjunctBreakClass GetIndicConjunctBreakClass(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
GetIndicPositionalCategory(in CodePoint)
Gets the IndicPositionalCategory for the given codepoint.
public static IndicPositionalCategory GetIndicPositionalCategory(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
GetIndicSyllabicCategory(in CodePoint)
Gets the IndicSyllabicCategory for the given codepoint.
public static IndicSyllabicCategory GetIndicSyllabicCategory(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
GetLineBreakClass(in CodePoint)
Gets the LineBreakClass for the given codepoint.
public static LineBreakClass GetLineBreakClass(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
GetScriptClass(in CodePoint)
Gets the ScriptClass for the given codepoint.
public static ScriptClass GetScriptClass(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
- ScriptClass
The ScriptClass.
GetVerticalOrientationType(in CodePoint)
Gets the VerticalOrientationType for the given codepoint.
public static VerticalOrientationType GetVerticalOrientationType(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
GetWordBreakClass(in CodePoint)
Gets the WordBreakClass for the given codepoint.
public static WordBreakClass GetWordBreakClass(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint.
Returns
IsControl(in CodePoint)
Gets a value indicating whether the given codepoint is a control character.
public static bool IsControl(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsDigit(in CodePoint)
Returns a value that indicates whether the specified codepoint is categorized as a decimal digit.
public static bool IsDigit(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsLetter(in CodePoint)
Returns a value that indicates whether the specified codepoint is categorized as a letter.
public static bool IsLetter(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsLetterOrDigit(in CodePoint)
Returns a value that indicates whether the specified codepoint is categorized as a letter or decimal digit.
public static bool IsLetterOrDigit(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsLower(in CodePoint)
Returns a value that indicates whether the specified codepoint is categorized as a lowercase letter.
public static bool IsLower(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsMark(in CodePoint)
Returns a value that indicates whether the specified codepoint is categorized as a mark.
public static bool IsMark(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsNewLine(in CodePoint)
Gets a value indicating whether the given codepoint is a new line indicator.
public static bool IsNewLine(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsNonBreakingSpace(in CodePoint)
Gets a value indicating whether the given codepoint is a non-breaking space.
public static bool IsNonBreakingSpace(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsNumber(in CodePoint)
Returns a value that indicates whether the specified codepoint is categorized as a number.
public static bool IsNumber(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsPunctuation(in CodePoint)
Returns a value that indicates whether the specified codepoint is categorized as punctuation.
public static bool IsPunctuation(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsSeparator(in CodePoint)
Returns a value that indicates whether the specified codepoint is categorized as a separator.
public static bool IsSeparator(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsSymbol(in CodePoint)
Returns a value that indicates whether the specified codepoint is categorized as a symbol.
public static bool IsSymbol(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsTabulation(in CodePoint)
Gets a value indicating whether the given codepoint is a tabulation indicator.
public static bool IsTabulation(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsUpper(in CodePoint)
Returns a value that indicates whether the specified codepoint is categorized as an uppercase letter.
public static bool IsUpper(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsValid(int)
Returns true if value is a valid Unicode code
point, i.e., is in [ U+0000..U+10FFFF ], inclusive.
public static bool IsValid(int value)
Parameters
valueintThe value to evaluate.
Returns
IsValid(uint)
Returns true if value is a valid Unicode code
point, i.e., is in [ U+0000..U+10FFFF ], inclusive.
public static bool IsValid(uint value)
Parameters
valueuintThe value to evaluate.
Returns
IsVariationSelector(in CodePoint)
Gets a value indicating whether the given codepoint is a variation selector. https://en.wikipedia.org/wiki/Variation_Selectors_%28Unicode_block%29
public static bool IsVariationSelector(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsWhiteSpace(in CodePoint)
Gets a value indicating whether the given codepoint is white space.
public static bool IsWhiteSpace(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsZeroWidthJoiner(in CodePoint)
Gets a value indicating whether the given codepoint is a zero-width-joiner.
public static bool IsZeroWidthJoiner(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
IsZeroWidthNonJoiner(in CodePoint)
Gets a value indicating whether the given codepoint is a zero-width-non-joiner.
public static bool IsZeroWidthNonJoiner(in CodePoint codePoint)
Parameters
codePointCodePointThe codepoint to evaluate.
Returns
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
TryGetBidiMirror(in CodePoint, out CodePoint)
Gets the codepoint representing the bidi mirror for this instance. http://www.unicode.org/reports/tr44/#Bidi_Mirrored
public static bool TryGetBidiMirror(in CodePoint codePoint, out CodePoint mirror)
Parameters
codePointCodePointThe code point to be mapped.
mirrorCodePointWhen this method returns, contains the codepoint representing the bidi mirror for this instance; otherwise, the default value for the type of the
codePointparameter. This parameter is passed uninitialized. .
Returns
TryGetVerticalMirror(in CodePoint, out CodePoint)
Gets the codepoint representing the vertical mirror for this instance. https://www.unicode.org/reports/tr50/#vertical_alternates
public static bool TryGetVerticalMirror(in CodePoint codePoint, out CodePoint mirror)
Parameters
codePointCodePointThe code point to be mapped.
mirrorCodePointWhen this method returns, contains the codepoint representing the vertical mirror for this instance; otherwise, the default value for the type of the
codePointparameter. This parameter is passed uninitialized. .
Returns
Operators
operator ==(CodePoint, CodePoint)
public static bool operator ==(CodePoint left, CodePoint right)
Parameters
Returns
explicit operator CodePoint(char)
public static explicit operator CodePoint(char ch)
Parameters
chchar
Returns
explicit operator CodePoint(int)
public static explicit operator CodePoint(int value)
Parameters
valueint
Returns
explicit operator CodePoint(uint)
public static explicit operator CodePoint(uint value)
Parameters
valueuint
Returns
operator >(CodePoint, CodePoint)
public static bool operator >(CodePoint left, CodePoint right)
Parameters
Returns
operator >=(CodePoint, CodePoint)
public static bool operator >=(CodePoint left, CodePoint right)
Parameters
Returns
operator !=(CodePoint, CodePoint)
public static bool operator !=(CodePoint left, CodePoint right)
Parameters
Returns
operator <(CodePoint, CodePoint)
public static bool operator <(CodePoint left, CodePoint right)
Parameters
Returns
operator <=(CodePoint, CodePoint)
public static bool operator <=(CodePoint left, CodePoint right)