Documentation

Hale.Base.Data.Char

@[inline]

Alias for Char.isWhitespace. $$\text{isSpace}(c) = \text{isWhitespace}(c)$$

Equations
Instances For
    @[inline]

    Test if a character is alphanumeric (letter or digit). $$\text{isAlphaNum}(c) = \text{isAlpha}(c) \lor \text{isDigit}(c)$$

    Equations
    Instances For
      @[inline]

      Test if a character is in the ASCII range $[0, 128)$. $$\text{isAscii}(c) \iff \text{ord}(c) < 128$$

      Equations
      Instances For
        @[inline]

        Test if a character is in the Latin-1 range $[0, 256)$. $$\text{isLatin1}(c) \iff \text{ord}(c) < 256$$

        Equations
        Instances For
          @[inline]

          Test if a character is a control character (codes 0--31 or 127). $$\text{isControl}(c) \iff \text{ord}(c) < 32 \lor \text{ord}(c) = 127$$

          Equations
          Instances For
            @[inline]

            Test if a character is printable (ASCII, non-control). $$\text{isPrint}(c) \iff \lnot\,\text{isControl}(c) \land \text{ord}(c) < 128$$ Note: this is a simplified ASCII-only version.

            Equations
            Instances For
              @[inline]

              Test if a character is a hexadecimal digit: 0--9, a--f, A--F. $$\text{isHexDigit}(c) \iff c \in [0\text{-}9] \cup [a\text{-}f] \cup [A\text{-}F]$$

              Equations
              Instances For
                @[inline]

                Test if a character is an octal digit: 0--7. $$\text{isOctDigit}(c) \iff \text{ord}(c) \in [48, 55]$$

                Equations
                Instances For
                  @[inline]

                  Test if a character is an ASCII uppercase letter: A--Z. $$\text{isAsciiUpper}(c) \iff \text{ord}(c) \in [65, 90]$$

                  Equations
                  Instances For
                    @[inline]

                    Test if a character is an ASCII lowercase letter: a--z. $$\text{isAsciiLower}(c) \iff \text{ord}(c) \in [97, 122]$$

                    Equations
                    Instances For
                      @[inline]

                      Test if a character is ASCII punctuation. $$\text{isPunctuation}(c) \iff c \in [\texttt{!}-\texttt{/}] \cup [\texttt{:}-\texttt{@}] \cup [\texttt{[}-\texttt{`}] \cup [\texttt{\{}-\texttt{~}]$$ Covers ASCII punctuation ranges: 33--47, 58--64, 91--96, 123--126.

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

                        Character to its Unicode code point. $$\text{ord}(c) = \text{toNat}(c)$$

                        Equations
                        Instances For
                          @[inline]

                          Code point to character. $$\text{chr}(n) = \text{Char.ofNat}(n)$$

                          Equations
                          Instances For

                            Convert a hex digit character to its numeric value, bounded below 16. $$\text{digitToInt}(c) = \begin{cases} n - 48 & c \in [\texttt{0}\text{-}\texttt{9}] \\ n - 55 & c \in [\texttt{A}\text{-}\texttt{F}] \\ n - 87 & c \in [\texttt{a}\text{-}\texttt{f}] \\ \text{none} & \text{otherwise} \end{cases}$$ Returns Option {n : Nat // n < 16} — the proof that the digit is in $[0, 15]$ is carried in the subtype and erased at runtime.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              def Data.Char'.intToDigit (n : Nat) (_h : n < 16 := by omega) :

                              Convert a number in $[0, 15]$ to a hex digit character. Total — no Option needed. $$\text{intToDigit}(n) = \begin{cases} \texttt{0} + n & n \in [0, 9] \\ \texttt{a} + (n - 10) & n \in [10, 15] \end{cases}$$ The proof obligation n < 16 is required at the call site and erased at runtime.

                              Equations
                              Instances For

                                isAlphaNum unfolds to its definition.

                                isSpace is an alias for isWhitespace.

                                ord is an alias for toNat.

                                theorem Data.Char'.isAscii_bound (c : Char) (h : isAscii c = true) :
                                c.toNat < 128

                                isAscii c = true implies c.toNat < 128.

                                Roundtrip: digitToInt (intToDigit n) = some ⟨n, h⟩ for all n < 16.

                                isAscii is true iff the code point is below 128.

                                Every decimal digit is also a hex digit.

                                theorem Data.Char'.intToDigit_isAscii (n : Nat) (h : n < 16) :

                                intToDigit always produces an ASCII character.