General API #
As a general rule, for a given Unicode property called Unicode_Property,
for example:
If the property is boolean valued then the implementation is called
Unicode.isUnicodeProperty.Otherwise, the implementation is called
Unicode.getUnicodeProperty.If the value is not of standard type (
Bool,Char,Nat,Int, etc.) or a combination thereof (e.g.Bool × Option Nat) then the value type is defined inUnicodeBasic.Types.If the input type needs disambiguation (e.g.
CharvsString) the type name may be appended to the name as inUnicode.isUnicodePropertyCharor inUnicode.getUnicodePropertyString.If the output type is
Option _then the suffix?may be appended to indicate that this is a partial function. In this case, a companion function with the suffix!may be implemented. This function performs the same calculation as the original but assumes that the input is in the domain; it may panic if this is not the case.
General Categories #
Unicode general categories are encoded using the type GC. This type has
a boolean algebra structure with inclusion ⊆, meet/intersection &&&,
join/union ||| and complement ~~~. The relation ∈ is provided to
check whether a character belongs to a given category. For example,
c ∈ (GC.L &&& ~~~GC.Lt) ||| GC.Z checks whether c is either a
non-titlecase letter or a separator.
The namespace Unicode.GeneralCategory provides a predicate for each
general category, for example GeneralCategory.isLetter for GC.L and
GeneralCategory.isMathSymbol for GC.Sm.
Scripts #
Scripts are identified by their four-letter ISO 15924 codes using the type
Script, for example Script.ofAbbrev! "Latn". The function getScript
returns the script of a character and getScriptName? returns the long
name of a script, such as "Latin". The function getScriptSet returns the
ScriptSet of scripts a character is commonly used with; use ∈ to check
membership, as in Script.ofAbbrev! "Grek" ∈ getScriptSet c.
Name #
Get character name
When the Unicode property Name is empty, a unique code point label is
returned as recommended in Unicode Standard, section 4.8, for example
<control-0009> or <private-use-E000>. These labels start with '<'
(U+003C) and end with '>' (U+003E) so they are distinguishable from
actual name values.
Unicode property: Name
Instances For
Script #
Get character script
Returns Zzzz (Unknown) for unassigned, private use and noncharacter code
points.
Unicode property: Script
Instances For
Get script name
Returns the long name of the script, for example "Latin" for Latn.
Returns none if the script code is not assigned to a script.
Unicode property: Script
Instances For
Get the set of scripts a character is commonly used with
If Unicode lists no such set for the character, this contains only getScript char.
Note: despite its name, the Script_Extensions property does not extend the Script
property. A set contains either one implicit script (Zyyy or Zinh) or one or more
explicit scripts (UAX #24, Section 3.1).
So a character whose script is Zyyy (Common) or Zinh (Inherited) may get a set that
excludes its script: U+00B7 MIDDLE DOT has script Zyyy, but its set is Avst Cari Copt ….
Unicode property: Script_Extensions
Instances For
Bidirectional Properties #
Get character bidirectional class
Unicode property: Bidi_Class
Instances For
Check if bidirectional mirrored character
Unicode property: Bidi_Mirrored
Instances For
Check if bidirectional control character
Unicode property: Bidi_Control
Instances For
General Category #
Get character general category
Caveat: This function never returns a derived general category. Use
char ∈ cat to check whether a character belongs to a general category
cat (derived or not).
Unicode property: General_Category
Instances For
char ∈ cat holds when the general category of char is included in cat
Check if letter character (L)
This is a derived category (L = Lu | Ll | Lt | Lm | Lo).
Unicode property: General_Category=L
Instances For
Check if lowercase letter character (Ll)
Unicode property: General_Category=Ll
Instances For
Check if titlecase letter character (Lt)
Unicode property: General_Category=Lt
Instances For
Check if uppercase letter character (Lu)
Unicode property: General_Category=Lu
Instances For
Check if cased letter character (LC)
This is a derived category (LC = Lu | Ll | Lt).
Unicode property: General_Category=LC
Instances For
Check if modifier letter character (Lm)
Unicode property: General_Category=Lm
Instances For
Check if other letter character (Lo)
Unicode property: General_Category=Lo
Instances For
Check if mark character (M)
This is a derived category (M = Mn | Mc | Me).
Unicode property: General_Category=M
Instances For
Check if nonspacing combining mark character (Mn)
Unicode property: General_Category=Mn
Instances For
Check if spacing combining mark character (Mc)
Unicode property: General_Category=Mc
Instances For
Check if enclosing combining mark character (Me)
Unicode property: General_Category=Me
Instances For
Check if number character (N)
This is a derived category (N = Nd | Nl | No).
Unicode property: General_Category=N
Instances For
Check if decimal number character (Nd)
Unicode property: General_Category=Nd
Instances For
Check if letter number character (Nl)
Unicode property: General_Category=Nl
Instances For
Check if other number character (No)
Unicode property: General_Category=No
Instances For
Check if punctuation character (P)
This is a derived category (P = Pc | Pd | Ps | Pe | Pi | Pf | Po).
Unicode property: General_Category=P
Instances For
Check if connector punctuation character (Pc)
Unicode property: General_Category=Pc
Instances For
Check if dash punctuation character (Pd)
Unicode property: General_Category=Pd
Instances For
Check if grouping punctuation character (PG)
This is a derived category (PG = Ps | Pe). It is not defined by Unicode
but is provided for convenience.
Unicode property: General_Category=PG
Instances For
Check if open punctuation character (Ps)
Unicode property: General_Category=Ps
Instances For
Check if close punctuation character (Pe)
Unicode property: General_Category=Pe
Instances For
Check if quoting punctuation character (PQ)
This is a derived category (PQ = Pi | Pf). It is not defined by Unicode
but is provided for convenience.
Unicode property: General_Category=PQ
Instances For
Check if initial punctuation character (Pi)
Unicode property: General_Category=Pi
Instances For
Check if final punctuation character (Pf)
Unicode property: General_Category=Pf
Instances For
Check if other punctuation character (Po)
Unicode property: General_Category=Po
Instances For
Check if symbol character (S)
This is a derived category (S = Sm | Sc | Sk | So).
Unicode property: General_Category=S
Instances For
Check if math symbol character (Sm)
Unicode property: General_Category=Sm
Instances For
Check if currency symbol character (Sc)
Unicode property: General_Category=Sc
Instances For
Check if modifier symbol character (Sk)
Unicode property: General_Category=Sk
Instances For
Check if other symbol character (So)
Unicode property: General_Category=So
Instances For
Check if separator character (Z)
This is a derived category (Z = Zs | Zl | Zp).
Unicode property: General_Category=Z
Instances For
Check if space separator character (Zs)
Unicode property: General_Category=Zs
Instances For
Check if line separator character (Zl)
Unicode property: General_Category=Zl
Instances For
Check if paragraph separator character (Zp)
Unicode property: General_Category=Zp
Instances For
Check if other character (C)
This is a derived category (C = Cc | Cf | Cs | Co | Cn).
Unicode property: General_Category=C
Instances For
Check if control character (Cc)
Unicode property: General_Category=Cc
Instances For
Check if format character (Cf)
Unicode property: General_Category=Cf
Instances For
Check if surrogate character (Cs)
Does not actually occur since Lean does not regard surrogate code points as characters.
Unicode property: General_Category=Cs
Instances For
Check if private use character (Co)
Unicode property: General_Category=Co
Instances For
Check if unassigned character (Cn)
Unicode property: General_Category=Cn
Instances For
Case Type and Mapping #
Check if lowercase character
This includes some characters that are not letters, such as U+24D0 CIRCLED LATIN SMALL LETTER A.
Generated by General_Category=Ll | Other_Lowercase.
Unicode property: Lowercase
Instances For
Check if uppercase character
This includes some characters that are not letters, such as U+24B6 CIRCLED LATIN CAPITAL LETTER A.
Generated by General_Category=Lu | Other_Uppercase.
Unicode property: Uppercase
Instances For
Check if cased character
This includes some characters that are not letters, such as U+24B6 CIRCLED LATIN CAPITAL LETTER A.
Generated by General_Category=LC | Other_Lowercase | Other_Uppercase.
Unicode property: Cased
Instances For
Check if character is ignorable for casing purposes
Generated from general categories Lm, Mn, Me, Sk, Cf, and word
break property values MidLetter, MidNumLet, Single_Quote.
Unicode property: Case_Ignorable
Instances For
Map character to lowercase
Returns the character itself if it has no lowercase mapping. This function
does not handle the case where the full lowercase mapping would consist of
more than one character, for example U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE;
use getLower for the full lowercase mapping.
Unicode property: Simple_Lowercase_Mapping
Instances For
Full lowercase mapping of a character, in continuation-passing style
Calls k with the first character of the full lowercase mapping of char
and the list of its remaining characters. For example, for U+0130 LATIN
CAPITAL LETTER I WITH DOT ABOVE, k is called with 'i' and ['\u0307'].
Conditional mappings, such as for final sigma, are not applied.
Unicode property: Lowercase_Mapping
Instances For
Full lowercase mapping of a character
The result may consist of more than one character, for example "i\u0307"
for U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE. Conditional mappings, such
as for final sigma, are not applied.
Unicode property: Lowercase_Mapping
Instances For
Map character to uppercase
Returns the character itself if it has no uppercase mapping. This function
does not handle the case where the full uppercase mapping would consist of
more than one character, for example U+00DF LATIN SMALL LETTER SHARP S; use
getUpper for the full uppercase mapping.
Unicode property: Simple_Uppercase_Mapping
Instances For
Full uppercase mapping of a character, in continuation-passing style
Calls k with the first character of the full uppercase mapping of char
and the list of its remaining characters. For example, for U+00DF LATIN SMALL
LETTER SHARP S, k is called with 'S' and ['S']. Conditional mappings
are not applied.
Unicode property: Uppercase_Mapping
Instances For
Full uppercase mapping of a character
The result may consist of more than one character, for example "SS" for
U+00DF LATIN SMALL LETTER SHARP S. Conditional mappings are not applied.
Unicode property: Uppercase_Mapping
Instances For
Map character to titlecase
Returns the character itself if it has no titlecase mapping. This function
does not handle the case where the full titlecase mapping would consist of
more than one character, for example U+00DF LATIN SMALL LETTER SHARP S; use
getTitle for the full titlecase mapping.
Unicode property: Simple_Titlecase_Mapping
Instances For
Full titlecase mapping of a character, in continuation-passing style
Calls k with the first character of the full titlecase mapping of char
and the list of its remaining characters. For example, for U+00DF LATIN SMALL
LETTER SHARP S, k is called with 'S' and ['s']. Conditional mappings
are not applied.
Unicode property: Titlecase_Mapping
Instances For
Full titlecase mapping of a character
The result may consist of more than one character, for example "Ss" for
U+00DF LATIN SMALL LETTER SHARP S. Conditional mappings are not applied.
Unicode property: Titlecase_Mapping
Instances For
Simple case folding of a character
Returns the character itself if it has no case folding. This function does
not handle the case where case folding would consist of more than one
character; use getCaseFolding for full case folding.
Unicode property: Simple_Case_Folding
Instances For
Full case folding of a character, in continuation-passing style
Calls k with the first character of the full case folding of char and
the list of its remaining characters. For example, for U+00DF LATIN SMALL
LETTER SHARP S, k is called with 's' and ['s'].
Unicode property: Case_Folding
Instances For
Full case folding of a character
The result may consist of more than one character, for example "ss" for
U+00DF LATIN SMALL LETTER SHARP S.
Unicode property: Case_Folding
Instances For
Case-insensitive prefix match
If pat matches a prefix of s up to full case folding, returns that prefix
and the rest of s. Otherwise, returns none. For example, "straße"
matches "STRASSE", but "ß" does not match "S", since the full case
folding of "ß" is "ss".
This is default caseless matching, as defined in the Unicode Standard; it does not normalize either string.
Unicode property: Case_Folding
Instances For
Decomposition Type and Mapping #
Get canonical combining class of character
Characters with combining class 0 are called starters. These include all
characters that are not combining marks, as well as some combining marks.
Unicode property: Canonical_Combining_Class
Instances For
Get full canonical decomposition of character (NFD)
Returns the full canonical decomposition of the character, including for Hangul syllables. Returns the character itself if it has no canonical decomposition.
Unicode properties:
Decomposition_Mapping
Decomposition_Type=Canonical
Instances For
Get decomposition mapping of a character
Returns none if the character has no decomposition mapping. The tag
field is none for a canonical mapping and some _ for a compatibility
mapping. This is a single decomposition step, not the full decomposition
used in normalization to canonical decomposition (NFD) and compatibility
decomposition (NFKD).
Unicode properties:
Decomposition_Type
Decomposition_Mapping
Instances For
Numeric Type and Value #
Check if character represents a numerical value
This includes decimal digits and other digits.
Unicode property: Numeric_Type (any value other than None)
Instances For
Check if character represents a digit in base 10
This includes decimal digits as well as other digits such as U+00B2 SUPERSCRIPT TWO.
Unicode property: Numeric_Type=Decimal | Numeric_Type=Digit
Instances For
Check if character represents a decimal digit
For this property, a character must be part of a contiguous sequence representing the ten decimal digits in order from 0 to 9.
Unicode property: Numeric_Type=Decimal
Instances For
Get decimal digit range
If the character is part of a contiguous sequence representing the ten decimal digits in order from 0 to 9, this function returns the first and last characters from this range.
Unicode properties:
Numeric_Type=Decimal
Numeric_Value
Instances For
Check if character represents a hexadecimal digit
Unicode property: Hex_Digit
Instances For
Get value of a hexadecimal digit
Returns none if the character is not a hexadecimal digit in the sense of
isHexDigit. Both ASCII and fullwidth forms are accepted.
Unicode property: Hex_Digit
Instances For
Other Properties #
Check if noncharacter code point
Unicode property: Noncharacter_Code_Point
Instances For
Check if default ignorable character
Unicode property: Default_Ignorable_Code_Point
Instances For
Check if white space character
Unicode property: White_Space
Instances For
Check if mathematical symbol character
Generated by General_Category=Sm | Other_Math.
Unicode property: Math
Instances For
Check if alphabetic character
Generated by General_Category=L | General_Category=Nl | Other_Alphabetic.
Unicode property: Alphabetic
Instances For
Check if alphabetic character
Generated by General_Category=L | General_Category=Nl | Other_Alphabetic.
Unicode property: Alphabetic