Documentation

UnicodeBasic

General API #

As a general rule, for a given Unicode property called Unicode_Property, for example:

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 #

@[inline]

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 #

    @[inline]

    Get character script

    Returns Zzzz (Unknown) for unassigned, private use and noncharacter code points.

    Unicode property: Script

    Instances For
      @[inline]

      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
        @[inline]

        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 #

          @[inline]

          Get character bidirectional class

          Unicode property: Bidi_Class

          Instances For
            @[inline]

            Check if bidirectional mirrored character

            Unicode property: Bidi_Mirrored

            Instances For
              @[inline]

              Check if bidirectional control character

              Unicode property: Bidi_Control

              Instances For

                General Category #

                @[inline]
                def Unicode.getGC (char : Char) :

                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
                  @[instance_reducible]

                  char ∈ cat holds when the general category of char is included in cat

                  @[instance_reducible]
                  instance Unicode.instDecidableMemCharGC (char : Char) (cat : GC) :
                  Decidable (char ∈ cat)
                  theorem Unicode.GC.mem_of_subset_of_mem {char : Char} {x y : GC} (h : x ⊆ y) :
                  char ∈ x → char ∈ y

                  A character in a general category is also in every category that includes it

                  @[reducible, inline]

                  Check if letter character (L)

                  This is a derived category (L = Lu | Ll | Lt | Lm | Lo).

                  Unicode property: General_Category=L

                  Instances For
                    @[reducible, inline]

                    Check if lowercase letter character (Ll)

                    Unicode property: General_Category=Ll

                    Instances For
                      @[reducible, inline]

                      Check if titlecase letter character (Lt)

                      Unicode property: General_Category=Lt

                      Instances For
                        @[reducible, inline]

                        Check if uppercase letter character (Lu)

                        Unicode property: General_Category=Lu

                        Instances For
                          @[reducible, inline]

                          Check if cased letter character (LC)

                          This is a derived category (LC = Lu | Ll | Lt).

                          Unicode property: General_Category=LC

                          Instances For
                            @[reducible, inline]

                            Check if modifier letter character (Lm)

                            Unicode property: General_Category=Lm

                            Instances For
                              @[reducible, inline]

                              Check if other letter character (Lo)

                              Unicode property: General_Category=Lo

                              Instances For
                                @[reducible, inline]

                                Check if mark character (M)

                                This is a derived category (M = Mn | Mc | Me).

                                Unicode property: General_Category=M

                                Instances For
                                  @[reducible, inline]

                                  Check if nonspacing combining mark character (Mn)

                                  Unicode property: General_Category=Mn

                                  Instances For
                                    @[reducible, inline]

                                    Check if spacing combining mark character (Mc)

                                    Unicode property: General_Category=Mc

                                    Instances For
                                      @[reducible, inline]

                                      Check if enclosing combining mark character (Me)

                                      Unicode property: General_Category=Me

                                      Instances For
                                        @[reducible, inline]

                                        Check if number character (N)

                                        This is a derived category (N = Nd | Nl | No).

                                        Unicode property: General_Category=N

                                        Instances For
                                          @[reducible, inline]

                                          Check if decimal number character (Nd)

                                          Unicode property: General_Category=Nd

                                          Instances For
                                            @[reducible, inline]

                                            Check if letter number character (Nl)

                                            Unicode property: General_Category=Nl

                                            Instances For
                                              @[reducible, inline]

                                              Check if other number character (No)

                                              Unicode property: General_Category=No

                                              Instances For
                                                @[reducible, inline]

                                                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
                                                  @[reducible, inline]

                                                  Check if connector punctuation character (Pc)

                                                  Unicode property: General_Category=Pc

                                                  Instances For
                                                    @[reducible, inline]

                                                    Check if dash punctuation character (Pd)

                                                    Unicode property: General_Category=Pd

                                                    Instances For
                                                      @[reducible, inline]

                                                      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
                                                        @[reducible, inline]

                                                        Check if open punctuation character (Ps)

                                                        Unicode property: General_Category=Ps

                                                        Instances For
                                                          @[reducible, inline]

                                                          Check if close punctuation character (Pe)

                                                          Unicode property: General_Category=Pe

                                                          Instances For
                                                            @[reducible, inline]

                                                            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
                                                              @[reducible, inline]

                                                              Check if initial punctuation character (Pi)

                                                              Unicode property: General_Category=Pi

                                                              Instances For
                                                                @[reducible, inline]

                                                                Check if final punctuation character (Pf)

                                                                Unicode property: General_Category=Pf

                                                                Instances For
                                                                  @[reducible, inline]

                                                                  Check if other punctuation character (Po)

                                                                  Unicode property: General_Category=Po

                                                                  Instances For
                                                                    @[reducible, inline]

                                                                    Check if symbol character (S)

                                                                    This is a derived category (S = Sm | Sc | Sk | So).

                                                                    Unicode property: General_Category=S

                                                                    Instances For
                                                                      @[reducible, inline]

                                                                      Check if math symbol character (Sm)

                                                                      Unicode property: General_Category=Sm

                                                                      Instances For
                                                                        @[reducible, inline]

                                                                        Check if currency symbol character (Sc)

                                                                        Unicode property: General_Category=Sc

                                                                        Instances For
                                                                          @[reducible, inline]

                                                                          Check if modifier symbol character (Sk)

                                                                          Unicode property: General_Category=Sk

                                                                          Instances For
                                                                            @[reducible, inline]

                                                                            Check if other symbol character (So)

                                                                            Unicode property: General_Category=So

                                                                            Instances For
                                                                              @[reducible, inline]

                                                                              Check if separator character (Z)

                                                                              This is a derived category (Z = Zs | Zl | Zp).

                                                                              Unicode property: General_Category=Z

                                                                              Instances For
                                                                                @[reducible, inline]

                                                                                Check if space separator character (Zs)

                                                                                Unicode property: General_Category=Zs

                                                                                Instances For
                                                                                  @[reducible, inline]

                                                                                  Check if line separator character (Zl)

                                                                                  Unicode property: General_Category=Zl

                                                                                  Instances For
                                                                                    @[reducible, inline]

                                                                                    Check if paragraph separator character (Zp)

                                                                                    Unicode property: General_Category=Zp

                                                                                    Instances For
                                                                                      @[reducible, inline]

                                                                                      Check if other character (C)

                                                                                      This is a derived category (C = Cc | Cf | Cs | Co | Cn).

                                                                                      Unicode property: General_Category=C

                                                                                      Instances For
                                                                                        @[reducible, inline]

                                                                                        Check if control character (Cc)

                                                                                        Unicode property: General_Category=Cc

                                                                                        Instances For
                                                                                          @[reducible, inline]

                                                                                          Check if format character (Cf)

                                                                                          Unicode property: General_Category=Cf

                                                                                          Instances For
                                                                                            @[reducible, inline]

                                                                                            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
                                                                                              @[reducible, inline]

                                                                                              Check if private use character (Co)

                                                                                              Unicode property: General_Category=Co

                                                                                              Instances For
                                                                                                @[reducible, inline]

                                                                                                Check if unassigned character (Cn)

                                                                                                Unicode property: General_Category=Cn

                                                                                                Instances For

                                                                                                  Case Type and Mapping #

                                                                                                  @[inline]

                                                                                                  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
                                                                                                    @[inline]

                                                                                                    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
                                                                                                      @[inline]
                                                                                                      def Unicode.isCased (char : Char) :

                                                                                                      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
                                                                                                        @[inline]

                                                                                                        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

                                                                                                          Auxiliary data for isCaseIgnorable

                                                                                                          Extracted from UCD auxiliary/WordBreakProperty.txt.

                                                                                                          Instances For
                                                                                                            @[inline]

                                                                                                            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
                                                                                                              @[inline]

                                                                                                              Full lowercase mapping of a character as its first code point and the rest

                                                                                                              Internal use only.

                                                                                                              Instances For
                                                                                                                @[inline]
                                                                                                                def Unicode.withLowercasing {β : Sort u_1} (char : Char) (k : Char → List Char → β) :
                                                                                                                β

                                                                                                                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
                                                                                                                    @[inline]

                                                                                                                    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
                                                                                                                      @[inline]

                                                                                                                      Full uppercase mapping of a character as its first code point and the rest

                                                                                                                      Internal use only.

                                                                                                                      Instances For
                                                                                                                        @[inline]
                                                                                                                        def Unicode.withUppercasing {β : Sort u_1} (char : Char) (k : Char → List Char → β) :
                                                                                                                        β

                                                                                                                        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
                                                                                                                            @[inline]

                                                                                                                            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
                                                                                                                              @[inline]

                                                                                                                              Full titlecase mapping of a character as its first code point and the rest

                                                                                                                              Internal use only.

                                                                                                                              Instances For
                                                                                                                                @[inline]
                                                                                                                                def Unicode.withTitlecasing {β : Sort u_1} (char : Char) (k : Char → List Char → β) :
                                                                                                                                β

                                                                                                                                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
                                                                                                                                    @[inline]

                                                                                                                                    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
                                                                                                                                      @[inline]

                                                                                                                                      Full case folding of a character as its first code point and the rest

                                                                                                                                      Internal use only.

                                                                                                                                      Instances For
                                                                                                                                        @[inline]
                                                                                                                                        def Unicode.withCaseFolding {β : Sort u_1} (char : Char) (k : Char → List Char → β) :
                                                                                                                                        β

                                                                                                                                        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
                                                                                                                                          @[inline]

                                                                                                                                          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 #

                                                                                                                                                    @[inline]

                                                                                                                                                    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
                                                                                                                                                      @[inline]
                                                                                                                                                      def Unicode.isDigit (char : Char) :

                                                                                                                                                      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
                                                                                                                                                        @[inline]
                                                                                                                                                        def Unicode.getDigit? (char : Char) :
                                                                                                                                                        Option (Fin 10)

                                                                                                                                                        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

                                                                                                                                                        Instances For
                                                                                                                                                          @[inline]

                                                                                                                                                          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
                                                                                                                                                            @[inline]

                                                                                                                                                            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
                                                                                                                                                              @[inline]

                                                                                                                                                              Check if character represents a hexadecimal digit

                                                                                                                                                              Unicode property: Hex_Digit

                                                                                                                                                              Instances For
                                                                                                                                                                @[inline]
                                                                                                                                                                def Unicode.getHexDigit? (char : Char) :
                                                                                                                                                                Option (Fin 16)

                                                                                                                                                                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 #

                                                                                                                                                                  @[inline]

                                                                                                                                                                  Check if noncharacter code point

                                                                                                                                                                  Unicode property: Noncharacter_Code_Point

                                                                                                                                                                  Instances For
                                                                                                                                                                    @[inline]

                                                                                                                                                                    Check if default ignorable character

                                                                                                                                                                    Unicode property: Default_Ignorable_Code_Point

                                                                                                                                                                    Instances For
                                                                                                                                                                      @[inline]

                                                                                                                                                                      Check if white space character

                                                                                                                                                                      Unicode property: White_Space

                                                                                                                                                                      Instances For
                                                                                                                                                                        @[inline]
                                                                                                                                                                        def Unicode.isMath (char : Char) :

                                                                                                                                                                        Check if mathematical symbol character

                                                                                                                                                                        Generated by General_Category=Sm | Other_Math.

                                                                                                                                                                        Unicode property: Math

                                                                                                                                                                        Instances For
                                                                                                                                                                          @[inline]

                                                                                                                                                                          Check if alphabetic character

                                                                                                                                                                          Generated by General_Category=L | General_Category=Nl | Other_Alphabetic.

                                                                                                                                                                          Unicode property: Alphabetic

                                                                                                                                                                          Instances For
                                                                                                                                                                            @[reducible, inline]
                                                                                                                                                                            abbrev Unicode.isAlpha (char : Char) :

                                                                                                                                                                            Check if alphabetic character

                                                                                                                                                                            Generated by General_Category=L | General_Category=Nl | Other_Alphabetic.

                                                                                                                                                                            Unicode property: Alphabetic

                                                                                                                                                                            Instances For