2021-08-23 23:47:29 +00:00
|
|
|
with Ada.Finalization;
|
|
|
|
|
|
|
|
generic
|
2021-10-03 16:53:13 +00:00
|
|
|
--type Item_Type is private;
|
|
|
|
type Item_Type is (<>);
|
|
|
|
G_Terminator_Length: System_Zero_Or_One;
|
|
|
|
G_Terminator_Value: Item_Type;
|
2021-08-23 23:47:29 +00:00
|
|
|
package H3.Strings is
|
|
|
|
|
2021-10-03 16:53:13 +00:00
|
|
|
Terminator_Length: constant System_Zero_Or_One := G_Terminator_Length;
|
|
|
|
Terminator_Value: constant Item_Type := G_Terminator_Value;
|
|
|
|
|
2021-08-23 23:47:29 +00:00
|
|
|
type Elastic_String is private;
|
2021-10-03 16:53:13 +00:00
|
|
|
type Item_Array is array(System_Index range <>) of Item_Type;
|
|
|
|
--type Item_Array_Pointer is access all Item_Array;
|
2021-08-23 23:47:29 +00:00
|
|
|
|
2021-10-03 16:53:13 +00:00
|
|
|
subtype Thin_Item_Array is Item_Array(System_Index'Range);
|
|
|
|
type Thin_Item_Array_Pointer is access Thin_Item_Array;
|
2021-08-23 23:47:29 +00:00
|
|
|
|
2021-10-03 16:53:13 +00:00
|
|
|
function To_Item_Array (Str: in Elastic_String) return Item_Array;
|
2021-08-23 23:47:29 +00:00
|
|
|
|
|
|
|
function Get_Capacity (Str: in Elastic_String) return System_Size;
|
2021-08-24 16:07:29 +00:00
|
|
|
pragma Inline (Get_Capacity);
|
2021-08-23 23:47:29 +00:00
|
|
|
|
|
|
|
function Get_Length (Str: in Elastic_String) return System_Size;
|
2021-08-24 16:07:29 +00:00
|
|
|
pragma Inline (Get_Length);
|
2021-08-24 07:17:32 +00:00
|
|
|
|
2021-09-30 23:54:50 +00:00
|
|
|
-- the return type is System_Size for consistency with Get_Last_Index.
|
2021-08-24 07:17:32 +00:00
|
|
|
function Get_First_Index (Str: in Elastic_String) return System_Size;
|
2021-08-24 16:07:29 +00:00
|
|
|
pragma Inline (Get_First_Index);
|
2021-08-24 07:17:32 +00:00
|
|
|
|
2021-09-30 23:54:50 +00:00
|
|
|
-- the return type is System_Size because the Last index is -1 off the System_Index'First for an empty string
|
2021-08-24 07:17:32 +00:00
|
|
|
function Get_Last_Index (Str: in Elastic_String) return System_Size;
|
2021-08-24 16:07:29 +00:00
|
|
|
pragma Inline (Get_Last_index);
|
2021-08-23 23:47:29 +00:00
|
|
|
|
2021-10-03 16:53:13 +00:00
|
|
|
function Get_Item (Str: in Elastic_String; Pos: in System_Index) return Item_Type;
|
2021-08-24 16:07:29 +00:00
|
|
|
pragma Inline (Get_Item);
|
2021-08-23 23:47:29 +00:00
|
|
|
|
2021-08-24 07:17:32 +00:00
|
|
|
-- unsafe
|
2021-10-03 16:53:13 +00:00
|
|
|
function Get_Slot_Pointer (Str: in Elastic_String) return Thin_Item_Array_Pointer;
|
2021-08-24 16:07:29 +00:00
|
|
|
pragma Inline (Get_Slot_Pointer);
|
2021-08-23 23:47:29 +00:00
|
|
|
|
|
|
|
function Is_Shared(Str: in Elastic_String) return Standard.Boolean;
|
2021-08-24 16:07:29 +00:00
|
|
|
pragma Inline (Is_Shared);
|
2021-08-23 23:47:29 +00:00
|
|
|
|
2021-08-24 07:17:32 +00:00
|
|
|
procedure Clear (Str: in out Elastic_String);
|
2021-10-03 16:53:13 +00:00
|
|
|
procedure Purge (Str: in out Elastic_String); -- clear and reset the buffer to Empty_Buffer.
|
2021-08-23 23:47:29 +00:00
|
|
|
|
2021-10-03 16:53:13 +00:00
|
|
|
procedure Insert (Str: in out Elastic_String; Pos: in System_Index; V: in Item_Type; Repeat: in System_Size := 1);
|
|
|
|
procedure Insert (Str: in out Elastic_String; Pos: in System_Index; V: in Item_Array);
|
2021-10-03 15:38:31 +00:00
|
|
|
|
2021-10-03 16:53:13 +00:00
|
|
|
procedure Append (Str: in out Elastic_String; V: in Item_Type; Repeat: in System_Size := 1);
|
|
|
|
procedure Append (Str: in out Elastic_String; V: in Item_Array);
|
2021-08-23 23:47:29 +00:00
|
|
|
|
2021-10-03 16:53:13 +00:00
|
|
|
procedure Prepend (Str: in out Elastic_String; V: in Item_Type; Repeat: in System_Size := 1);
|
|
|
|
procedure Prepend (Str: in out Elastic_String; V: in Item_Array);
|
2021-10-03 15:38:31 +00:00
|
|
|
|
2021-10-03 16:53:13 +00:00
|
|
|
procedure Replace (Str: in out Elastic_String; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Type; Repeat: in System_Size := 1);
|
|
|
|
procedure Replace (Str: in out Elastic_String; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Array);
|
2021-10-03 15:38:31 +00:00
|
|
|
|
|
|
|
procedure Delete (Str: in out Elastic_String; From_Pos: in System_Index; To_Pos: in System_Size);
|
|
|
|
|
|
|
|
function "=" (Str: in Elastic_String; Str2: in Elastic_String) return Standard.Boolean;
|
2021-10-03 16:53:13 +00:00
|
|
|
function "=" (Str: in Elastic_String; Str2: in Item_Array) return Standard.Boolean;
|
2021-09-30 23:54:50 +00:00
|
|
|
|
2021-08-23 23:47:29 +00:00
|
|
|
private
|
2021-08-24 07:17:32 +00:00
|
|
|
type Buffer_Record(Capa: System_Size) is limited record
|
|
|
|
Refs: System_Size := 1;
|
2021-10-03 16:53:13 +00:00
|
|
|
Slot: Item_Array(1 .. Capa) := (others => Terminator_Value);
|
2021-08-23 23:47:29 +00:00
|
|
|
Last: System_Size := 0;
|
|
|
|
end record;
|
|
|
|
|
|
|
|
type Buffer_Pointer is access all Buffer_Record;
|
|
|
|
|
|
|
|
--Empty_Buffer: aliased Buffer_Record(1);
|
2021-10-03 16:53:13 +00:00
|
|
|
-- Use 1 slot to hold the terminator value regardless of th terminator length in Empty_Buffer.
|
|
|
|
Empty_Buffer: aliased Buffer_Record := (Capa => 1, Refs => 0, Slot => (1 => Terminator_Value), Last => 0);
|
2021-08-23 23:47:29 +00:00
|
|
|
|
|
|
|
type Elastic_String is new Ada.Finalization.Controlled with record
|
|
|
|
Buffer: Buffer_Pointer := Empty_Buffer'Access;
|
|
|
|
end record;
|
|
|
|
|
|
|
|
overriding procedure Initialize (Str: in out Elastic_String);
|
|
|
|
overriding procedure Adjust (Str: in out Elastic_String);
|
|
|
|
overriding procedure Finalize (Str: in out Elastic_String);
|
|
|
|
|
|
|
|
end H3.Strings;
|