comp.lang.ada
 help / color / mirror / Atom feed
* How to do case conversion?
@ 1996-08-10  0:00 Mike Shen
  1996-08-11  0:00 ` David C. Hoos, Sr.
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Mike Shen @ 1996-08-10  0:00 UTC (permalink / raw)



I am trying to do case conversion in GNAT. Does anyone
know a simple way to do it? I expected the Ada.Strings(.Maps)
package to provide something for my purpose, but it doesn't.

Thanks in advance.

-Mike Shen




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to do case conversion?
  1996-08-10  0:00 How to do case conversion? Mike Shen
  1996-08-11  0:00 ` David C. Hoos, Sr.
@ 1996-08-11  0:00 ` Robert Dewar
  1996-08-12  0:00   ` Robert A Duff
  1996-08-13  0:00   ` Jon S Anthony
  1996-08-13  0:00 ` Robert I. Eachus
  2 siblings, 2 replies; 8+ messages in thread
From: Robert Dewar @ 1996-08-11  0:00 UTC (permalink / raw)



Mike Shen said

"I am trying to do case conversion in GNAT. Does anyone
know a simple way to do it? I expected the Ada.Strings(.Maps)
package to provide something for my purpose, but it doesn't."

Well this is an Ada 95 question, not a GNAT question. The standard
library routine Ada.Strings.Maps.Constants has exactly what you need,
and what you might consider is how next time you can find that more
easily than having to wait for someone to reply to you on a newsgroup.
A simple method I find useful (you can obviously do better with fancy
tools) is simply to grab a copy of the ASCII version of the RM, and 
search it with your favorite editor.

I happened to know the answer to that question off the top of my head,
but if I had not, I would have searched for Lower_Case, and found the
reference in the RM almost immediately.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to do case conversion?
  1996-08-10  0:00 How to do case conversion? Mike Shen
@ 1996-08-11  0:00 ` David C. Hoos, Sr.
  1996-08-11  0:00   ` Robert Dewar
  1996-08-11  0:00 ` Robert Dewar
  1996-08-13  0:00 ` Robert I. Eachus
  2 siblings, 1 reply; 8+ messages in thread
From: David C. Hoos, Sr. @ 1996-08-11  0:00 UTC (permalink / raw)



Hi Mike,
The standard package Ada.Characters.Handling has subprograms To_Lower, and
To_Upper, for both characters and strings.
Hope this helps 
David C. Hoos, Sr.,
http://www.dbhwww.com
http://www.ada95.com

Mike Shen <mshen+@cs.cmu.edu> wrote in article
<320D5A34.41C67EA6@cs.cmu.edu>...
> I am trying to do case conversion in GNAT. Does anyone
> know a simple way to do it? I expected the Ada.Strings(.Maps)
> package to provide something for my purpose, but it doesn't.
> 
> Thanks in advance.
> 
> -Mike Shen
> 




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to do case conversion?
  1996-08-11  0:00 ` David C. Hoos, Sr.
@ 1996-08-11  0:00   ` Robert Dewar
  0 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1996-08-11  0:00 UTC (permalink / raw)



David Hoos points out that Ada.Characters.Handling contains ready made
routines that use the maps in Ada.Strings.Maps.Constants, and yes, you
may as well use them if they fit. The coding is quite trivial:

   function To_Lower (Item : in Character) return Character is
   begin
      return Value (Lower_Case_Map, Item);
   end To_Lower;

   function To_Lower (Item : in String) return String is
      Result : String (1 .. Item'Length);

   begin
      for J in Item'Range loop
         Result (J - (Item'First - 1)) := Value (Lower_Case_Map, Item (J));
      end loop;

      return Result;
   end To_Lower;

It is Lower_Case_Map that is the difficult part! Note that in Ada 95 days
it is better if you can to always use this map rather than the old 
add/subtract 32 ASCII trick, since that way your code work fine for
all Latin-1 letters without any extra effort on your part, and indeed
in an implementation with localizations of these packages for other
Latin sets, your code will still work.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to do case conversion?
  1996-08-11  0:00 ` Robert Dewar
@ 1996-08-12  0:00   ` Robert A Duff
  1996-08-13  0:00   ` Jon S Anthony
  1 sibling, 0 replies; 8+ messages in thread
From: Robert A Duff @ 1996-08-12  0:00 UTC (permalink / raw)



In article <dewar.839779145@schonberg>, Robert Dewar <dewar@cs.nyu.edu> wrote:
>tools) is simply to grab a copy of the ASCII version of the RM, and 
>search it with your favorite editor.

Yeah, I do that a lot, too.  It's available online at
sw-eng.falls-church.va.us via anonymous FTP in directory
public/adaic/docs/standard/95lrm_rat/v6.0.

Also, the index is pretty complete, in case you only have paper copy.

- Bob





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to do case conversion?
  1996-08-13  0:00 ` Robert I. Eachus
@ 1996-08-13  0:00   ` Robert Dewar
  0 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1996-08-13  0:00 UTC (permalink / raw)



Eachus said


"    The multilingual problems can arise either due to use of say
Latin2, or be more subtle.  For instance, the correct upper/lower case
mapping for e-acute in French is locale specific."

What on earth do you mean by this last phrase. The upper case in French
for lower case e-acute is upper case e-acute.

Now it is true that if you want to emulate the output if technically
incompetent typewriters that have no upper case E acute, then you may
want to print out the upper case E acute as an ordinary E, but that's
a different issue from the casing issue.

Besides this seems unlikely, If you print out upper case E acute, then
either the output device you are speaking to is capable of proper French
output and has this character, or it is a decrepit device lacking this
character, in which case you would expect upper case E acute to print
as upper case E anyway.

P.S. there is a common myth, particularly in France, that French does not
permit accents on upper case letters. This is incorrect, it derives from
the fact that early typewriters were incapable of proper accent output
for upper case letters.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to do case conversion?
  1996-08-11  0:00 ` Robert Dewar
  1996-08-12  0:00   ` Robert A Duff
@ 1996-08-13  0:00   ` Jon S Anthony
  1 sibling, 0 replies; 8+ messages in thread
From: Jon S Anthony @ 1996-08-13  0:00 UTC (permalink / raw)



In article <Dw15ty.Hz5@world.std.com> bobduff@world.std.com (Robert A Duff) writes:

> Also, the index is pretty complete, in case you only have paper copy.
> 
> - Bob

The index is rather amazing!  Thanks Bob!

/Jon
-- 
Jon Anthony
Organon Motives, Inc.
1 Williston Road, Suite 4
Belmont, MA 02178

617.484.3383
jsa@organon.com





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to do case conversion?
  1996-08-10  0:00 How to do case conversion? Mike Shen
  1996-08-11  0:00 ` David C. Hoos, Sr.
  1996-08-11  0:00 ` Robert Dewar
@ 1996-08-13  0:00 ` Robert I. Eachus
  1996-08-13  0:00   ` Robert Dewar
  2 siblings, 1 reply; 8+ messages in thread
From: Robert I. Eachus @ 1996-08-13  0:00 UTC (permalink / raw)



In article <320D5A34.41C67EA6@cs.cmu.edu> Mike Shen <mshen+@cs.cmu.edu> writes:

  > I am trying to do case conversion in GNAT. Does anyone
  > know a simple way to do it? I expected the Ada.Strings(.Maps)
  > package to provide something for my purpose, but it doesn't.

    Others have posted the right place to look.  However, if you are
dealing with multi-lingual or non-Latin1 text be warned.

    The "correct" mapping for ISO Latin 1, which is what you should
get, may not be what you want.  In particular PC-Compatible machines,
Macintoshes, and Unix machines do not use Latin1 by default.  (The
Amiga I am typing this on does. ;-)

    The multilingual problems can arise either due to use of say
Latin2, or be more subtle.  For instance, the correct upper/lower case
mapping for e-acute in French is locale specific.

    All this is why the facilities for making your own maps are there.

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1996-08-13  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-10  0:00 How to do case conversion? Mike Shen
1996-08-11  0:00 ` David C. Hoos, Sr.
1996-08-11  0:00   ` Robert Dewar
1996-08-11  0:00 ` Robert Dewar
1996-08-12  0:00   ` Robert A Duff
1996-08-13  0:00   ` Jon S Anthony
1996-08-13  0:00 ` Robert I. Eachus
1996-08-13  0:00   ` Robert Dewar

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