From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.13.220.132 with SMTP id f126mr13574256ywe.22.1449244168137; Fri, 04 Dec 2015 07:49:28 -0800 (PST) X-Received: by 10.182.104.163 with SMTP id gf3mr157254obb.5.1449244168095; Fri, 04 Dec 2015 07:49:28 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!b51no6404934qgf.0!news-out.google.com!f6ni16264igq.0!nntp.google.com!mv3no9194674igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 4 Dec 2015 07:49:28 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=194.154.216.90; posting-account=sDyr7QoAAAA7hiaifqt-gaKY2K7OZ8RQ NNTP-Posting-Host: 194.154.216.90 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Problem with Unbounded Strings From: Laurent Injection-Date: Fri, 04 Dec 2015 15:49:28 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:28631 Date: 2015-12-04T07:49:28-08:00 List-Id: Hi I have a problem with unbounded strings. When I append a String(1..10) to my Buffer which is an unbounded string it works. So my Buffer has the length 10. If I use this buffer of length 10 and append again a String(1..10) the length of the buffer should increase to 20 and I should have the content of both strings? Somehow in the procedure I have written that doesn't happen. The Buffer seems to get fixed to the length of the first string and further appending doesn't change it. The new string gets appended but truncated at its begin and the buffer at the end. I have no idea why that happens. I suppose something silly as always. There is no difference between using append or "&". The behaviour is the same. If someone could enlighten me I would be happy. Thanks Laurent package U_B renames Ada.Strings.Unbounded; subtype Ub_S is U_B.Unbounded_String; function "+" (Right : U_B.Unbounded_String) return String renames U_B.To_String; function "+" (Right : String) return U_B.Unbounded_String is (U_B.To_Unbounded_String (Right)); --------------- procedure Read_Message (File : in Ada.Text_IO.File_Type; Buffer : out Ub_S; Has_Finished : out Boolean) is begin -- Read_Message Has_Finished := False; Buffer := +""; while not Ada.Text_IO.End_Of_File (Log_File) loop declare S : String := Ada.Text_IO.Get_Line (File => File); Line : String (1 .. S'Length - TStamp); -- removes this useless timestamp begin -- declare Line (1 .. Line'Last) := S (38 .. S'Last); if Line (1 .. 5) = EOT then -- we have reached the end of the message so we can exit the loop -- and hand over the Buffer for treatment -- Has_Finished has to be set to True Has_Finished := True; exit; -- end of message elsif Line (1 .. 5) = ETX or Line (1 .. 5) = ACK or Line (1 .. 5) = ENQ or Line (1 .. 5) = STX or Line (1 .. 4) = GS -- if Line contains ETX, ACK, ENQ, STX or GS commands, -- we don't need them, so just ignore then null; elsif Line (1 .. 4) = RS then -- so Line contains RS command which indicates the begin of -- a message so we have to take care of those lines U_B.Append (Source => Buffer, New_Item => Line (5 .. Line'Last)); -- Buffer := U_B."&" (Buffer,Line ( 5 .. Line'Last)); else -- Line is something else, like some info about the succes of -- the backup engine. who cares? null; end if; end; end loop; end Read_Message;