DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Ada.Strings.UTF_Encoding.Wide_Wide_Strings

Conversions between Wide_Wide_String (a code point a character) and UTF-8 (a byte a character), both proved. Decode reads each malformed sequence as U+FFFD, the replacement character, where Ada raises Encoding_Error.

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 client proof uses these contracts without proving the body again (see library assurance). The bodies are proved by Verada's own tests.

Import and instantiate

with Ada.Strings.UTF_Encoding.Wide_Wide_Strings;
import Ada.Strings.UTF_Encoding.Wide_Wide_Strings;

A Vibe module imports this unit's names with from Ada.Strings.UTF_Encoding.Wide_Wide_Strings import Name; see library use across syntaxes.

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

Encode (declaration) — Each code point as its one to four UTF-8 bytes, after a byte-order mark when one is asked for.

function Encode (Item : Wide_Wide_String; Output_BOM : Boolean := False) return UTF_8_String
  with Pre => (for all I in Item'Range => Wide_Wide_Character'Pos (Item (I)) <= 16#10FFFF#),
       Post => Encode'Result'First = 1
               and then Long_Long_Long_Integer (Encode'Result'Length) <= 4 * Long_Long_Long_Integer (Item'Length) + 3
               and then Encode'Result'Length < Verada.Storage.Length_Bound;

API 002

Decode (declaration) — The code points of UTF-8 text; a byte-order mark at its start is left out, and a malformed sequence becomes U+FFFD.

function Decode (Item : UTF_8_String) return Wide_Wide_String
  with Post => Decode'Result'First = 1 and then Decode'Result'Length <= Item'Length
               and then (for all I in Decode'Result'Range => Wide_Wide_Character'Pos (Decode'Result (I)) <= 16#10FFFF#);