comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Length of unbounded_string.
Date: Tue, 01 Nov 2011 11:22:14 -0700
Date: 2011-11-01T11:22:14-07:00	[thread overview]
Message-ID: <j8phh3$gj5$1@tornado.tornevall.net> (raw)
In-Reply-To: <4eafc489$0$3081$703f8584@textnews.kpn.nl>

On 11/01/2011 03:05 AM, ldries46 wrote:
> I finally have rewritten my routine continuation to try to make a work around .
> I believe that this has been succesfull.
> But The discrepancy between the display and the print facility with debugging
> stays as can be seen in the attachment. Also a strance behavior with the display
> of the character comma can be seen with lastch, that with an 'e' would have the
> output 109 'e' but for the comma gives 44 '
> I think I found a bug in the compiler so I will report this to AdaCore.

I don't see any evidence that this is a compiler error. It appears to be a 
debugger error.

17            nextlen := Length(Next_Line)	-- Next_Line is Global
18            ok1 := nextlen /= 0;

You seem to be missing a semicolon on line 17. Ok1 is never referenced.

You have two big if statements that are essentially

    if Condition then
       Do_This;
    else
       exit; -- Ok := True;
    end if;

which I would write

    exit when not Condition;

    Do_This;

The latter is clearer, especially given that small else parts tend to be 
overlooked after a large if part.

30                     while (nextch = ' ' or nextch = ASCII.HT) loop
31                        Replace_Slice(Next_Line, 1, 1, "");
32                        nextch := Element(Next_Line, 1);
33                     end loop;

Why do you use Replace_Slice with a null replacement rather than Delete?

If this loop reduces Next_Line to the null string, you'll get Constraint_Error 
from Element.

35                  str := To_Unbounded_String(Slice(str, 1, lenstr - 1));

Why do you use To_Unbounded_String (Slice (...) ) rather than Unbounded_Slice?

Cleaning this up, and removing everything not related to the processing, I came 
up with

procedure Continuation(Str : in out Unbounded_String; Nr : in out Integer) is
    Lenstr  : Integer;
    Nextlen : Integer;
    Lastch  : Character;
    Nextch  : Character;
begin
    All_Continuations : loop
       Lenstr := Length(Str);

       exit All_Continuations when Lenstr = 0;

       Lastch := Element(Str, Lenstr);
       Nextlen := Length(Next_Line);	-- Next_Line is Global

       exit All_Continuations when Lastch = ';' or Lastch = '{' or Lastch = '}' 
or Nextlen = 0;

       Nr := Nr + 1;

       Skip_Blanks : loop
       	Nextch := Element (Next_Line, 1);

         exit Skip_Blanks when Nextch /= ' ' and Nextch /= ASCII.HT;

         Delete (Source => Next_Line, From => 1, Through => 1);

         exit Skip_Blanks when Length (Next_Line) = 0;
       end loop Skip_Blanks;

       Str := Str & ' ' & Next_Line;
       -- I don't see any reason to slice the last character off and then
       -- concatenate it back on again.

       if Nr < Buffer1.Length - 1 then
          Next_Line := Buffer1.Get_Buffer( Nr + 1 );	-- Buffer1 is a global
       else
          Next_Line := Null_Unbounded_String;
       end if;
    end loop All_Continuations;
end Continuation;

-- 
Jeff Carter
"Sir Lancelot saves Sir Gallahad from almost certain temptation."
Monty Python & the Holy Grail
69



  parent reply	other threads:[~2011-11-01 18:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-25  9:37 Length of unbounded_string ldries46
2011-10-25 17:57 ` Jeffrey Carter
2011-10-28  2:54   ` ldries46
2011-10-28  4:55     ` Jeffrey Carter
2011-10-25 20:23 ` Vadim Godunko
2011-10-25 21:28   ` Simon Wright
2011-10-26  4:41     ` Simon Wright
2011-10-26 22:47     ` Randy Brukardt
2011-10-27  8:05       ` AdaMagica
2011-10-27  8:56       ` Simon Wright
2011-10-27 11:05         ` Brian Drummond
2011-10-28  3:12           ` ldries46
     [not found]           ` <4eafc489$0$3081$703f8584@textnews.kpn.nl>
2011-11-01 18:22             ` Jeffrey Carter [this message]
2011-10-27 11:28         ` Georg Bauhaus
2011-10-27 12:17           ` Dmitry A. Kazakov
2011-10-27 13:31             ` Georg Bauhaus
2011-10-27 14:34               ` Dmitry A. Kazakov
  -- strict thread matches above, loose matches on Subject: below --
2011-10-16  8:48 ldries46
2011-10-16  9:59 ` Niklas Holsti
2011-10-16 12:06   ` ldries46
2011-10-16 12:52   ` ldries46
2011-10-16 13:00     ` Niklas Holsti
2011-10-17  7:39       ` ldries46
2011-10-17 19:49         ` Niklas Holsti
2011-10-18 11:47           ` ldries46
2011-10-18 17:54             ` Niklas Holsti
2011-10-19  2:38               ` ldries46
2011-10-19  6:07                 ` Niklas Holsti
2011-10-24 15:10                   ` ldries46
2011-10-19  6:37                 ` Simon Wright
2011-10-19 14:48                 ` Alex Mentis
2011-10-24 17:04                   ` ldries46
2011-10-16 10:14 ` Vinzent Hoefler
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox