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
Equations
- Unicode.getName char = Unicode.lookupName char.val
Instances For
Script #
Get character script
Returns Zzzz (Unknown) for unassigned, private use and noncharacter code
points.
Unicode property: Script
Equations
- Unicode.getScript char = Unicode.lookupScript char.val
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
Equations
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
Equations
- Unicode.getScriptSet char = Unicode.lookupScriptSet char.val
Instances For
Bidirectional Properties #
Get character bidirectional class
Unicode property: Bidi_Class
Equations
- Unicode.getBidiClass char = Unicode.lookupBidiClass char.val
Instances For
Check if bidirectional mirrored character
Unicode property: Bidi_Mirrored
Equations
- Unicode.isBidiMirrored char = Unicode.lookupBidiMirrored char.val
Instances For
Check if bidirectional control character
Unicode property: Bidi_Control
Equations
- One or more equations did not get rendered due to their size.
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
Equations
- Unicode.getGC char = if h : char.toNat < Unicode.getGC.table✝.size then Unicode.getGC.table✝[char.toNat] else Unicode.lookupGC char.val
Instances For
char ∈ cat holds when the general category of char is included in cat
Equations
- Unicode.instMembershipCharGC = { mem := fun (cat : Unicode.GC) (char : Char) => Unicode.getGC char ⊆ cat }
Equations
- Unicode.instDecidableMemCharGC char cat = (Unicode.getGC char).instDecidableSubset cat
Check if letter character (L)
This is a derived category (L = Lu | Ll | Lt | Lm | Lo).
Unicode property: General_Category=L
Equations
- Unicode.GeneralCategory.isLetter char = decide (char ∈ Unicode.GC.L)
Instances For
Check if lowercase letter character (Ll)
Unicode property: General_Category=Ll
Equations
- Unicode.GeneralCategory.isLowercaseLetter char = decide (char ∈ Unicode.GC.Ll)
Instances For
Check if titlecase letter character (Lt)
Unicode property: General_Category=Lt
Equations
- Unicode.GeneralCategory.isTitlecaseLetter char = decide (char ∈ Unicode.GC.Lt)
Instances For
Check if uppercase letter character (Lu)
Unicode property: General_Category=Lu
Equations
- Unicode.GeneralCategory.isUppercaseLetter char = decide (char ∈ Unicode.GC.Lu)
Instances For
Check if cased letter character (LC)
This is a derived category (LC = Lu | Ll | Lt).
Unicode property: General_Category=LC
Equations
- Unicode.GeneralCategory.isCasedLetter char = decide (char ∈ Unicode.GC.LC)
Instances For
Check if modifier letter character (Lm)
Unicode property: General_Category=Lm
Equations
- Unicode.GeneralCategory.isModifierLetter char = decide (char ∈ Unicode.GC.Lm)
Instances For
Check if other letter character (Lo)
Unicode property: General_Category=Lo
Equations
- Unicode.GeneralCategory.isOtherLetter char = decide (char ∈ Unicode.GC.Lo)
Instances For
Check if mark character (M)
This is a derived category (M = Mn | Mc | Me).
Unicode property: General_Category=M
Equations
- Unicode.GeneralCategory.isMark char = decide (char ∈ Unicode.GC.M)
Instances For
Check if nonspacing combining mark character (Mn)
Unicode property: General_Category=Mn
Equations
- Unicode.GeneralCategory.isNonspacingMark char = decide (char ∈ Unicode.GC.Mn)
Instances For
Check if spacing combining mark character (Mc)
Unicode property: General_Category=Mc
Equations
- Unicode.GeneralCategory.isSpacingMark char = decide (char ∈ Unicode.GC.Mc)
Instances For
Check if enclosing combining mark character (Me)
Unicode property: General_Category=Me
Equations
- Unicode.GeneralCategory.isEnclosingMark char = decide (char ∈ Unicode.GC.Me)
Instances For
Check if number character (N)
This is a derived category (N = Nd | Nl | No).
Unicode property: General_Category=N
Equations
- Unicode.GeneralCategory.isNumber char = decide (char ∈ Unicode.GC.N)
Instances For
Check if decimal number character (Nd)
Unicode property: General_Category=Nd
Equations
- Unicode.GeneralCategory.isDecimalNumber char = decide (char ∈ Unicode.GC.Nd)
Instances For
Check if letter number character (Nl)
Unicode property: General_Category=Nl
Equations
- Unicode.GeneralCategory.isLetterNumber char = decide (char ∈ Unicode.GC.Nl)
Instances For
Check if other number character (No)
Unicode property: General_Category=No
Equations
- Unicode.GeneralCategory.isOtherNumber char = decide (char ∈ Unicode.GC.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
Equations
- Unicode.GeneralCategory.isPunctuation char = decide (char ∈ Unicode.GC.P)
Instances For
Check if connector punctuation character (Pc)
Unicode property: General_Category=Pc
Equations
Instances For
Check if dash punctuation character (Pd)
Unicode property: General_Category=Pd
Equations
- Unicode.GeneralCategory.isDashPunctuation char = decide (char ∈ Unicode.GC.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
Equations
- Unicode.GeneralCategory.isGroupPunctuation char = decide (char ∈ Unicode.GC.PG)
Instances For
Check if open punctuation character (Ps)
Unicode property: General_Category=Ps
Equations
- Unicode.GeneralCategory.isOpenPunctuation char = decide (char ∈ Unicode.GC.Ps)
Instances For
Check if close punctuation character (Pe)
Unicode property: General_Category=Pe
Equations
- Unicode.GeneralCategory.isClosePunctuation char = decide (char ∈ Unicode.GC.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
Equations
- Unicode.GeneralCategory.isQuotePunctuation char = decide (char ∈ Unicode.GC.PQ)
Instances For
Check if initial punctuation character (Pi)
Unicode property: General_Category=Pi
Equations
Instances For
Check if final punctuation character (Pf)
Unicode property: General_Category=Pf
Equations
- Unicode.GeneralCategory.isFinalPunctuation char = decide (char ∈ Unicode.GC.Pf)
Instances For
Check if other punctuation character (Po)
Unicode property: General_Category=Po
Equations
- Unicode.GeneralCategory.isOtherPunctuation char = decide (char ∈ Unicode.GC.Po)
Instances For
Check if symbol character (S)
This is a derived category (S = Sm | Sc | Sk | So).
Unicode property: General_Category=S
Equations
- Unicode.GeneralCategory.isSymbol char = decide (char ∈ Unicode.GC.S)
Instances For
Check if math symbol character (Sm)
Unicode property: General_Category=Sm
Equations
- Unicode.GeneralCategory.isMathSymbol char = decide (char ∈ Unicode.GC.Sm)
Instances For
Check if currency symbol character (Sc)
Unicode property: General_Category=Sc
Equations
- Unicode.GeneralCategory.isCurrencySymbol char = decide (char ∈ Unicode.GC.Sc)
Instances For
Check if modifier symbol character (Sk)
Unicode property: General_Category=Sk
Equations
- Unicode.GeneralCategory.isModifierSymbol char = decide (char ∈ Unicode.GC.Sk)
Instances For
Check if other symbol character (So)
Unicode property: General_Category=So
Equations
- Unicode.GeneralCategory.isOtherSymbol char = decide (char ∈ Unicode.GC.So)
Instances For
Check if separator character (Z)
This is a derived category (Z = Zs | Zl | Zp).
Unicode property: General_Category=Z
Equations
- Unicode.GeneralCategory.isSeparator char = decide (char ∈ Unicode.GC.Z)
Instances For
Check if space separator character (Zs)
Unicode property: General_Category=Zs
Equations
- Unicode.GeneralCategory.isSpaceSeparator char = decide (char ∈ Unicode.GC.Zs)
Instances For
Check if line separator character (Zl)
Unicode property: General_Category=Zl
Equations
- Unicode.GeneralCategory.isLineSeparator char = decide (char ∈ Unicode.GC.Zl)
Instances For
Check if paragraph separator character (Zp)
Unicode property: General_Category=Zp
Equations
Instances For
Check if other character (C)
This is a derived category (C = Cc | Cf | Cs | Co | Cn).
Unicode property: General_Category=C
Equations
- Unicode.GeneralCategory.isOther char = decide (char ∈ Unicode.GC.C)
Instances For
Check if control character (Cc)
Unicode property: General_Category=Cc
Equations
- Unicode.GeneralCategory.isControl char = decide (char ∈ Unicode.GC.Cc)
Instances For
Check if format character (Cf)
Unicode property: General_Category=Cf
Equations
- Unicode.GeneralCategory.isFormat char = decide (char ∈ Unicode.GC.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
Equations
- Unicode.GeneralCategory.isSurrogate char = decide (char ∈ Unicode.GC.Cs)
Instances For
Check if private use character (Co)
Unicode property: General_Category=Co
Equations
- Unicode.GeneralCategory.isPrivateUse char = decide (char ∈ Unicode.GC.Co)
Instances For
Check if unassigned character (Cn)
Unicode property: General_Category=Cn
Equations
- Unicode.GeneralCategory.isUnassigned char = decide (char ∈ Unicode.GC.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
Equations
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
Equations
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
Equations
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
Equations
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
Equations
- One or more equations did not get rendered due to their size.
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
Equations
- Unicode.withLowercasing char k = match Unicode.unconsLowercasing✝ char with | (v, l) => k (Char.ofNat v.toNat) (List.map (fun (v : UInt32) => Char.ofNat v.toNat) l)
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
Equations
- Unicode.getLower char = Unicode.withLowercasing char fun (c : Char) (l : List Char) => List.foldl String.push c.toString l
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
Equations
- One or more equations did not get rendered due to their size.
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
Equations
- Unicode.withUppercasing char k = match Unicode.unconsUppercasing✝ char with | (v, u) => k (Char.ofNat v.toNat) (List.map (fun (v : UInt32) => Char.ofNat v.toNat) u)
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
Equations
- Unicode.getUpper char = Unicode.withUppercasing char fun (c : Char) (u : List Char) => List.foldl String.push c.toString u
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
Equations
- One or more equations did not get rendered due to their size.
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
Equations
- Unicode.withTitlecasing char k = match Unicode.unconsTitlecasing✝ char with | (v, t) => k (Char.ofNat v.toNat) (List.map (fun (v : UInt32) => Char.ofNat v.toNat) t)
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
Equations
- Unicode.getTitle char = Unicode.withTitlecasing char fun (c : Char) (t : List Char) => List.foldl String.push c.toString t
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
Equations
- One or more equations did not get rendered due to their size.
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
Equations
- Unicode.withCaseFolding char k = match Unicode.unconsCaseFolding✝ char with | (v, f) => k (Char.ofNat v.toNat) (List.map (fun (v : UInt32) => Char.ofNat v.toNat) f)
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
Equations
- Unicode.getCaseFolding char = Unicode.withCaseFolding char fun (c : Char) (f : List Char) => List.foldl String.push c.toString f
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
Equations
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
Equations
- Unicode.getCanonicalCombiningClass char = if char.val < 128 then 0 else Unicode.lookupCanonicalCombiningClass char.val
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
Equations
- One or more equations did not get rendered due to their size.
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
Equations
- Unicode.getDecompositionMapping? char = if char.val < 128 then none else Unicode.lookupDecompositionMapping? char.val
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)
Equations
- One or more equations did not get rendered due to their size.
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
Equations
- One or more equations did not get rendered due to their size.
Instances For
Get value of digit
Returns none if the character is not a digit in the sense of isDigit.
Unicode properties:
Numeric_Type=Decimal | Numeric_Type=Digit
Numeric_Value
Equations
- One or more equations did not get rendered due to their size.
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
Equations
- One or more equations did not get rendered due to their size.
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
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check if character represents a hexadecimal digit
Unicode property: Hex_Digit
Equations
- One or more equations did not get rendered due to their size.
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
Equations
- One or more equations did not get rendered due to their size.
Instances For
Other Properties #
Check if noncharacter code point
Unicode property: Noncharacter_Code_Point
Equations
Instances For
Check if default ignorable character
Unicode property: Default_Ignorable_Code_Point
Equations
Instances For
Check if white space character
Unicode property: White_Space
Equations
Instances For
Check if mathematical symbol character
Generated by General_Category=Sm | Other_Math.
Unicode property: Math
Equations
- Unicode.isMath char = Unicode.lookupMath char.val
Instances For
Check if alphabetic character
Generated by General_Category=L | General_Category=Nl | Other_Alphabetic.
Unicode property: Alphabetic
Equations
Instances For
Check if alphabetic character
Generated by General_Category=L | General_Category=Nl | Other_Alphabetic.
Unicode property: Alphabetic