Strings.IntToStringForm: convert a number to Oberon format

Strings.IntToStringForm: convert a number to Oberon format

Postby Zorko » Mon Sep 13, 2021 5:38 pm

I propose to increase the functionality of the procedure Strings.IntToStringForm.

There is an input parameter MinWidth, which is responsible for the minimum number of output characters of a converted number. Any the number can take up one or more characters. But still, ASSERT inside this procedure also allows the value of MinWidth = 0

Code: Select all
      ASSERT(minWidth >= 0, 22);

Here, when MinWidth = 0, nothing terrible happens, but it will be the same as 1.

I was recently forced to write such code:

Code: Select all
   PROCEDURE WriteHex(i: INTEGER);
      VAR minWidth: INTEGER;
   BEGIN
      IF i > 9FFFH THEN minWidth := 5
      ELSIF i > 9FFH THEN minWidth := 4
      ELSIF i > 9FH THEN minWidth := 3
      ELSIF i > 9H THEN minWidth := 2
      ELSE minWidth := 1
      END;
      W.WriteIntForm(i, TextMappers.hexadecimal, minWidth, "0", FALSE)
   END WriteHex;

This procedure outputs a hexadecimal value in the Oberon format, i.e. if a hexadecimal literal starts with a letter, it is preceded by an insignificant zero.

And this behavior can be demanded quite often, so I suggest that with MinWidth = 0, implement exactly this behavior as encoded in my procedure: a hexadecimal number with an insignificant zero is output if this number starts with a letter. What do you think, colleagues?
Zorko
 
Posts: 23
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine

Re: Strings.IntToStringForm: convert a number to Oberon form

Postby Zinn » Fri Sep 17, 2021 6:06 pm

Sorry I don't understand your problem. You can optimize your procedure to

Code: Select all
  PROCEDURE WriteHex(i: INTEGER);
      VAR minWidth: INTEGER;
   BEGIN
      minWidth := 1;
      W.WriteIntForm(i, TextMappers.hexadecimal, minWidth, "0", FALSE)
   END WriteHex;

and have the same behaviour.
- Helmut
Zinn
 
Posts: 111
Joined: Mon Nov 24, 2014 10:47 am
Location: Frankfurt am Main


Return to Feature

Who is online

Users browsing this forum: No registered users and 1 guest

cron