DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Verada.Strings.Unicode

CPython's character classes and case mappings of all of Unicode, for Verada.Strings.Text_Operations.

Read the family guide for representation, selection and resource rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.

Availability and ownership

Digit_Code, Alpha_Code and Space_Code are CPython's isdigit, isalpha and isspace of a code point, and Upper_Code and Lower_Code its upper and lower case where that is one character: the run time's tables, generated from CPython's own str methods (rt/unicode.c). Verada.Strings.Text_Operations' character functions are made of them; programs do not need to import this unit.

Import and instantiate

with Verada.Strings.Unicode;
import Verada.Strings.Unicode;

Contract and lifecycle reading

A Pre condition is the caller's obligation; a Post is what a normal return guarantees. What a postcondition does not state, a client cannot assume.

API 001

Digit_Code (declaration) — 1 when CPython's isdigit holds of the code point, else 0: the run time's tables of Unicode.

Declared interface:

function Digit_Code (Code : Integer) return Integer
  with Import, Convention => Ada, External_Name => "verada_rt_digit_code",
       Global => null,
       Post => Digit_Code'Result in 0 .. 1;

API 002

Alpha_Code (declaration) — 1 when CPython's isalpha holds of the code point, else 0: the run time's tables of Unicode.

Declared interface:

function Alpha_Code (Code : Integer) return Integer
  with Import, Convention => Ada, External_Name => "verada_rt_alpha_code",
       Global => null,
       Post => Alpha_Code'Result in 0 .. 1;

API 003

Space_Code (declaration) — 1 when CPython's isspace holds of the code point, else 0: the run time's tables of Unicode.

Declared interface:

function Space_Code (Code : Integer) return Integer
  with Import, Convention => Ada, External_Name => "verada_rt_space_code",
       Global => null,
       Post => Space_Code'Result in 0 .. 1;

API 004

Upper_Code (declaration) — A code point's upper case, CPython's where it is one character: the run time's tables of Unicode.

Declared interface:

function Upper_Code (Code : Integer) return Integer
  with Import, Convention => Ada, External_Name => "verada_rt_upper_of",
       Global => null,
       Pre => Code in 0 .. 16#10FFFF#,
       Post => Upper_Code'Result in 0 .. 16#10FFFF#;

API 005

Lower_Code (declaration) — A code point's lower case, CPython's where it is one character: the run time's tables of Unicode.

Declared interface:

function Lower_Code (Code : Integer) return Integer
  with Import, Convention => Ada, External_Name => "verada_rt_lower_of",
       Global => null,
       Pre => Code in 0 .. 16#10FFFF#,
       Post => Lower_Code'Result in 0 .. 16#10FFFF#;

API 006

General_Category (declaration) — Unicode's general categories by their short names, in the order of the run time's codes.

Declared interface:

type General_Category is
  (Lu, Ll, Lt, Lm, Lo, Mn, Mc, Me, Nd, Nl, No, Pc, Pd, Ps, Pe, Pi, Pf, Po,
   Sm, Sc, Sk, So, Zs, Zl, Zp, Cc, Cf, Cs, Co, Cn);

API 007

Category_Code (declaration) — The position in General_Category of a code point's category, from the run time's table (Cn beyond Unicode).

Declared interface:

function Category_Code (Code : Natural) return Natural
  with Import, Convention => Ada, External_Name => "verada_rt_category_code",
       Global => null,
       Post => Category_Code'Result <= General_Category'Pos (General_Category'Last);

API 008

Compatibility_Code (declaration) — 1 when the code point has a compatibility decomposition, else 0.

Declared interface:

function Compatibility_Code (Code : Natural) return Natural
  with Import, Convention => Ada, External_Name => "verada_rt_compatibility_code",
       Global => null,
       Post => Compatibility_Code'Result in 0 .. 1;

API 009

NFKC_Code (declaration) — 1 when normalization form KC leaves the code point as it is, else 0.

Declared interface:

function NFKC_Code (Code : Natural) return Natural
  with Import, Convention => Ada, External_Name => "verada_rt_nfkc_code",
       Global => null,
       Post => NFKC_Code'Result in 0 .. 1;

API 010

Simple_Upper_Code (declaration) — Unicode's simple upper-case mapping of a code point, else the code point, from the run time's table.

Declared interface:

function Simple_Upper_Code (Code : Natural) return Natural
  with Import, Convention => Ada, External_Name => "verada_rt_simple_upper",
       Global => null,
       Post => Simple_Upper_Code'Result <= 16#10FFFF# or else Simple_Upper_Code'Result = Code;

API 011

Simple_Lower_Code (declaration) — Unicode's simple lower-case mapping of a code point, else the code point, from the run time's table.

Declared interface:

function Simple_Lower_Code (Code : Natural) return Natural
  with Import, Convention => Ada, External_Name => "verada_rt_simple_lower",
       Global => null,
       Post => Simple_Lower_Code'Result <= 16#10FFFF# or else Simple_Lower_Code'Result = Code;

API 012

Basic_Code (declaration) — A letter's basic letter (the letter its canonical decomposition starts with when the rest is combining marks), else the code point.

Declared interface:

function Basic_Code (Code : Natural) return Natural
  with Import, Convention => Ada, External_Name => "verada_rt_basic_of",
       Global => null,
       Post => Basic_Code'Result <= 16#10FFFF# or else Basic_Code'Result = Code;

API 013

Category (declaration) — A code point's general category: Latin-1's written out, so that proofs see it; the rest from Category_Code.

Declared interface:

function Category (Code : Natural) return General_Category is
  (if Code > 255 then General_Category'Val (Category_Code (Code))
   else (case Code is
            when 0 .. 31 | 127 .. 159 => Cc,
            when 32 | 160 => Zs,
            when 33 .. 35 | 37 .. 39 | 42 | 44 | 46 .. 47 | 58 .. 59 | 63 .. 64 | 92 | 161 | 167
                 | 182 .. 183 | 191 => Po,
            when 36 | 162 .. 165 => Sc,
            when 40 | 91 | 123 => Ps,
            when 41 | 93 | 125 => Pe,
            when 43 | 60 .. 62 | 124 | 126 | 172 | 177 | 215 | 247 => Sm,
            when 45 => Pd,
            when 48 .. 57 => Nd,
            when 65 .. 90 | 192 .. 214 | 216 .. 222 => Lu,
            when 94 | 96 | 168 | 175 | 180 | 184 => Sk,
            when 95 => Pc,
            when 97 .. 122 | 181 | 223 .. 246 | 248 .. 255 => Ll,
            when 166 | 169 | 174 | 176 => So,
            when 170 | 186 => Lo,
            when 171 => Pi,
            when 173 => Cf,
            when 178 .. 179 | 185 | 188 .. 190 => No,
            when 187 => Pf,
            when others => Cn));

API 014

Has_Compatibility_Decomposition (declaration) — Whether a code point has a compatibility decomposition: Latin-1's written out, the rest from Compatibility_Code.

Declared interface:

function Has_Compatibility_Decomposition (Code : Natural) return Boolean is
  (if Code > 255 then Compatibility_Code (Code) = 1
   else Code in 160 | 168 | 170 | 175 | 178 .. 181 | 184 .. 186 | 188 .. 190);

API 015

Is_NFKC (declaration) — Whether normalization form KC leaves a code point as it is: Latin-1's written out, the rest from NFKC_Code.

Declared interface:

function Is_NFKC (Code : Natural) return Boolean is
  (if Code > 255 then NFKC_Code (Code) = 1
   else Code not in 160 | 168 | 170 | 175 | 178 .. 181 | 184 .. 186 | 188 .. 190);

API 016

Simple_Upper (declaration) — A code point's simple upper case: Latin-1's written out, the rest from Simple_Upper_Code.

Declared interface:

function Simple_Upper (Code : Natural) return Natural is
  (if Code > 255 then Simple_Upper_Code (Code)
   elsif Code in 97 .. 122 | 224 .. 246 | 248 .. 254 then Code - 32
   elsif Code = 181 then 924
   elsif Code = 255 then 376
   else Code);

API 017

Simple_Lower (declaration) — A code point's simple lower case: Latin-1's written out, the rest from Simple_Lower_Code.

Declared interface:

function Simple_Lower (Code : Natural) return Natural is
  (if Code > 255 then Simple_Lower_Code (Code)
   elsif Code in 65 .. 90 | 192 .. 214 | 216 .. 222 then Code + 32
   else Code);

API 018

Basic (declaration) — A code point's basic letter: Latin-1's written out, the rest from Basic_Code.

Declared interface:

function Basic (Code : Natural) return Natural is
  (if Code > 255 then Basic_Code (Code)
   else (case Code is
            when 192 .. 197 => 65, when 199 => 67, when 200 .. 203 => 69, when 204 .. 207 => 73,
            when 209 => 78, when 210 .. 214 => 79, when 217 .. 220 => 85, when 221 => 89,
            when 224 .. 229 => 97, when 231 => 99, when 232 .. 235 => 101, when 236 .. 239 => 105,
            when 241 => 110, when 242 .. 246 => 111, when 249 .. 252 => 117, when 253 | 255 => 121,
            when others => Code));