Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > case insensitive find on case sensitive stl map

Reply
Thread Tools

case insensitive find on case sensitive stl map

 
 
benhoefer@gmail.com
Guest
Posts: n/a
 
      04-06-2007
I have been searching around and have not been able to find any info
on this. I have a unique situation where I need a case sensitive map:

std::map<string, int> imap;

I need to be able to run a find on this map with a case sensitive AND
case insensitive search. I need to be able to change this dynamically
during execution. Is this possible? Any thoughts on this? I
understand that I can make the map case insensitive, but that is not
what I need.

 
Reply With Quote
 
 
 
 
Mark P
Guest
Posts: n/a
 
      04-06-2007
wrote:
> I have been searching around and have not been able to find any info
> on this. I have a unique situation where I need a case sensitive map:
>
> std::map<string, int> imap;
>
> I need to be able to run a find on this map with a case sensitive AND
> case insensitive search. I need to be able to change this dynamically
> during execution. Is this possible? Any thoughts on this? I
> understand that I can make the map case insensitive, but that is not
> what I need.
>


How about a custom comparison function which will sort such that all
strings which differ only in case are adjacent to one another? There
are a number of ways to achieve this.

Then, for case insensitive search, you can use lower_bound or
upper_bound instead of find and efficiently look at adjacent map
elements with the same letters modulo capitalization.

Another possibility is to use multimap instead of map but this, unlike
the above approach, will allow multiple identical keys and you may have
to look at all cases even for case sensitive search.

-Mark
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
check file exists with case sensitive on a case insensitive filesystem Xah Lee Perl Misc 4 04-05-2009 11:21 PM
STL map or hash map using struct as data and find it kl C++ 7 01-01-2008 11:05 AM
std::map and case insensitive search bb C++ 4 05-19-2007 08:13 AM
case sensitive / insensitive string equality Stephanie ASP General 2 10-03-2005 01:23 PM
how to case select with case-insensitive string ? Tee ASP .Net 3 06-23-2004 07:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57