DEVELOPMENT EDITION · 769442725406
Library Reference
Package Ada.Strings.UTF_Encoding.Wide_Wide_Strings
Verada predefined library: Ada.Strings.UTF_Encoding.Wide_Wide_Strings (Ada RM A.4.11): between Wide_Wide_String, a code point a character, and UTF-8, a byte a character. Both are proved. Encode needs code points (up to 16#10FFFF#). Decode reads each malformed sequence as U+FFFD, the replacement character, where Ada raises Encoding_Error. Only memory limits their lengths: Encode reserves room for its result first (Storage_Error when memory cannot hold it, Verada.Storage), so neither has a precondition on lengths.
Encode
function Encode (Item : Wide_Wide_String; Output_BOM : Boolean := False) return UTF_8_String
with Global => null,
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;each code point as its one to four bytes, after a byte-order mark when one is asked for
Decode
function Decode (Item : UTF_8_String) return Wide_Wide_String
with Global => null,
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#);the code points of UTF-8 text (a byte-order mark at its start is left out)