Natools

Check-in [f1e8b35069]
Login
Overview
Comment:s_expressions-printers-pretty: fix width handling in hexadecimal and base-64 atom encodings
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f1e8b3506931472b3da71a02217cebc5c5649eb0
User & Date: nat on 2014-01-29 21:08:01
Other Links: manifest | tags
Context
2014-01-30
20:53
s_expressions-printers-pretty-tests: new test for quoted string escape sequences check-in: e499a522b3 user: nat tags: trunk
2014-01-29
21:08
s_expressions-printers-pretty: fix width handling in hexadecimal and base-64 atom encodings check-in: f1e8b35069 user: nat tags: trunk
2014-01-28
19:40
s_expressions-printers-pretty-tests: add test for output width in hexadecimal and base-64 atom encodings check-in: ed46bbdd62 user: nat tags: trunk
Changes

Modified src/natools-s_expressions-printers-pretty.adb from [df34c00cc5] to [c7513de8cf].

466
467
468
469
470
471
472
473
474


475
476
477
478




479
480
481

482
483
484
485
486
487
488
466
467
468
469
470
471
472


473
474
475



476
477
478
479
480
481

482
483
484
485
486
487
488
489







-
-
+
+

-
-
-
+
+
+
+


-
+







         Output.Stream.Write (Encodings.Encode_Base64 (Data));
         Output.Stream.Write ((0 => Encodings.Base64_Atom_End));
      else
         Output.Stream.Write ((0 => Encodings.Base64_Atom_Begin));
         Output.Cursor := Output.Cursor + 1;

         loop
            Available := Output.Param.Width - Output.Cursor;
            Chunk_Size := Count (Available) / 4 * 3;
            Available := Output.Param.Width + 1 - Output.Cursor;
            Chunk_Size := Count'Max (1, Count (Available) / 4) * 3;

            if Available mod 4 /= 0 then
               Output.Stream.Write ((0 => Encodings.Space));
               Output.Cursor := Output.Cursor + 1;
            if Available mod 4 /= 0 and then I in Data'Range then
               Output.Stream.Write
                 ((1 .. Count (Available mod 4) => Encodings.Space));
               Output.Cursor := Output.Cursor + (Available mod 4);
            end if;

            if I + Chunk_Size in Data'Range then
            if I + Chunk_Size - 1 in Data'Range then
               Output.Stream.Write (Encodings.Encode_Base64
                                      (Data (I .. I + Chunk_Size - 1)));
               Newline (Output);
               I := I + Chunk_Size;
            else
               Output.Stream.Write (Encodings.Encode_Base64
                                      (Data (I .. Data'Last)));
507
508
509
510
511
512
513
514
515


516
517

518
519
520
521
522

523
524
525
526
527
528
529
508
509
510
511
512
513
514


515
516
517

518
519
520
521
522

523
524
525
526
527
528
529
530







-
-
+
+

-
+




-
+







                                                    Output.Param.Hex_Casing));
         Output.Stream.Write ((0 => Encodings.Hex_Atom_End));
      else
         Output.Stream.Write ((0 => Encodings.Hex_Atom_Begin));
         Output.Cursor := Output.Cursor + 1;

         loop
            Available := Output.Param.Width - Output.Cursor;
            Chunk_Size := Count (Available) / 2;
            Available := Output.Param.Width + 1 - Output.Cursor;
            Chunk_Size := Count'Max (1, Count (Available) / 2);

            if Available mod 2 = 1 then
            if Available mod 2 = 1 and then I in Data'Range then
               Output.Stream.Write ((0 => Encodings.Space));
               Output.Cursor := Output.Cursor + 1;
            end if;

            if I + Chunk_Size in Data'Range then
            if I + Chunk_Size - 1 in Data'Range then
               Output.Stream.Write (Encodings.Encode_Hex
                                      (Data (I .. I + Chunk_Size - 1),
                                       Output.Param.Hex_Casing));
               Newline (Output);
               I := I + Chunk_Size;
            else
               Output.Stream.Write (Encodings.Encode_Hex