From: mheaney@ni.net (Matthew Heaney)
Subject: Re: [Q] Returning Strings From A Function
Date: 1997/04/06
Date: 1997-04-06T00:00:00+00:00 [thread overview]
Message-ID: <mheaney-ya023680000604972151220001@news.ni.net> (raw)
In-Reply-To: 33478738.2129057@news.demon.co.uk
In article <33478738.2129057@news.demon.co.uk>, john@assen.demon.co.uk
(John McCabe) wrote:
>
>>John, it is still very difficult to understand what you are asking for.
>>Your code above makes perfect sense if you want File_Name to be 12 characters
>>long, and of course the assignment will check for 12 characters.
>
>Exactly - but I want the assignment to check for <=12 characters.
In Ada 83, you can just assign the function return value to a (constant)
object, and then do whatever you want with it (including assigning it to a
fixed-length string). For example,
subtype Name_String is String (1 .. 12);
procedure Get_Name (Name : out Name_String) is
The_Name : constant String := Text_IO.Name (The_File);
Pad_Length : constant Natural := Name'Length - The_Name'Length;
Pad : constant String (1 .. Pad_Length) := (others => ' ');
begin
Name := The_Name & Pad;
end;
A hipper technique is to use a string buffer, as follows:
subtype Name_Length_Range is Natural range 0 .. 12;
type Name_Buffer (Length : Name_Length_Range := 0) is
record
Name : String (1 .. Length);
end record;
procedure Get_Name (Name : out Name_Buffer) is
The_Name : constant String := Text_IO.Name (The_File);
begin
Name := (The_Name'Length, The_Name);
end;
Hope that helps,
Matt
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271
next prev parent reply other threads:[~1997-04-06 0:00 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-04-04 0:00 [Q] Returning Strings From A Function John McCabe
1997-04-04 0:00 ` Joakim Olsson
1997-04-05 0:00 ` John McCabe
1997-04-05 0:00 ` Robert A Duff
1997-04-05 0:00 ` Robert Dewar
1997-04-06 0:00 ` John McCabe
1997-04-06 0:00 ` Robert Dewar
1997-04-06 0:00 ` Nick Roberts
1997-04-07 0:00 ` Robert A Duff
1997-04-08 0:00 ` Nick Roberts
1997-04-07 0:00 ` Matthew Heaney
1997-04-06 0:00 ` Matthew Heaney [this message]
1997-04-05 0:00 ` johnherro
1997-04-05 0:00 ` Mark & Zurima McKinney
1997-04-07 0:00 ` johnherro
1997-04-07 0:00 ` Robert Dewar
1997-04-07 0:00 ` Jon S Anthony
1997-04-07 0:00 ` johnherro
1997-04-08 0:00 ` Jeff Carter
1997-04-09 0:00 ` Looking for an Ada SCIENTIFIC UNITS checking package Ron House
1997-04-05 0:00 ` [Q] Returning Strings From A Function Robert Dewar
1997-04-06 0:00 ` John McCabe
1997-04-06 0:00 ` Robert Dewar
1997-04-06 0:00 ` John McCabe
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox