--  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.
with Verada.Storage;

package Ada.Strings.UTF_Encoding.Wide_Wide_Strings
  with Pure
is
   --  each code point as its one to four 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 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;

   --  the code points of UTF-8 text (a byte-order mark at its start is left out)
   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#);
end Ada.Strings.UTF_Encoding.Wide_Wide_Strings;
