comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison <dennison@telepath.com>
Subject: Re: Case Sensitivity
Date: 2000/05/11
Date: 2000-05-11T00:00:00+00:00	[thread overview]
Message-ID: <8fekov$7pk$1@nnrp1.deja.com> (raw)
In-Reply-To: 958056490.47876@hearts.q-net.net.au

In article <958056490.47876@hearts.q-net.net.au>,
  "Cameron McShane" <cazza@aceonline.com.au> wrote:
> Hey
>
> I am doing a project for Uni, and am a bit stuck.
>
> 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?

Yes.

In the Latin_1 character collating sequence, it just so happens that the
characters 'a' through 'z' all have the same relative position to each
other as the characters 'A' through 'Z'. The lower-case letters have a
larger value than the upper case letters. (See Ada.Characters.Latin_1)
So the traditional manual way to do this would be to find the difference
in the integer position of an upper case character from that of its
lower-case counterpart (eg: 'A' and 'a'). Then you can add that
difference to the integer position of every upper-case letter you
encounter. Then you just need to find the character value for that
resulting integer position. There are predefined attributes that you can
apply to characters to convert between their character value and their
integer position. (This reads pretty complicated, but the code's really
very simple).

But you don't have to do this manually (unless your teacher wants you
to). Take out your handy-dandy Ada LRM (if you don't have one, there's
one online at http://www.adapower.com ) and look through the routines in
the standard Ada library in Appendix A. There are a couple of sets of
packages in there that provide useful routines for doing this kind of
thing. There are packages for doing lots of other neat stuff too, so be
sure to look through them all.

While you're at it, do yourself a favor and read through appendix K
(Language Defined Attributes). There's lots of vital stuff in there to
make your life easier.

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




  parent reply	other threads:[~2000-05-11  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 ` Florian Weimer
2000-05-11  0:00 ` Gautier
2000-05-11  0:00 ` Alfred Hilscher
2000-05-11  0:00 ` Ted Dennison [this message]
2000-05-12  0:00 ` John English
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