]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/doc/html/manual/bk01pt05ch13s02.html
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / doc / html / manual / bk01pt05ch13s02.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Case Sensitivity</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      library&#10;    " /><link rel="start" href="../spine.html" title="The GNU C++ Library Documentation" /><link rel="up" href="bk01pt05ch13.html" title="Chapter 13. String Classes" /><link rel="prev" href="bk01pt05ch13.html" title="Chapter 13. String Classes" /><link rel="next" href="bk01pt05ch13s03.html" title="Arbitrary Character Types" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Case Sensitivity</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk01pt05ch13.html">Prev</a> </td><th width="60%" align="center">Chapter 13. String Classes</th><td width="20%" align="right"> <a accesskey="n" href="bk01pt05ch13s03.html">Next</a></td></tr></table><hr /></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="strings.string.case"></a>Case Sensitivity</h2></div></div></div><p>
4     </p><p>The well-known-and-if-it-isn't-well-known-it-ought-to-be
5       <a class="ulink" href="http://www.gotw.ca/gotw/" target="_top">Guru of the Week</a>
6       discussions held on Usenet covered this topic in January of 1998.
7       Briefly, the challenge was, “<span class="quote">write a 'ci_string' class which
8       is identical to the standard 'string' class, but is
9       case-insensitive in the same way as the (common but nonstandard)
10       C function stricmp()</span>”.
11    </p><pre class="programlisting">
12    ci_string s( "AbCdE" );
13
14    // case insensitive
15    assert( s == "abcde" );
16    assert( s == "ABCDE" );
17
18    // still case-preserving, of course
19    assert( strcmp( s.c_str(), "AbCdE" ) == 0 );
20    assert( strcmp( s.c_str(), "abcde" ) != 0 ); </pre><p>The solution is surprisingly easy.  The original answer was
21    posted on Usenet, and a revised version appears in Herb Sutter's
22    book <span class="emphasis"><em>Exceptional C++</em></span> and on his website as <a class="ulink" href="http://www.gotw.ca/gotw/029.htm" target="_top">GotW 29</a>.
23    </p><p>See?  Told you it was easy!</p><p>
24      <span class="emphasis"><em>Added June 2000:</em></span> The May 2000 issue of C++
25      Report contains a fascinating <a class="ulink" href="http://lafstern.org/matt/col2_new.pdf" target="_top"> article</a> by
26      Matt Austern (yes, <span class="emphasis"><em>the</em></span> Matt Austern) on why
27      case-insensitive comparisons are not as easy as they seem, and
28      why creating a class is the <span class="emphasis"><em>wrong</em></span> way to go
29      about it in production code.  (The GotW answer mentions one of
30      the principle difficulties; his article mentions more.)
31    </p><p>Basically, this is "easy" only if you ignore some things,
32       things which may be too important to your program to ignore.  (I chose
33       to ignore them when originally writing this entry, and am surprised
34       that nobody ever called me on it...)  The GotW question and answer
35       remain useful instructional tools, however.
36    </p><p><span class="emphasis"><em>Added September 2000:</em></span>  James Kanze provided a link to a
37       <a class="ulink" href="http://www.unicode.org/unicode/reports/tr21/" target="_top">Unicode
38       Technical Report discussing case handling</a>, which provides some
39       very good information.
40    </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk01pt05ch13.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk01pt05ch13.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk01pt05ch13s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 13. String Classes </td><td width="20%" align="center"><a accesskey="h" href="../spine.html">Home</a></td><td width="40%" align="right" valign="top"> Arbitrary Character Types</td></tr></table></div></body></html>