Topic: creating a case-insensitive string class
Author: "Simon Harris" <simon@addease.com.au>
Date: 1996/08/15 Raw View
First off, please excuse me if I've posted to an inppropriate group. Let me
know and I'll stop. OK now down to business.
{ Begineers - please follow the advice at the bottom of this post! -mod }
I would like to create a string class, based on the STL basic_string if
possible, that treats upper and lower case characters as the same. i.e.
('a' == 'A') == true. Can I do this without being STL implementation
specific?
I've noticed that my version of the STL (Roguewave) that came with Borland
C++ 5.0 defines the methods eq ne lt gt in the class basic_string_traits.
is this a starting point or is this just their implementation?
Regards, Simon.
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
Author: magao@zip.com.au (Timothy C. Delaney)
Date: 1996/08/16 Raw View
In article <4uup10$8ql@netlab.cs.rpi.edu>, "Simon Harris"
<simon@addease.com.au> wrote:
> First off, please excuse me if I've posted to an inppropriate group. Let me
> know and I'll stop. OK now down to business.
> { Begineers - please follow the advice at the bottom of this post! -mod }
>
> I would like to create a string class, based on the STL basic_string if
> possible, that treats upper and lower case characters as the same. i.e.
> ('a' == 'A') == true. Can I do this without being STL implementation
> specific?
>
> I've noticed that my version of the STL (Roguewave) that came with Borland
> C++ 5.0 defines the methods eq ne lt gt in the class basic_string_traits.
> is this a starting point or is this just their implementation?
Whilst I haven't done it in STL, I find the simplest way to make a
case-insensitive string class is to simply make the stored string all
upper/lowercase (choose your preference) and then any strings being
compared are converted to the same case before the comparison takes place.
This is easily done if the string class provides a Compare (or similar
function) - simply override it (and the constructors) to convert the
string passed in to lowercase. In the case of a constructor this would
probably involve converting a data member which is initialised in the base
class, for the compare you would make a local copy of the string, convert
it to lowercase (this could be done in one step) and then call the base
class' comparison function on the new string.
--
<http://www.zip.com.au/~delaney/standard_disclaimer.html>
_/_/_/_/
__| __| _/_| _/_/_/ _/_| _/_/_/
_/_| _/_| _/ _| _/ _/ _| _/ _/
-/ _|_/ _| _/_/_/_| _/ _/_/_/ _/_/_/_| _/ _/
_/ __/ _| _/ _| _/_/_/ _/ _| _/_/_/
Tim Delaney magao@zip.com.au
Mac/Windows SW Engineer, Bold magao@bold.com.au
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]