comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: determining input data type
Date: Sat, 18 Oct 2008 10:00:21 +0200
Date: 2008-10-18T10:00:21+02:00	[thread overview]
Message-ID: <qums3z5ubpnb.ee69jvdovdk8$.dlg@40tude.net> (raw)
In-Reply-To: 214384a8-9f78-4797-a194-457166456462@i18g2000prf.googlegroups.com

On Fri, 17 Oct 2008 23:53:54 -0700 (PDT), deadlyhead wrote:

> Using Ada.Integer_Text_IO.Get does some work for you, though.  For
> instance, if the user inputs 214yy0, it puts 214 in My_Int and
> continues on its way.  This may not be what you want, thus some actual
> text processing may be in order.

Yes, this was one of the motivations behind:

   http://www.dmitry-kazakov.de/ada/strings_edit.htm 

Your example reworked for Strings_Edit:

with Ada.Text_IO;            use Ada.Text_IO;
with Strings_Edit.Integers;  use Strings_Edit.Integers;

procedure Int_Test is
   My_Int : Integer;
begin
   Put ("Give me some input, and I will tell you if it is an integer:");
   My_Int := Value (Get_Line);
   Put_Line (Image (My_Int) & " is an integer!");
exception
   when Constraint_Error =>
      Put_Line ("That was a too large integer!");
   when End_Error =>
      Put_Line ("You entered nothing!");
   when Data_Error =>
      Put_Line ("That was not an integer!");
end Int_Test;

The function Value takes care to check the whole string for containing
integer and nothing but integer.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2008-10-18  8:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-18  0:48 determining input data type jedivaughn
2008-10-18  1:41 ` Jeffrey R. Carter
2008-10-18  6:17   ` Paul
2008-10-18  6:53 ` deadlyhead
2008-10-18  8:00   ` Dmitry A. Kazakov [this message]
2008-10-18 18:54 ` anon
2008-10-20 11:01   ` jedivaughn
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox