From: Sébastien <seb.morand@gmail.com>
Subject: Re: String declaration and initialization
Date: Thu, 22 May 2008 16:58:51 +0000
Date: 2008-05-22T16:58:51+00:00 [thread overview]
Message-ID: <g148oh$mcd$1@registered.motzarella.org> (raw)
In-Reply-To:
> The simplest way is to use a bounded or unbounded string:
>
> declare
> S : Unbounded_String;
> begin
> case Some_Test is
> when T1 => S := To_Unbounded_String ("test1");
> ...
> end;
Yep I think about it but in this case, I made several conversions
because I have stuff like that:
buffer := To_Unbouned_String(Trim(Integer'Image(my_int), Left));
And then treatment use String so:
MyTreatment(To_String(buffer));
So I don't actually know how fast is the conversion between String and
Unbounded_String but I think it's a waste of ressource.
> Another way is to use a table like you can in C:
>
> declare
> Test1 : aliased constant String := "test1";
> Test2 : aliased constant String := "test2";
>
> type Table_Type is array (Test_Type) of
> not null access constant String;
>
> Table : constant Table_Type :=
> (T1 => Test1'Access,
> T2 => Test2'Access,
> ...);
>
> S : String renames Table (Some_Test).all;
> begin
> ...
> end;
That's an idea but... Test1 are actually not a constant string, that was
an example :-) It's calculated sometime it's even a return of some
function and so on.
But you give me an Idea :
declare
buffer: access String;
Free_String is new Unchecked_Deallocation(String, access all String);
begin
case SomeTest is
case TEST1 =>
buffer := new String("Test1");
case TEST2 =>
buffer := new String("Test2");
end case;
MyTreatment1(buffer.all, buffer.all'Size);
MyTreatment2(buffer.all, buffer.all'Size);
MyTreatment3(buffer.all, buffer.all'Size);
end;
but it doesn't work of course since I can't create with new an
unconstrained object.
next prev parent reply other threads:[~2008-05-22 16:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-22 15:47 String declaration and initialization Sébastien
2008-05-22 16:05 ` Dmitry A. Kazakov
2008-05-22 16:47 ` Sébastien
2008-05-23 8:18 ` Dmitry A. Kazakov
2008-05-23 9:33 ` Sébastien
2008-05-22 16:16 ` Matthew Heaney
2008-05-22 16:58 ` Sébastien [this message]
2008-05-22 17:11 ` Robert A Duff
2008-05-22 18:16 ` Matthew Heaney
2008-05-22 20:01 ` Jeffrey R. Carter
2008-05-22 16:40 ` Jean-Pierre Rosen
2008-05-22 18:09 ` Martin Krischik
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox