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

Equations
Instances For

    Script #

    @[inline]

    Get character script

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

    Unicode property: Script

    Equations
    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

      Equations
      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

        Equations
        Instances For

          Bidirectional Properties #

          @[inline]

          Get character bidirectional class

          Unicode property: Bidi_Class

          Equations
          Instances For
            @[inline]

            Check if bidirectional mirrored character

            Unicode property: Bidi_Mirrored

            Equations
            Instances For
              @[inline]

              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 #

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

                Equations
                Instances For
                  @[instance_reducible]

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

                  Equations
                  @[instance_reducible]
                  instance Unicode.instDecidableMemCharGC (char : Char) (cat : GC) :
                  Decidable (char ∈ cat)
                  Equations
                  @[reducible, inline]

                  Check if letter character (L)

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

                  Unicode property: General_Category=L

                  Equations
                  Instances For
                    @[reducible, inline]

                    Check if lowercase letter character (Ll)

                    Unicode property: General_Category=Ll

                    Equations
                    Instances For
                      @[reducible, inline]

                      Check if titlecase letter character (Lt)

                      Unicode property: General_Category=Lt

                      Equations
                      Instances For
                        @[reducible, inline]

                        Check if uppercase letter character (Lu)

                        Unicode property: General_Category=Lu

                        Equations
                        Instances For
                          @[reducible, inline]

                          Check if cased letter character (LC)

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

                          Unicode property: General_Category=LC

                          Equations
                          Instances For
                            @[reducible, inline]

                            Check if modifier letter character (Lm)

                            Unicode property: General_Category=Lm

                            Equations
                            Instances For
                              @[reducible, inline]

                              Check if other letter character (Lo)

                              Unicode property: General_Category=Lo

                              Equations
                              Instances For
                                @[reducible, inline]

                                Check if mark character (M)

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

                                Unicode property: General_Category=M

                                Equations
                                Instances For
                                  @[reducible, inline]

                                  Check if nonspacing combining mark character (Mn)

                                  Unicode property: General_Category=Mn

                                  Equations
                                  Instances For
                                    @[reducible, inline]

                                    Check if spacing combining mark character (Mc)

                                    Unicode property: General_Category=Mc

                                    Equations
                                    Instances For
                                      @[reducible, inline]

                                      Check if enclosing combining mark character (Me)

                                      Unicode property: General_Category=Me

                                      Equations
                                      Instances For
                                        @[reducible, inline]

                                        Check if number character (N)

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

                                        Unicode property: General_Category=N

                                        Equations
                                        Instances For
                                          @[reducible, inline]

                                          Check if decimal number character (Nd)

                                          Unicode property: General_Category=Nd

                                          Equations
                                          Instances For
                                            @[reducible, inline]

                                            Check if letter number character (Nl)

                                            Unicode property: General_Category=Nl

                                            Equations
                                            Instances For
                                              @[reducible, inline]

                                              Check if other number character (No)

                                              Unicode property: General_Category=No

                                              Equations
                                              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

                                                Equations
                                                Instances For
                                                  @[reducible, inline]

                                                  Check if connector punctuation character (Pc)

                                                  Unicode property: General_Category=Pc

                                                  Equations
                                                  Instances For
                                                    @[reducible, inline]

                                                    Check if dash punctuation character (Pd)

                                                    Unicode property: General_Category=Pd

                                                    Equations
                                                    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

                                                      Equations
                                                      Instances For
                                                        @[reducible, inline]

                                                        Check if open punctuation character (Ps)

                                                        Unicode property: General_Category=Ps

                                                        Equations
                                                        Instances For
                                                          @[reducible, inline]

                                                          Check if close punctuation character (Pe)

                                                          Unicode property: General_Category=Pe

                                                          Equations
                                                          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

                                                            Equations
                                                            Instances For
                                                              @[reducible, inline]

                                                              Check if initial punctuation character (Pi)

                                                              Unicode property: General_Category=Pi

                                                              Equations
                                                              Instances For
                                                                @[reducible, inline]

                                                                Check if final punctuation character (Pf)

                                                                Unicode property: General_Category=Pf

                                                                Equations
                                                                Instances For
                                                                  @[reducible, inline]

                                                                  Check if other punctuation character (Po)

                                                                  Unicode property: General_Category=Po

                                                                  Equations
                                                                  Instances For
                                                                    @[reducible, inline]

                                                                    Check if symbol character (S)

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

                                                                    Unicode property: General_Category=S

                                                                    Equations
                                                                    Instances For
                                                                      @[reducible, inline]

                                                                      Check if math symbol character (Sm)

                                                                      Unicode property: General_Category=Sm

                                                                      Equations
                                                                      Instances For
                                                                        @[reducible, inline]

                                                                        Check if currency symbol character (Sc)

                                                                        Unicode property: General_Category=Sc

                                                                        Equations
                                                                        Instances For
                                                                          @[reducible, inline]

                                                                          Check if modifier symbol character (Sk)

                                                                          Unicode property: General_Category=Sk

                                                                          Equations
                                                                          Instances For
                                                                            @[reducible, inline]

                                                                            Check if other symbol character (So)

                                                                            Unicode property: General_Category=So

                                                                            Equations
                                                                            Instances For
                                                                              @[reducible, inline]

                                                                              Check if separator character (Z)

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

                                                                              Unicode property: General_Category=Z

                                                                              Equations
                                                                              Instances For
                                                                                @[reducible, inline]

                                                                                Check if space separator character (Zs)

                                                                                Unicode property: General_Category=Zs

                                                                                Equations
                                                                                Instances For
                                                                                  @[reducible, inline]

                                                                                  Check if line separator character (Zl)

                                                                                  Unicode property: General_Category=Zl

                                                                                  Equations
                                                                                  Instances For
                                                                                    @[reducible, inline]

                                                                                    Check if paragraph separator character (Zp)

                                                                                    Unicode property: General_Category=Zp

                                                                                    Equations
                                                                                    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

                                                                                      Equations
                                                                                      Instances For
                                                                                        @[reducible, inline]

                                                                                        Check if control character (Cc)

                                                                                        Unicode property: General_Category=Cc

                                                                                        Equations
                                                                                        Instances For
                                                                                          @[reducible, inline]

                                                                                          Check if format character (Cf)

                                                                                          Unicode property: General_Category=Cf

                                                                                          Equations
                                                                                          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

                                                                                            Equations
                                                                                            Instances For
                                                                                              @[reducible, inline]

                                                                                              Check if private use character (Co)

                                                                                              Unicode property: General_Category=Co

                                                                                              Equations
                                                                                              Instances For
                                                                                                @[reducible, inline]

                                                                                                Check if unassigned character (Cn)

                                                                                                Unicode property: General_Category=Cn

                                                                                                Equations
                                                                                                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

                                                                                                  Equations
                                                                                                  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

                                                                                                    Equations
                                                                                                    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

                                                                                                      Equations
                                                                                                      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

                                                                                                        Equations
                                                                                                        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

                                                                                                          Equations
                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                          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

                                                                                                            Equations
                                                                                                            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
                                                                                                              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

                                                                                                                Equations
                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                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

                                                                                                                  Equations
                                                                                                                  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
                                                                                                                    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

                                                                                                                      Equations
                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                      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

                                                                                                                        Equations
                                                                                                                        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
                                                                                                                          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

                                                                                                                            Equations
                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                            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

                                                                                                                              Equations
                                                                                                                              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

                                                                                                                                Equations
                                                                                                                                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
                                                                                                                                    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
                                                                                                                                        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)

                                                                                                                                          Equations
                                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                                          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

                                                                                                                                            Equations
                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                            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

                                                                                                                                              Equations
                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                              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

                                                                                                                                                Equations
                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                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

                                                                                                                                                  Equations
                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                  Instances For
                                                                                                                                                    @[inline]

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

                                                                                                                                                      Equations
                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                      Instances For

                                                                                                                                                        Other Properties #

                                                                                                                                                        @[inline]

                                                                                                                                                        Check if noncharacter code point

                                                                                                                                                        Unicode property: Noncharacter_Code_Point

                                                                                                                                                        Equations
                                                                                                                                                        Instances For
                                                                                                                                                          @[inline]

                                                                                                                                                          Check if default ignorable character

                                                                                                                                                          Unicode property: Default_Ignorable_Code_Point

                                                                                                                                                          Equations
                                                                                                                                                          Instances For
                                                                                                                                                            @[inline]

                                                                                                                                                            Check if white space character

                                                                                                                                                            Unicode property: White_Space

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

                                                                                                                                                              Check if mathematical symbol character

                                                                                                                                                              Generated by General_Category=Sm | Other_Math.

                                                                                                                                                              Unicode property: Math

                                                                                                                                                              Equations
                                                                                                                                                              Instances For
                                                                                                                                                                @[inline]

                                                                                                                                                                Check if alphabetic character

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

                                                                                                                                                                Unicode property: Alphabetic

                                                                                                                                                                Equations
                                                                                                                                                                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

                                                                                                                                                                  Equations
                                                                                                                                                                  Instances For