DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Ada.Characters.Handling

Latin-1 classification and upper/lower conversion.

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

The classifiers are expression functions, so a proof sees the exact character sets. String conversions keep the source's bounds. Case conversion covers Latin-1 only; there is no locale or Unicode case mapping.

A client proof uses these contracts without proving the body again (see library assurance). Global => null excludes package-global effects, not changes made through an in out argument.

Import and instantiate

with Ada.Characters.Handling;
import Ada.Characters.Handling;

A Vibe module imports this unit's names with from Ada.Characters.Handling import Name; see library use across syntaxes. In Varc, keep each name's declared spelling and write & on arguments the call changes.

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. Ghost functions are for contracts and ghost code. The family guide describes copying, lifetime, order and cost.

API 001

Is_Control (declaration) — Recognize Character positions 0..31 or 127..159.

Declared interface:

function Is_Control (Item : Character) return Boolean is
  (Character'Pos (Item) in 0 .. 31 | 127 .. 159);

API 002

Is_Graphic (declaration) — Recognize characters outside Is_Control.

Declared interface:

function Is_Graphic (Item : Character) return Boolean is (not Is_Control (Item));

API 003

Is_Upper (declaration) — Recognize ASCII and the declared Latin-1 uppercase ranges.

Declared interface:

function Is_Upper (Item : Character) return Boolean is
  (Item in 'A' .. 'Z' or else Character'Pos (Item) in 192 .. 214 | 216 .. 222);

API 004

Is_Lower (declaration) — Recognize ASCII and the declared Latin-1 lowercase ranges.

Declared interface:

function Is_Lower (Item : Character) return Boolean is
  (Item in 'a' .. 'z' or else Character'Pos (Item) in 223 .. 246 | 248 .. 255);

API 005

Is_Letter (declaration) — Recognize Is_Upper or Is_Lower.

Declared interface:

function Is_Letter (Item : Character) return Boolean is (Is_Upper (Item) or else Is_Lower (Item));

API 006

Is_Basic (declaration) — Recognize the explicitly listed basic-letter subset, not arbitrary ASCII characters.

Declared interface:

function Is_Basic (Item : Character) return Boolean is
  (Item in 'A' .. 'Z' | 'a' .. 'z' or else Character'Pos (Item) in 198 | 208 | 222 | 223 | 230 | 240 | 254);

API 007

Is_Digit (declaration) — Recognize ASCII decimal characters 0 through 9.

Declared interface:

function Is_Digit (Item : Character) return Boolean is (Item in '0' .. '9');

API 008

Is_Decimal_Digit (declaration) — Renaming of Is_Digit with identical character classification.

Declared interface:

function Is_Decimal_Digit (Item : Character) return Boolean renames Is_Digit;

API 009

Is_Hexadecimal_Digit (declaration) — Recognize ASCII 0..9, A..F or a..f.

Declared interface:

function Is_Hexadecimal_Digit (Item : Character) return Boolean is
  (Item in '0' .. '9' | 'A' .. 'F' | 'a' .. 'f');

API 010

Is_Alphanumeric (declaration) — Recognize a supported letter or decimal digit.

Declared interface:

function Is_Alphanumeric (Item : Character) return Boolean is (Is_Letter (Item) or else Is_Digit (Item));

API 011

Is_Special (declaration) — Recognize graphic nonalphanumeric characters.

Declared interface:

function Is_Special (Item : Character) return Boolean is
  (Is_Graphic (Item) and then not Is_Alphanumeric (Item));

API 012

Is_Line_Terminator (declaration) — Recognize positions 10..13 or 133.

Declared interface:

function Is_Line_Terminator (Item : Character) return Boolean is
  (Character'Pos (Item) in 10 .. 13 | 133);

API 013

Is_Space (declaration) — Recognize ordinary/no-break spaces, positions 32 or 160; tabs are not included.

Declared interface:

function Is_Space (Item : Character) return Boolean is (Character'Pos (Item) in 32 | 160);

API 014

Is_Mark (declaration) — Always False: Latin-1 has no combining marks.

Declared interface:

function Is_Mark (Item : Character) return Boolean is (False);

API 015

Is_Other_Format (declaration) — Recognize the soft hyphen, position 173, Latin-1's one format character.

Declared interface:

function Is_Other_Format (Item : Character) return Boolean is (Character'Pos (Item) = 173);

API 016

Is_Punctuation_Connector (declaration) — Recognize the low line _, Latin-1's one connector punctuation.

Declared interface:

function Is_Punctuation_Connector (Item : Character) return Boolean is (Item = '_');

API 017

Is_NFKC (declaration) — Whether compatibility normalization (NFKC) leaves the character as it is: every position except 160, 168, 170, 175, 178..181, 184..186 and 188..190.

Declared interface:

function Is_NFKC (Item : Character) return Boolean is
  (Character'Pos (Item) not in 160 | 168 | 170 | 175 | 178 .. 181 | 184 .. 186 | 188 .. 190);

API 018

To_Upper (declaration) — The upper-case letter of a lower-case one, by subtracting 32 in the supported ranges; ß and ÿ, whose upper-case letters Latin-1 lacks, are unchanged, as is every other character.

Declared interface:

function To_Upper (Item : Character) return Character is
  (if Item in 'a' .. 'z' or else Character'Pos (Item) in 224 .. 246 | 248 .. 254
   then Character'Val (Character'Pos (Item) - 32)
   else Item);

API 019

To_Lower (declaration) — The lower-case letter of an upper-case one (Is_Upper), by adding 32; every other character unchanged.

Declared interface:

function To_Lower (Item : Character) return Character is
  (if Is_Upper (Item) then Character'Val (Character'Pos (Item) + 32) else Item);

API 020

To_Upper (declaration) — To_Upper of each character, indexed from 1 with Item's length.

Declared interface:

function To_Upper (Item : String) return String
  with Post => To_Upper'Result'First = 1 and then To_Upper'Result'Length = Item'Length
               and then (for all I in 1 .. Item'Length => To_Upper'Result (I) = To_Upper (Item (I - 1 + Item'First)));

API 021

To_Lower (declaration) — To_Lower of each character, indexed from 1 with Item's length.

Declared interface:

function To_Lower (Item : String) return String
  with Post => To_Lower'Result'First = 1 and then To_Lower'Result'Length = Item'Length
               and then (for all I in 1 .. Item'Length => To_Lower'Result (I) = To_Lower (Item (I - 1 + Item'First)));

API 022

To_Basic (declaration) — The basic letter of a letter with a diacritical mark (é to e); every other character unchanged.

Declared interface:

function To_Basic (Item : Character) return Character is
  (case Character'Pos (Item) is
      when 192 .. 197 => 'A', when 199 => 'C', when 200 .. 203 => 'E', when 204 .. 207 => 'I',
      when 209 => 'N', when 210 .. 214 | 216 => 'O', when 217 .. 220 => 'U', when 221 => 'Y',
      when 224 .. 229 => 'a', when 231 => 'c', when 232 .. 235 => 'e', when 236 .. 239 => 'i',
      when 241 => 'n', when 242 .. 246 | 248 => 'o', when 249 .. 252 => 'u', when 253 | 255 => 'y',
      when others => Item);

API 023

To_Basic (declaration) — To_Basic of each character, indexed from 1 with Item's length.

Declared interface:

function To_Basic (Item : String) return String
  with Post => To_Basic'Result'First = 1 and then To_Basic'Result'Length = Item'Length
               and then (for all I in 1 .. Item'Length => To_Basic'Result (I) = To_Basic (Item (I - 1 + Item'First)));

API 024

ISO_646 (declaration) — The subtype of the first 128 characters.

Declared interface:

subtype ISO_646 is Character range Character'Val (0) .. Character'Val (127);

API 025

Is_ISO_646 (declaration) — Whether the character is in ISO_646, below position 128.

Declared interface:

function Is_ISO_646 (Item : Character) return Boolean is (Item in ISO_646);

API 026

Is_ISO_646 (declaration) — Whether every character of the string is in ISO_646.

Declared interface:

function Is_ISO_646 (Item : String) return Boolean is (for all I in Item'Range => Is_ISO_646 (Item (I)));

API 027

To_ISO_646 (declaration) — The character if it is in ISO_646, else Substitute.

Declared interface:

function To_ISO_646 (Item : Character; Substitute : ISO_646 := ' ') return ISO_646 is
  (if Is_ISO_646 (Item) then Item else Substitute);

API 028

To_ISO_646 (declaration) — To_ISO_646 of each character, indexed from 1 with Item's length.

Declared interface:

function To_ISO_646 (Item : String; Substitute : ISO_646 := ' ') return String
  with Post => To_ISO_646'Result'First = 1 and then To_ISO_646'Result'Length = Item'Length
               and then (for all I in 1 .. Item'Length => To_ISO_646'Result (I) = To_ISO_646 (Item (I - 1 + Item'First), Substitute));