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.66.153.78 with SMTP id ve14mr15410029pab.44.1449264116221; Fri, 04 Dec 2015 13:21:56 -0800 (PST) X-Received: by 10.182.241.195 with SMTP id wk3mr181745obc.8.1449264116185; Fri, 04 Dec 2015 13:21:56 -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!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!mv3no11664099igc.0!news-out.google.com!l1ni81igd.0!nntp.google.com!mv3no11664092igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 4 Dec 2015 13:21:55 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=83.99.95.2; posting-account=sDyr7QoAAAA7hiaifqt-gaKY2K7OZ8RQ NNTP-Posting-Host: 83.99.95.2 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <274dc49b-b7cd-4eef-b333-34bae665c992@googlegroups.com> Subject: Re: Problem with Unbounded Strings From: Laurent Injection-Date: Fri, 04 Dec 2015 21:21:56 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:28643 Date: 2015-12-04T13:21:55-08:00 List-Id: On Friday, 4 December 2015 19:08:11 UTC+1, Jeffrey R. Carter wrote: > I would ignore Kazakov's comments. While he prefers to avoid unbounded st= rings, > many others don't, so if the characteristics of Unbounded_String are suit= able > for your project there is no reason not to use them. >=20 > You can't use a case statement because you're comparing strings, and case > statements can only be used for discrete types. >=20 > On 12/04/2015 08:49 AM, Laurent wrote: > > procedure Read_Message (File : in Ada.Text_IO.File_Type; > > ... > > while not Ada.Text_IO.End_Of_File (Log_File) loop >=20 > What is Log_File? >=20 > > U_B.Append (Source =3D> Buffer, > > New_Item =3D> Line (5 .. Line'Last)); >=20 > I see nothing wrong with this use of append. If it's possible that 5 > Li= ne'Last > then you would be appending a null string, which would not change the val= ue of > Buffer. It would be nice if you could reduce your example to eliminate th= e > irrelevant parts and provide some input and corresponding output (and exp= ected > output) that demonstrates your problem. Otherwise I'm unable to to offer = any > advice. Certainly I've made extensive use of Unbounded_String and never > encountered any problem with Append, so you probably have a logic problem= . Ok I have reduced the whole thing to the minimum and still get the same beh= aviour + an additional glitch The Log_File I have reduced it to the minimum too: 0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ I expect my code to do this: 1st read: 0123456789 append to the buffer which is empty so content of buffer is: 0123456789 2nd read: abcdefghijklmnopqrstuvwxyz append to buffer so it becomes: 0123456789abcdefghijklmnopqrstuvwxyz 3rd read: ABCDEFGHIJKLMNOPQRSTUVWXYZ append to buffer so it would be: 0123456789abcdefghijklmnopqrstuvwxyzABCDEF= GHIJKLMNOPQRSTUVWXYZ But I get this: 1st read: Line: 0123456789 Buffer after append: 0123456789 2nd read: Line: abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz56789 3rd read: Line: ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ56789 I first thought that I could have inverted source and new_item. But there a= re only 2 appends in Unbound_String. One which accepts only Unbound_Strings= and one where source:Unbound_String and New_Item: String. So I can't inver= se them, the compiler would complain. But the output looks a bit like inver= ted. So no idea. And as a bonus after the first loop=20 Ada.Text_IO.Put_Line ("Buffer after append: " & (+Buffer)); does no longer = print the "Buffer after append: " part. No idea why. So the reduced code which compiles.=20 with Ada.Text_IO; with Ada.Strings.Unbounded; procedure Test_UB is =20 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)); Log_File : Ada.Text_IO.File_Type; Message_Buf : Ub_S; ------------------ -- Read_Message -- ------------------ procedure Read_Message (File : in Ada.Text_IO.File_Type; Buffer : out Ub_S) is begin -- Read_Message while not Ada.Text_IO.End_Of_File (File) loop declare Line : String :=3D Ada.Text_IO.Get_Line (File =3D> File); begin -- declare Ada.Text_IO.Put_Line ("Line: " & Line); U_B.Append (Source =3D> Buffer, New_Item =3D> Line); Ada.Text_IO.Put_Line ("Buffer after append: " & (+Buffer)); Ada.Text_IO.New_Line; =20 end; end loop; end Read_Message; begin -- Main Ada.Text_IO.Open (File =3D> Log_File, Mode =3D> Ada.Text_IO.In_File, Name =3D> "Test.log"); Read_Message (File =3D> Log_File, Buffer =3D> Message_Buf); Ada.Text_IO.Close (File =3D> Log_File); end Test_UB;