122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
-
+
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
+
+
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
+
+
-
-
|
Last_Run_Size : constant Positive
:= Input_Length - (Run_Count - 1) * Largest_Run;
begin
return Ada.Streams.Stream_Element_Count (Run_Count - 1)
* (Tools.Image_Length (Largest_Run) + 1)
+ Tools.Image_Length (Last_Run_Size) + 1;
end;
elsif Input_Length mod 3 = 0 then
else
declare
Largest_Run : constant Positive := 64 * 3;
Run_Count : constant Positive
:= (Input_Length + Largest_Run - 1) / Largest_Run;
Last_Run_Size : constant Positive
:= Input_Length - (Run_Count - 1) * Largest_Run;
Largest_Prefix : constant Natural
:= (case Input_Length mod 3 is
when 1 => 15 * 3 + 1,
when 2 => ((62 - Natural (Last_Code)) * 4 - 1) * 3 + 2,
when others => 0);
begin
return Ada.Streams.Stream_Element_Count (Run_Count - 1)
* (Tools.Image_Length (Largest_Run) + 2)
Prefix_Header_Size : constant Ada.Streams.Stream_Element_Count
:= (if Largest_Prefix > 0 then 1 else 0);
+ Tools.Image_Length (Last_Run_Size) + 2;
end;
elsif Input_Length mod 3 = 1 then
declare
Largest_Final_Run : constant Positive := 15 * 3 + 1;
Largest_Prefix_Run : constant Positive := 64 * 3;
Prefix_Run_Count : constant Natural
Largest_Run : constant Positive := 64 * 3;
Prefix_Size : constant Natural
:= (Input_Length + Largest_Prefix_Run - Largest_Final_Run)
/ Largest_Prefix_Run;
Last_Run_Size : constant Positive
:= Input_Length - Prefix_Run_Count * Largest_Prefix_Run;
:= Natural'Min (Largest_Prefix, Input_Length);
Run_Count : constant Natural
:= (Input_Length - Prefix_Size + Largest_Run - 1) / Largest_Run;
begin
if Run_Count > 0 then
return Prefix_Header_Size + Tools.Image_Length (Prefix_Size)
return Ada.Streams.Stream_Element_Count (Prefix_Run_Count)
* (Tools.Image_Length (Largest_Prefix_Run) + 2)
+ Tools.Image_Length (Last_Run_Size) + 1;
+ Ada.Streams.Stream_Element_Count (Run_Count - 1)
* (Tools.Image_Length (Largest_Run) + 2)
+ Tools.Image_Length (Input_Length - Prefix_Size
end;
elsif Input_Length mod 3 = 2 then
declare
Largest_Final_Run : constant Positive
:= ((62 - Natural (Last_Code)) * 4 - 1) * 3 + 2;
- (Run_Count - 1) * Largest_Run)
+ 2;
Largest_Prefix_Run : constant Positive := 64 * 3;
Prefix_Run_Count : constant Natural
:= (Input_Length + Largest_Prefix_Run - Largest_Final_Run)
/ Largest_Prefix_Run;
Last_Run_Size : constant Positive
:= Input_Length - Prefix_Run_Count * Largest_Prefix_Run;
begin
else
return Ada.Streams.Stream_Element_Count (Prefix_Run_Count)
* (Tools.Image_Length (Largest_Prefix_Run) + 2)
+ Tools.Image_Length (Last_Run_Size) + 1;
return Prefix_Header_Size + Tools.Image_Length (Prefix_Size);
end if;
end;
else
raise Program_Error with "Condition unreachable";
end if;
end Verbatim_Size;
procedure Write_Code
(Output : in out Ada.Streams.Stream_Element_Array;
Offset : in out Ada.Streams.Stream_Element_Offset;
|