1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 | --
-- Copyright (C) 2020-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--
pragma Warnings (Off, "is an internal GNAT unit");
with Ada.Strings.Unbounded.Aux;
pragma Warnings (On, "is an internal GNAT unit");
package body VSS.Stream_Element_Vectors.Conversions is
-----------------------------
-- To_Stream_Element_Array --
-----------------------------
function To_Stream_Element_Array
(Item : Stream_Element_Vector'Class)
return Ada.Streams.Stream_Element_Array
is
use type Ada.Streams.Stream_Element_Offset;
begin
if Item.Data = null
or else Item.Data.Length = 0
then
return [0 .. -1 => <>];
else
return Item.Data.Storage (1 .. Item.Data.Length);
end if;
end To_Stream_Element_Array;
------------------------------
-- To_Stream_Element_Vector --
------------------------------
function To_Stream_Element_Vector
(Item : Ada.Streams.Stream_Element_Array) return Stream_Element_Vector is
begin
return Result : Stream_Element_Vector do
declare
Length : constant Ada.Streams.Stream_Element_Offset :=
Ada.Streams.Stream_Element_Offset (Item'Length);
begin
Result.Data :=
new Data_Record'
(Size => Length,
Length => Length,
Storage => Item);
end;
end return;
end To_Stream_Element_Vector;
-------------------------------------
-- Unchecked_From_Unbounded_String --
-------------------------------------
function Unchecked_From_Unbounded_String
(Item : Ada.Strings.Unbounded.Unbounded_String)
return Stream_Element_Vector
is
Source : Ada.Strings.Unbounded.Aux.Big_String_Access;
Source_Length : Natural;
begin
Ada.Strings.Unbounded.Aux.Get_String (Item, Source, Source_Length);
return Result : Stream_Element_Vector do
declare
Length : constant Ada.Streams.Stream_Element_Offset :=
Ada.Streams.Stream_Element_Offset (Source_Length);
subtype Bounded_Stream_Element_Array is
Ada.Streams.Stream_Element_Array (1 .. Length);
Aux : Bounded_Stream_Element_Array
with Address => Source.all'Address;
begin
Result.Data :=
new Data_Record'
(Size => Length,
Length => Length,
Storage => Aux);
end;
end return;
end Unchecked_From_Unbounded_String;
-------------------------
-- Unchecked_To_String --
-------------------------
function Unchecked_To_String
(Item : Stream_Element_Vector'Class) return String
is
use type Ada.Streams.Stream_Element_Offset;
begin
if Item.Data = null or else Item.Data.Length = 0 then
return "";
end if;
declare
Result : String (1 .. Natural (Item.Data.Length))
with Address => Item.Data.Storage (Item.Data.Storage'First)'Address;
begin
return Result;
end;
end Unchecked_To_String;
end VSS.Stream_Element_Vectors.Conversions;
|