From: Laurent <lutgenl@icloud.com>
Subject: Problem with Unbounded Strings
Date: Fri, 4 Dec 2015 07:49:28 -0800 (PST)
Date: 2015-12-04T07:49:28-08:00 [thread overview]
Message-ID: <e28c35a7-5f41-4beb-afb3-eb4fc9da9384@googlegroups.com> (raw)
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;
next reply other threads:[~2015-12-04 15:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-04 15:49 Laurent [this message]
2015-12-04 16:04 ` Problem with Unbounded Strings Dmitry A. Kazakov
2015-12-04 16:53 ` Laurent
2015-12-04 18:00 ` Niklas Holsti
2015-12-04 21:05 ` Laurent
2015-12-04 20:34 ` Dmitry A. Kazakov
2015-12-04 21:43 ` Laurent
2015-12-04 22:23 ` Dmitry A. Kazakov
2015-12-05 10:22 ` Laurent
2015-12-05 12:19 ` Dmitry A. Kazakov
2015-12-05 13:15 ` Laurent
2015-12-04 18:08 ` Jeffrey R. Carter
2015-12-04 21:21 ` Laurent
2015-12-04 21:59 ` Simon Wright
2015-12-04 23:19 ` Laurent
2015-12-04 22:02 ` Dmitry A. Kazakov
2015-12-04 22:28 ` Jeffrey R. Carter
2015-12-04 23:35 ` Laurent
2015-12-04 23:59 ` Jeffrey R. Carter
2015-12-05 10:13 ` Laurent
2015-12-08 1:53 ` Randy Brukardt
2015-12-04 23:00 ` Ben Bacarisse
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox