<aclass="ulink"href="http://www.gotw.ca/gotw/"target="_top">Guru of the Week</a>
discussions held on Usenet covered this topic in January of 1998.
Briefly, the challenge was, “<spanclass="quote">write a 'ci_string' class which
is identical to the standard 'string' class, but is
case-insensitive in the same way as the (common but nonstandard)
C function stricmp()</span>”.
</p><preclass="programlisting">
ci_string s( "AbCdE" );
// case insensitive
assert( s == "abcde" );
assert( s == "ABCDE" );
// still case-preserving, of course
assert( strcmp( s.c_str(), "AbCdE" ) == 0 );
assert( strcmp( s.c_str(), "abcde" ) != 0 ); </pre><p>The solution is surprisingly easy. The original answer was
posted on Usenet, and a revised version appears in Herb Sutter's
book <spanclass="emphasis"><em>Exceptional C++</em></span> and on his website as <aclass="ulink"href="http://www.gotw.ca/gotw/029.htm"target="_top">GotW 29</a>.
</p><p>See? Told you it was easy!</p><p>
<spanclass="emphasis"><em>Added June 2000:</em></span> The May 2000 issue of C++
Report contains a fascinating <aclass="ulink"href="http://lafstern.org/matt/col2_new.pdf"target="_top"> article</a> by
Matt Austern (yes, <spanclass="emphasis"><em>the</em></span> Matt Austern) on why
case-insensitive comparisons are not as easy as they seem, and
why creating a class is the <spanclass="emphasis"><em>wrong</em></span> way to go
about it in production code. (The GotW answer mentions one of
the principle difficulties; his article mentions more.)
</p><p>Basically, this is "easy" only if you ignore some things,
things which may be too important to your program to ignore. (I chose
to ignore them when originally writing this entry, and am surprised
that nobody ever called me on it...) The GotW question and answer
remain useful instructional tools, however.
</p><p><spanclass="emphasis"><em>Added September 2000:</em></span> James Kanze provided a link to a
Technical Report discussing case handling</a>, which provides some
very good information.
</p></div><divclass="navfooter"><hr/><tablewidth="100%"summary="Navigation footer"><tr><tdwidth="40%"align="left"><aaccesskey="p"href="bk01pt05ch13.html">Prev</a></td><tdwidth="20%"align="center"><aaccesskey="u"href="bk01pt05ch13.html">Up</a></td><tdwidth="40%"align="right"><aaccesskey="n"href="bk01pt05ch13s03.html">Next</a></td></tr><tr><tdwidth="40%"align="left"valign="top">Chapter13.String Classes</td><tdwidth="20%"align="center"><aaccesskey="h"href="../spine.html">Home</a></td><tdwidth="40%"align="right"valign="top">Arbitrary Character Types</td></tr></table></div></body></html>