Natools

Check-in [c49fad3790]
Login
Overview
Comment:smaz_implementations-base_64: fix multi-block verbatim size computation
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c49fad3790f41bc2a2d9f0a03a2ccec5b0b20c9d
User & Date: nat on 2017-01-01 21:43:54
Other Links: manifest | tags
Context
2017-01-02
20:22
smaz_tests: ASCIIfy the base-64 dictionary, to make it more portable check-in: 8f0534e6a4 user: nat tags: trunk
2017-01-01
21:43
smaz_implementations-base_64: fix multi-block verbatim size computation check-in: c49fad3790 user: nat tags: trunk
2016-12-31
16:57
smaz_tests: add a check to show a bug in long verbatim size computation check-in: 4f0ae7072f user: nat tags: trunk
Changes

Modified src/natools-smaz_implementations-base_64.adb from [106572d0cd] to [1a162cf272].

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;