On this page
Verada.Strings.Texts
Copyable reference-counted immutable text.
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
A text holds Unicode code points; its model is To_Wide_Wide_String. A default Text is empty. A copy shares the characters (Share is the Adjust operation, Release the finalizer). Only memory limits a text: Length is stated below Verada.Storage.Length_Bound (2⁶⁰), and making a longer text is Storage_Error, so no operation has a precondition on lengths. Concatenation allocates. To_String and Element give Latin-1 views and require Is_Latin_1; Wide_Element, Item and To_Wide_Wide_String take any text. The relational operators order texts by code point, as Python orders strings, and * repeats a text. Vibe's str is this type; Verada.Strings.Text_Operations has its methods.
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 Verada.Strings.Texts;import Verada.Strings.Texts;
A Vibe module imports this unit's names with from Verada.Strings.Texts 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
Text (declaration) — Copyable reclaimed immutable text, initially empty. Adjust/Finalize hooks retain and release shared character storage while preserving logical value semantics.
Declared interface:
type Text is private
with Default_Initial_Condition => Length (Text) = 0,
Finalizable => (Adjust => Share, Finalize => Release, Relaxed_Finalization => True);API 002
Length (declaration) — Observe the logical length/cardinality, not backing capacity or physical allocation size.
On normal return the declared contract establishes:
Length'Result < Verada.Storage.Length_BoundAPI 003
Reserve (declaration) — Room for a text of Count characters, as a result is about to be made: Storage_Error when memory cannot hold it. Replace and Join call it first, so that their result's length needs no precondition; the postcondition gives the bound for what follows.
On normal return the declared contract establishes:
procedure Reserve (Count : Long_Long_Long_Integer)
with Global => null, Always_Terminates,
Post => Count < Verada.Storage.Length_Bound;API 004
To_Wide_Wide_String (declaration) — The model: the text's code points, indexed from 1, each at most 16#10FFFF#. Contracts state a text's value through it.
On normal return the declared contract establishes:
To_Wide_Wide_String'Result'Length = Length (Source)
and then (To_Wide_Wide_String'Result'Length = 0 or else To_Wide_Wide_String'Result'First = 1)
and then (for all I in To_Wide_Wide_String'Result'Range => Wide_Wide_Character'Pos (To_Wide_Wide_String'Result (I)) <= 16#10FFFF#)API 005
Is_Latin_1 (declaration) — Whether every character is Latin-1, so that the text has a String: the precondition of To_String and Element.
API 006
To_String (declaration) — Materialize the family's logical text/image as String; consult bounds/content contracts rather than assuming a writable internal view.
Before this operation, establish:
Is_Latin_1 (Source)On normal return the declared contract establishes:
To_String'Result'Length = Length (Source)
and then (To_String'Result'Length = 0 or else To_String'Result'First = 1)
and then (for all I in To_String'Result'Range => Character'Pos (To_String'Result (I)) = Wide_Wide_Character'Pos (To_Wide_Wide_String (Source) (I)))API 007
To_Text (declaration) — Create a copyable Text holding the given String value.
On normal return the declared contract establishes:
Length (To_Text'Result) = Source'Length
and then Is_Latin_1 (To_Text'Result)
and then To_String (To_Text'Result) = SourceAPI 008
To_Text_Of (declaration) — Create a text holding the given code points.
Before this operation, establish:
(for all I in Source'Range => Wide_Wide_Character'Pos (Source (I)) <= 16#10FFFF#)On normal return the declared contract establishes:
Length (To_Text_Of'Result) = Source'Length
and then To_Wide_Wide_String (To_Text_Of'Result) = SourceAPI 009
Identical (declaration) — Whether two texts are the same text (the same characters, shared), not only equal ones. Share's postcondition states it, so that a proof takes an array of texts copied to be the array it was.
Ghost: for contracts and ghost code, and left out of the program.
API 010
"=" (declaration) — Equality in this declared value/model domain; the family defines whether sequence order, set membership, map pairs or logical text contents are compared.
On normal return the declared contract establishes:
"="'Result = (To_Wide_Wide_String (Left) = To_Wide_Wide_String (Right))API 011
"&" (declaration) — Concatenate Text values (Storage_Error when memory cannot hold the result).
On normal return the declared contract establishes:
Length ("&"'Result) = Length (Left) + Length (Right)
and then To_Wide_Wide_String ("&"'Result) = To_Wide_Wide_String (Left) & To_Wide_Wide_String (Right)
and then (if Is_Latin_1 (Left) and then Is_Latin_1 (Right)
then Is_Latin_1 ("&"'Result) and then To_String ("&"'Result) = To_String (Left) & To_String (Right))API 012
"<" (declaration) — Python's s < t: lexicographic order by code point, a proper prefix first, which is Ada's ordering of the models.
On normal return the declared contract establishes:
"<"'Result = (To_Wide_Wide_String (Left) < To_Wide_Wide_String (Right))API 013
"<=" (declaration) — Python's s <= t, in the same code-point order as "<".
On normal return the declared contract establishes:
"<="'Result = (To_Wide_Wide_String (Left) <= To_Wide_Wide_String (Right))API 014
">" (declaration) — Python's s > t, in the same code-point order as "<".
On normal return the declared contract establishes:
">"'Result = (To_Wide_Wide_String (Left) > To_Wide_Wide_String (Right))API 015
">=" (declaration) — Python's s >= t, in the same code-point order as "<".
On normal return the declared contract establishes:
">="'Result = (To_Wide_Wide_String (Left) >= To_Wide_Wide_String (Right))API 016
"*" (declaration) — Python's s * n: Left's characters Right times over, the empty text when Right is zero or negative.
On normal return the declared contract establishes:
Length ("*"'Result) = (if Right <= 0 then 0 else Length (Left) * Right)
and then (for all I in 1 .. Length ("*"'Result) =>
To_Wide_Wide_String ("*"'Result) (I) = To_Wide_Wide_String (Left) ((I - 1) mod Length (Left) + 1))API 017
"*" (declaration) — Python's s * n: Left's characters Right times over, the empty text when Right is zero or negative.
On normal return the declared contract establishes:
Length ("*"'Result) = (if Right <= 0 then 0 else Length (Left) * Right)
and then (for all I in 1 .. Length ("*"'Result) =>
To_Wide_Wide_String ("*"'Result) (I) = To_Wide_Wide_String (Left) ((I - 1) mod Length (Left) + 1))API 018
Item (declaration) — Python's s[i]: the text of the one character at Index (from 1).
Before this operation, establish:
Index <= Length (Source)On normal return the declared contract establishes:
Length (Item'Result) = 1
and then To_Wide_Wide_String (Item'Result) (1) = To_Wide_Wide_String (Source) (Index)API 019
Iter_First (declaration) — The first position of a for over a text's characters: 1.
Declared interface:
function Iter_First (Source : Text) return Natural is (1)
with Global => null;API 020
Iter_Next (declaration) — The position after Position.
Declared interface:
function Iter_Next (Source : Text; Position : Natural) return Natural is
(if Position < Natural'Last then Position + 1 else Position)
with Global => null;API 021
Iter_Has_Element (declaration) — Whether Position is one of the text's characters.
Declared interface:
function Iter_Has_Element (Source : Text; Position : Natural) return Boolean is
(Position in 1 .. Length (Source))
with Global => null;API 022
Iter_Element (declaration) — The character at Position, as a text of one.
Declared interface:
function Iter_Element (Source : Text; Position : Natural) return Text is
(Item (Source, Position))
with Global => null,
Pre => Iter_Has_Element (Source, Position);API 023
Element (declaration) — Read an existing logical element; the required index/cursor/presence condition is distinct from the index type's capacity bound.
Before this operation, establish:
Index <= Length (Source) and then Wide_Wide_Character'Pos (To_Wide_Wide_String (Source) (Index)) <= 255On normal return the declared contract establishes:
Character'Pos (Element'Result) = Wide_Wide_Character'Pos (To_Wide_Wide_String (Source) (Index))API 024
Wide_Element (declaration) — The character at Index, any code point.
Before this operation, establish:
Index <= Length (Source)On normal return the declared contract establishes:
Wide_Element'Result = To_Wide_Wide_String (Source) (Index)API 025
Put (declaration) — Write the text to standard output as UTF-8.
API 026
Share (declaration) — Adjust hook retaining an additional holder of immutable Text characters while preserving value; normal supported copying invokes the protocol.
On normal return the declared contract establishes:
Identical (X, X'Old)
and Length (X) = Length (X)'Old and To_Wide_Wide_String (X) = To_Wide_Wide_String (X)'OldAPI 027
Release (declaration) — Finalize/drop this Text holder and make it empty, freeing characters when the last holder leaves.
On normal return the declared contract establishes:
Length (X) = 0API 028
Put_Line (declaration) — Write the text to standard output as UTF-8, then end the line (Varc's println of a text writes it too).