comp.lang.ada
 help / color / mirror / Atom feed
From: John English <je@bton.ac.uk>
Subject: Re: Case Sensitivity
Date: 2000/05/12
Date: 2000-05-12T09:08:50+00:00	[thread overview]
Message-ID: <391BC9D0.F20E8D22@bton.ac.uk> (raw)
In-Reply-To: 958056490.47876@hearts.q-net.net.au

Cameron McShane wrote:
> We need a menu that needs to be case-'in'sensitive. I am using an enumerated
> data type for the 3 menu options ie:
> 
>     type Menu_Options is (buy, read, done)
> 
> If the user is to be allowed to enter Buy or BUY or bUy - etc, do I need to
> make the data type
> 
>     type Menu_Options is (buy, Buy, bUY, etc
> 
> or is there a way of converting user input to all lower case?

If you instantiate Ada.Text_IO.Enumeration_IO for your Menu_Options
type, the user will be able to enter any of the three names in any
case mixture and you will get back the corresponding Menu_Options
result. You will also be able to display the three values using
Put -- the default is all uppercase but you can also select output
in all lowercase. Enumeration_IO for input lets you forget about
case differences completely.

In other words, rather than reading a string, read a Menu_Options
value directly. If the user types anything other than one of your
three possible values, you'll get a Constraint_Error, so checking
for invalid input is simpler too.

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




  parent reply	other threads:[~2000-05-12  0:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-11  0:00 Case Sensitivity Cameron McShane
2000-05-11  0:00 ` Gautier
2000-05-11  0:00 ` Florian Weimer
2000-05-11  0:00 ` Alfred Hilscher
2000-05-11  0:00 ` Ted Dennison
2000-05-12  0:00 ` John English [this message]
2000-05-12  0:00   ` David C. Hoos, Sr.
2000-05-15  0:00     ` John English
  -- strict thread matches above, loose matches on Subject: below --
1993-07-04  9:12 case sensitivity Erik Magnuson
1993-07-02 15:53 Robert I. Eachus
1993-07-01 23:03 cis.ohio-state.edu!pacific.mps.ohio-state.edu!math.ohio-state.edu!darwin.
1989-02-20 19:45 pse_papay
1989-02-21  8:18 ` Bruce Anderson
1989-02-22 22:28 ` Steven D. Litvintchouk
1989-02-27 14:45 ` Dennis M. O'Connor
replies disabled

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