On this page
Ada.Strings.Maps
Copyable sets of Latin-1 characters and character-to-character mappings.
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
Sets and mappings are tables over the 256 Character values. Every operation of RM A.4.2 is there, with contracts that say which characters each set holds and where each mapping takes them: To_Ranges gives the fewest ranges in ascending order, To_Sequence, To_Domain and To_Range their characters in ascending order. To_Mapping requires equal lengths and characters named once. Its bodies are proved (test/programs/prove/library-ada-strings-fixed).
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.Strings.Maps;import Ada.Strings.Maps;
A Vibe module imports this unit's names with from Ada.Strings.Maps 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
Character_Set (declaration) — Copyable private membership table over all 256 Character values; set algebra uses membership rather than sequence order.
Declared interface:
type Character_Set is private;API 002
Null_Set (declaration) — The empty Character_Set with no members.
Declared interface:
Null_Set : constant Character_Set;API 003
Character_Range (declaration) — Inclusive lower/upper Character bounds supplied to To_Set. A null Low..High range contributes no members.
Declared interface:
type Character_Range is record
Low : Character;
High : Character;
end record;API 004
Declared interface:
type Character_Ranges is array (Positive range <>) of Character_Range;API 005
To_Set (declaration) — The characters of any of the ranges.
Declared interface:
function To_Set (Ranges : Character_Ranges) return Character_Set
with Global => null,
Post => (for all C in Character => Is_In (C, To_Set'Result) = (for some I in Ranges'Range => C in Ranges (I).Low .. Ranges (I).High));API 006
To_Ranges (declaration) — The set as the fewest ranges, in ascending order, none empty and no two adjacent.
Declared interface:
function To_Ranges (Set : Character_Set) return Character_Ranges
with Global => null,
Post => To_Ranges'Result'First = 1
and then (for all I in To_Ranges'Result'Range => To_Ranges'Result (I).Low <= To_Ranges'Result (I).High)
and then (for all I in To_Ranges'Result'Range =>
(if I < To_Ranges'Result'Last
then Character'Pos (To_Ranges'Result (I).High) + 1 < Character'Pos (To_Ranges'Result (I + 1).Low)))
and then (for all C in Character =>
Is_In (C, Set) = (for some I in To_Ranges'Result'Range => C in To_Ranges'Result (I).Low .. To_Ranges'Result (I).High));API 007
Is_In (declaration) — Test membership of one Character in a Character_Set.
Declared interface:
function Is_In (Element : Character; Set : Character_Set) return Boolean
with Global => null;API 008
To_Set (declaration) — Build a Latin-1 set from the specified range, singleton or string; the postcondition states exactly which characters belong.
Declared interface:
function To_Set (Span : Character_Range) return Character_Set
with Global => null,
Post => (for all C in Character => Is_In (C, To_Set'Result) = (C in Span.Low .. Span.High));API 009
To_Set (declaration) — Build a Latin-1 set from the specified range, singleton or string; the postcondition states exactly which characters belong.
Declared interface:
function To_Set (Singleton : Character) return Character_Set
with Global => null,
Post => (for all C in Character => Is_In (C, To_Set'Result) = (C = Singleton));API 010
Declared interface:
subtype Character_Sequence is String;API 011
Declared interface:
function To_Set (Sequence : Character_Sequence) return Character_Set
with Global => null,
Post => (for all C in Character => Is_In (C, To_Set'Result) = (for some I in Sequence'Range => Sequence (I) = C));API 012
"not" (declaration) — Complement a Character_Set across the full Character domain.
Declared interface:
function "not" (Right : Character_Set) return Character_Set
with Global => null,
Post => (for all C in Character => Is_In (C, "not"'Result) = not Is_In (C, Right));API 013
"and" (declaration) — Intersection of Character_Set membership.
Declared interface:
function "and" (Left, Right : Character_Set) return Character_Set
with Global => null,
Post => (for all C in Character => Is_In (C, "and"'Result) = (Is_In (C, Left) and Is_In (C, Right)));API 014
"or" (declaration) — Union of Character_Set membership.
Declared interface:
function "or" (Left, Right : Character_Set) return Character_Set
with Global => null,
Post => (for all C in Character => Is_In (C, "or"'Result) = (Is_In (C, Left) or Is_In (C, Right)));API 015
"-" (declaration) — Unary negation, subtraction, time difference or character-set difference according to the profile; their obligations differ.
Declared interface:
function "-" (Left, Right : Character_Set) return Character_Set
with Global => null,
Post => (for all C in Character => Is_In (C, "-"'Result) = (Is_In (C, Left) and not Is_In (C, Right)));API 016
Declared interface:
function "xor" (Left, Right : Character_Set) return Character_Set
with Global => null,
Post => (for all C in Character => Is_In (C, "xor"'Result) = (Is_In (C, Left) /= Is_In (C, Right)));API 017
Is_Subset (declaration) — Test that every member of Elements belongs to Set.
Declared interface:
function Is_Subset (Elements : Character_Set; Set : Character_Set) return Boolean
with Global => null,
Post => Is_Subset'Result = (for all C in Character => (if Is_In (C, Elements) then Is_In (C, Set)));API 018
Declared interface:
function "<=" (Left : Character_Set; Right : Character_Set) return Boolean renames Is_Subset;API 019
To_Sequence (declaration) — The characters of the set, in ascending order.
Declared interface:
function To_Sequence (Set : Character_Set) return Character_Sequence
with Global => null,
Post => To_Sequence'Result'First = 1 and then To_Sequence'Result'Length <= 256
and then (for all I in To_Sequence'Result'Range =>
(if I < To_Sequence'Result'Last then To_Sequence'Result (I) < To_Sequence'Result (I + 1)))
and then (for all C in Character => Is_In (C, Set) = (for some I in To_Sequence'Result'Range => To_Sequence'Result (I) = C));API 020
Character_Mapping (declaration) — Copyable private character-to-character map over all 256 values; Value applies the mapping, and Identity leaves characters unchanged.
Declared interface:
type Character_Mapping is private;API 021
Identity (declaration) — The Character_Mapping sending every Character to itself.
Declared interface:
Identity : constant Character_Mapping;API 022
Declared interface:
function Value (Map : Character_Mapping; Element : Character) return Character
with Global => null;API 023
Lemma_Identity (declaration) — (Verada, a lemma for proofs) a mapping equal to the identity takes Element to itself.
Declared interface:
procedure Lemma_Identity (Map : Character_Mapping; Element : Character)
with Ghost, Global => null, Always_Terminates,
Pre => Map = Identity,
Post => Value (Map, Element) = Element;API 024
Character_Mapping_Function (declaration) — An access to a function from Character to Character, a mapping Index, Count and Translate of Ada.Strings.Unbounded may take.
Declared interface:
type Character_Mapping_Function is access function (From : Character) return Character;API 025
To_Mapping (declaration) — Map corresponding positions of equal-length strings and leave other characters unchanged; duplicate source-character resolution is an implementation detail.
Declared interface:
function To_Mapping (From, To : String) return Character_Mapping
with Global => null,
Pre => From'Length = To'Length
and then (for all I in From'Range => (for all J in From'Range => (if I /= J then From (I) /= From (J)))),
Post => (for all I in From'Range => Value (To_Mapping'Result, From (I)) = To (To'First + (I - From'First)))
and then (for all C in Character => (if (for all I in From'Range => From (I) /= C) then Value (To_Mapping'Result, C) = C));API 026
To_Domain (declaration) — The characters the mapping does not take to themselves, in ascending order.
Declared interface:
function To_Domain (Map : Character_Mapping) return Character_Sequence
with Global => null,
Post => To_Domain'Result'First = 1 and then To_Domain'Result'Length <= 256
and then (for all I in To_Domain'Result'Range =>
(if I < To_Domain'Result'Last then To_Domain'Result (I) < To_Domain'Result (I + 1)))
and then (for all C in Character => (Value (Map, C) /= C) = (for some I in To_Domain'Result'Range => To_Domain'Result (I) = C));API 027
To_Range (declaration) — Where the mapping takes the characters of its domain, in the domain's order.
Declared interface:
function To_Range (Map : Character_Mapping) return Character_Sequence
with Global => null,
Post => To_Range'Result'First = 1
and then To_Range'Result'Length = To_Domain (Map)'Length
and then (for all I in To_Range'Result'Range => To_Range'Result (I) = Value (Map, To_Domain (Map) (I)));