poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PATCH: provide %c and %u8c formatting in pickle printf()


From: Henner Zeller
Subject: Re: PATCH: provide %c and %u8c formatting in pickle printf()
Date: Fri, 4 Oct 2019 23:27:17 -0700

On Fri, 4 Oct 2019 at 06:25, Jose E. Marchesi <address@hidden> wrote:
>
>
>     But that seems a bit overkill?  An alternative, probably more natural,
>     is to catch EOF around the loop, do the right thing, then re-raise:
>
>     try
>       THE_LOOP_INCLUDING_draw_ascii_line;
>     catch if E_eof
>     {
>       draw_ascii_line;
>       raise E_eof;
>     }
>
> Thinking about this... we have this in dump:
>
>  try print_data :offset offset :top top :step 16#B;
>  catch if E_eof { print "\n"; }
>
> If we make `offset' and `top' globals in print_data (as opposed to
> function arguments) then we could abstract the ascii printing into a
> print_ascii_line function, and call it in that catch:
>
>  try print_data :offset offset :top top :step 16#B;
>  catch if E_eof { print_ascii_line; print "\n"; }

Thinking a bit more about the problem, we can solve a lot of the
issues by not goig through the loop twice, but only once: while going
through the bytes, we print them out in hex but allso append the ASCII
representation to a string, byte by byte. Once the end is reached, we
just print the string with the collected ASCII representation. This
solves several problems

   o it makes the code more compact and readable; just one loop and a
final print
   o No complicated EOF catching per character, just at the very end,
we print the half-collected line at the end (essentially your version
above, but not a function call, but the collected ASCII)
   o it will probably also slightly easier to do the space-padding of
lines in normal cases of running out of bytes (the other class of
problems)

Does pickle support appending characters to a string ? Or maybe
address an character-array and set characters there.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]