summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/docs/html/21_strings/howto.html
diff options
context:
space:
mode:
authorpme <pme@138bc75d-0d04-0410-961f-82ee72b054a4>2001-09-17 23:24:40 +0000
committerpme <pme@138bc75d-0d04-0410-961f-82ee72b054a4>2001-09-17 23:24:40 +0000
commitc558c60c115adb132ab9b4fb9662d23184c3272b (patch)
tree74ce2b24b23a1ae2d24a36c9cd0622a7a5845ca2 /libstdc++-v3/docs/html/21_strings/howto.html
parent77918ba42f29c839be0a9a261842035984d18c3b (diff)
downloadppe42-gcc-c558c60c115adb132ab9b4fb9662d23184c3272b.tar.gz
ppe42-gcc-c558c60c115adb132ab9b4fb9662d23184c3272b.zip
2001-09-17 Phil Edwards <pme@gcc.gnu.org>
* docs/html/configopts.html: HTML to XHTML change. Lowercase tags. * docs/html/documentation.html: Likewise. * docs/html/explanations.html: Likewise. * docs/html/install.html: Likewise. * docs/html/17_intro/howto.html: Likewise. * docs/html/18_support/howto.html: Likewise. * docs/html/19_diagnostics/howto.html: Likewise. * docs/html/20_util/howto.html: Likewise. * docs/html/21_strings/howto.html: Likewise. * docs/html/22_locale/codecvt.html: Likewise. * docs/html/22_locale/ctype.html: Likewise. * docs/html/22_locale/howto.html: Likewise. * docs/html/22_locale/locale.html: Likewise. * docs/html/22_locale/messages.html: Likewise. * docs/html/23_containers/howto.html: Likewise. * docs/html/24_iterators/howto.html: Likewise. * docs/html/25_algorithms/howto.html: Likewise. * docs/html/26_numerics/howto.html: Likewise. * docs/html/27_io/howto.html: Likewise. * docs/html/ext/howto.html: Likewise. * docs/html/faq/index.html: Likewise. * docs/html/faq/index.txt: Regenerated. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45668 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/docs/html/21_strings/howto.html')
-rw-r--r--libstdc++-v3/docs/html/21_strings/howto.html276
1 files changed, 138 insertions, 138 deletions
diff --git a/libstdc++-v3/docs/html/21_strings/howto.html b/libstdc++-v3/docs/html/21_strings/howto.html
index 80254269ff9..bf47e406c41 100644
--- a/libstdc++-v3/docs/html/21_strings/howto.html
+++ b/libstdc++-v3/docs/html/21_strings/howto.html
@@ -1,60 +1,60 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
-<HTML>
-<HEAD>
- <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
- <META NAME="AUTHOR" CONTENT="pme@sources.redhat.com (Phil Edwards)">
- <META NAME="KEYWORDS" CONTENT="HOWTO, libstdc++, GCC, g++, libg++, STL">
- <META NAME="DESCRIPTION" CONTENT="HOWTO for the libstdc++ chapter 21.">
- <META NAME="GENERATOR" CONTENT="vi and eight fingers">
- <TITLE>libstdc++-v3 HOWTO: Chapter 21</TITLE>
-<LINK REL=StyleSheet HREF="../lib3styles.css">
-<!-- $Id: howto.html,v 1.2 2001/02/07 00:03:20 pme Exp $ -->
-</HEAD>
-<BODY>
+<html>
+<head>
+ <meta HcodeP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
+ <meta NAME="AUTHOR" CONTENT="pme@gcc.gnu.org (Phil Edwards)">
+ <meta NAME="KEYWORDS" CONTENT="HOWTO, libstdc++, GCC, g++, libg++, STL">
+ <meta NAME="DESCRIPTION" CONTENT="HOWTO for the libstdc++ chapter 21.">
+ <meta NAME="GENERATOR" CONTENT="vi and eight fingers">
+ <title>libstdc++-v3 HOWTO: Chapter 21</title>
+<link REL=StyleSheet HREF="../lib3styles.css">
+<!-- $Id: howto.html,v 1.3 2001/04/03 00:26:55 pme Exp $ -->
+</head>
+<body>
-<H1 CLASS="centered"><A NAME="top">Chapter 21: Strings</A></H1>
+<h1 CLASS="centered"><a name="top">Chapter 21: Strings</a></h1>
-<P>Chapter 21 deals with the C++ strings library (a welcome relief).
-</P>
+<p>Chapter 21 deals with the C++ strings library (a welcome relief).
+</p>
<!-- ####################################################### -->
-<HR>
-<H1>Contents</H1>
-<UL>
- <LI><A HREF="#1">MFC's CString</A>
- <LI><A HREF="#2">A case-insensitive string class</A>
- <LI><A HREF="#3">Breaking a C++ string into tokens</A>
- <LI><A HREF="#4">Simple transformations</A>
-</UL>
+<hr>
+<h1>Contents</h1>
+<ul>
+ <li><a href="#1">MFC's CString</a>
+ <li><a href="#2">A case-insensitive string class</a>
+ <li><a href="#3">Breaking a C++ string into tokens</a>
+ <li><a href="#4">Simple transformations</a>
+</ul>
-<HR>
+<hr>
<!-- ####################################################### -->
-<H2><A NAME="1">MFC's CString</A></H2>
- <P>A common lament seen in various newsgroups deals with the Standard
+<h2><a name="1">MFC's CString</a></h2>
+ <p>A common lament seen in various newsgroups deals with the Standard
string class as opposed to the Microsoft Foundation Class called
CString. Often programmers realize that a standard portable
answer is better than a proprietary nonportable one, but in porting
their application from a Win32 platform, they discover that they
are relying on special functons offered by the CString class.
- </P>
- <P>Things are not as bad as they seem. In
- <A HREF="http://gcc.gnu.org/ml/gcc/1999-04n/msg00236.html">this
- message</A>, Joe Buck points out a few very important things:
- <UL>
- <LI>The Standard <TT>string</TT> supports all the operations
+ </p>
+ <p>Things are not as bad as they seem. In
+ <a href="http://gcc.gnu.org/ml/gcc/1999-04n/msg00236.html">this
+ message</a>, Joe Buck points out a few very important things:
+ <ul>
+ <li>The Standard <code>string</code> supports all the operations
that CString does, with three exceptions.
- <LI>Two of those exceptions (whitespace trimming and case
+ <li>Two of those exceptions (whitespace trimming and case
conversion) are trivial to implement. In fact, we do so
on this page.
- <LI>The third is <TT>CString::Format</TT>, which allows formatting
- in the style of <TT>sprintf</TT>. This deserves some mention:
- </UL>
- </P>
- <A NAME="1.1internal"> <!-- Coming from Chapter 27 -->
- <P>The old libg++ library had a function called form(), which did much
+ <li>The third is <code>CString::Format</code>, which allows formatting
+ in the style of <code>sprintf</code>. This deserves some mention:
+ </ul>
+ </p>
+ <a name="1.1internal"> <!-- Coming from Chapter 27 -->
+ <p>The old libg++ library had a function called form(), which did much
the same thing. But for a Standard solution, you should use the
stringstream classes. These are the bridge between the iostream
hierarchy and the string class, and they operate with regular
@@ -80,8 +80,8 @@
return output_stream.str();
} </PRE>
- </P></A>
- <P>A serious problem with CString is a design bug in its memory
+ </p></a>
+ <p>A serious problem with CString is a design bug in its memory
allocation. Specifically, quoting from that same message:
<PRE>
CString suffers from a common programming error that results in
@@ -105,40 +105,40 @@
If you replace CString with string in the above function, the
performance is O(n).
</PRE>
- </P>
- <P>Joe Buck also pointed out some other things to keep in mind when
+ </p>
+ <p>Joe Buck also pointed out some other things to keep in mind when
comparing CString and the Standard string class:
- <UL>
- <LI>CString permits access to its internal representation; coders
- who exploited that may have problems moving to <TT>string</TT>.
- <LI>Microsoft ships the source to CString (in the files
+ <ul>
+ <li>CString permits access to its internal representation; coders
+ who exploited that may have problems moving to <code>string</code>.
+ <li>Microsoft ships the source to CString (in the files
MFC\SRC\Str{core,ex}.cpp), so you could fix the allocation
bug and rebuild your MFC libraries.
- <EM><B>Note:</B> It looks like the the CString shipped with
+ <em><B>Note:</B> It looks like the the CString shipped with
VC++6.0 has fixed this, although it may in fact have been one
- of the VC++ SPs that did it.</EM>
- <LI><TT>string</TT> operations like this have O(n) complexity
- <EM>if the implementors do it correctly</EM>. The libstdc++
+ of the VC++ SPs that did it.</em>
+ <li><code>string</code> operations like this have O(n) complexity
+ <em>if the implementors do it correctly</em>. The libstdc++
implementors did it correctly. Other vendors might not.
- <LI>While parts of the SGI STL are used in libstdc++-v3, their
- string class is not. The SGI <TT>string</TT> is essentially
- <TT>vector&lt;char&gt;</TT> and does not do any reference
+ <li>While parts of the SGI STL are used in libstdc++-v3, their
+ string class is not. The SGI <code>string</code> is essentially
+ <code>vector&lt;char&gt;</code> and does not do any reference
counting like libstdc++-v3's does. (It is O(n), though.)
So if you're thinking about SGI's string or rope classes,
you're now looking at four possibilities: CString, the
libstdc++ string, the SGI string, and the SGI rope, and this
is all before any allocator or traits customizations! (More
choices than you can shake a stick at -- want fries with that?)
- </UL>
- </P>
- <P>Return <A HREF="#top">to top of page</A> or
- <A HREF="../faq/index.html">to the FAQ</A>.
- </P>
+ </ul>
+ </p>
+ <p>Return <a href="#top">to top of page</a> or
+ <a href="../faq/index.html">to the FAQ</a>.
+ </p>
-<HR>
-<H2><A NAME="2">A case-insensitive string class</A></H2>
- <P>The well-known-and-if-it-isn't-well-known-it-ought-to-be
- <A HREF="http://www.peerdirect.com/resources/">Guru of the Week</A>
+<hr>
+<h2><a name="2">A case-insensitive string class</a></h2>
+ <p>The well-known-and-if-it-isn't-well-known-it-ought-to-be
+ <a href="http://www.peerdirect.com/resources/">Guru of the Week</a>
discussions held on Usenet covered this topic in January of 1998.
Briefly, the challenge was, &quot;write a 'ci_string' class which
is identical to the standard 'string' class, but is
@@ -154,57 +154,57 @@
// still case-preserving, of course
assert( strcmp( s.c_str(), "AbCdE" ) == 0 );
assert( strcmp( s.c_str(), "abcde" ) != 0 ); </PRE>
- </P>
+ </p>
- <P>The solution is surprisingly easy. The original answer pages
+ <p>The solution is surprisingly easy. The original answer pages
on the GotW website were removed into cold storage, in
preparation for
- <A HREF="http://cseng.aw.com/bookpage.taf?ISBN=0-201-61562-2">a
- published book of GotW notes</A>. Before being
+ <a href="http://cseng.aw.com/bookpage.taf?ISBN=0-201-61562-2">a
+ published book of GotW notes</a>. Before being
put on the web, of course, it was posted on Usenet, and that
- posting containing the answer is <A HREF="gotw29a.txt">available
- here</A>.
- </P>
- <P>See? Told you it was easy!</P>
- <P><B>Added June 2000:</B> The May issue of <U>C++ Report</U> contains
- a fascinating article by Matt Austern (yes, <EM>the</EM> Matt Austern)
+ posting containing the answer is <a href="gotw29a.txt">available
+ here</a>.
+ </p>
+ <p>See? Told you it was easy!</p>
+ <p><B>Added June 2000:</B> The May issue of <U>C++ Report</U> contains
+ a fascinating article by Matt Austern (yes, <em>the</em> Matt Austern)
on why case-insensitive comparisons are not as easy as they seem,
- and why creating a class is the <EM>wrong</EM> way to go about it in
+ and why creating a class is the <em>wrong</em> 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 &quot;easy&quot; only if you ignore some things,
+ </p>
+ <p>Basically, this is &quot;easy&quot; 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><B>Added September 2000:</B> James Kanze provided a link to a
- <A HREF="http://www.unicode.org/unicode/reports/tr21/">Unicode
- Technical Report discussing case handling</A>, which provides some
+ </p>
+ <p><B>Added September 2000:</B> James Kanze provided a link to a
+ <a href="http://www.unicode.org/unicode/reports/tr21/">Unicode
+ Technical Report discussing case handling</a>, which provides some
very good information.
- </P>
- <P>Return <A HREF="#top">to top of page</A> or
- <A HREF="../faq/index.html">to the FAQ</A>.
- </P>
+ </p>
+ <p>Return <a href="#top">to top of page</a> or
+ <a href="../faq/index.html">to the FAQ</a>.
+ </p>
-<HR>
-<H2><A NAME="3">Breaking a C++ string into tokens</A></H2>
- <P>The Standard C (and C++) function <TT>strtok()</TT> leaves a lot to
+<hr>
+<h2><a name="3">Breaking a C++ string into tokens</a></h2>
+ <p>The Standard C (and C++) function <code>strtok()</code> leaves a lot to
be desired in terms of user-friendliness. It's unintuitive, it
destroys the character string on which it operates, and it requires
you to handle all the memory problems. But it does let the client
code decide what to use to break the string into pieces; it allows
you to choose the &quot;whitespace,&quot; so to speak.
- </P>
- <P>A C++ implementation lets us keep the good things and fix those
+ </p>
+ <p>A C++ implementation lets us keep the good things and fix those
annoyances. The implementation here is more intuitive (you only
call it once, not in a loop with varying argument), it does not
affect the original string at all, and all the memory allocation
is handled for you.
- </P>
- <P>It's called stringtok, and it's a template function. It's given
- <A HREF="stringtok_h.txt">in this file</A> in a less-portable form than
+ </p>
+ <p>It's called stringtok, and it's a template function. It's given
+ <a href="stringtok_h.txt">in this file</a> in a less-portable form than
it could be, to keep this example simple (for example, see the
comments on what kind of string it will accept). The author uses
a more general (but less readable) form of it for parsing command
@@ -223,39 +223,39 @@
:is:
:a:
:test:</PRE>
- with all the whitespace removed. The original <TT>s</TT> is still
- available for use, <TT>ls</TT> will clean up after itself, and
- <TT>ls.size()</TT> will return how many tokens there were.
- </P>
- <P>As always, there is a price paid here, in that stringtok is not
+ with all the whitespace removed. The original <code>s</code> is still
+ available for use, <code>ls</code> will clean up after itself, and
+ <code>ls.size()</code> will return how many tokens there were.
+ </p>
+ <p>As always, there is a price paid here, in that stringtok is not
as fast as strtok. The other benefits usually outweight that, however.
- <A HREF="stringtok_std_h.txt">Another version of stringtok is given
- here</A>, suggested by Chris King and tweaked by Petr Prikryl,
+ <a href="stringtok_std_h.txt">Another version of stringtok is given
+ here</a>, suggested by Chris King and tweaked by Petr Prikryl,
and this one uses the
transformation functions mentioned below. If you are comfortable
with reading the new function names, this version is recommended
as an example.
- </P>
- <P><B>Added February 2001:</B> Mark Wilden pointed out that the
- standard <TT>std::getline()</TT> function can be used with standard
- <A HREF="../27_io/howto.html">istringstreams</A> to perform
+ </p>
+ <p><B>Added February 2001:</B> Mark Wilden pointed out that the
+ standard <code>std::getline()</code> function can be used with standard
+ <a href="../27_io/howto.html">istringstreams</a> to perform
tokenizing as well. Build an istringstream from the input text,
and then use std::getline with varying delimiters (the three-argument
signature) to extract tokens into a string.
- </P>
- <P>Return <A HREF="#top">to top of page</A> or
- <A HREF="../faq/index.html">to the FAQ</A>.
- </P>
+ </p>
+ <p>Return <a href="#top">to top of page</a> or
+ <a href="../faq/index.html">to the FAQ</a>.
+ </p>
-<HR>
-<H2><A NAME="4">Simple transformations</A></H2>
- <P>Here are Standard, simple, and portable ways to perform common
- transformations on a <TT>string</TT> instance, such as &quot;convert
+<hr>
+<h2><a name="4">Simple transformations</a></h2>
+ <p>Here are Standard, simple, and portable ways to perform common
+ transformations on a <code>string</code> instance, such as &quot;convert
to all upper case.&quot; The word transformations is especially
apt, because the standard template function
- <TT>transform&lt;&gt;</TT> is used.
- </P>
- <P>This code will go through some iterations (no pun). Here's the
+ <code>transform&lt;&gt;</code> is used.
+ </p>
+ <p>This code will go through some iterations (no pun). Here's the
simplistic version usually seen on Usenet:
<PRE>
#include &lt;string&gt;
@@ -277,31 +277,31 @@
std::transform (s.begin(), s.end(), capital_s.begin(), tolower); </PRE>
<SPAN CLASS="larger"><B>Note</B></SPAN> that these calls all involve
the global C locale through the use of the C functions
- <TT>toupper/tolower</TT>. This is absolutely guaranteed to work --
- but <EM>only</EM> if the string contains <EM>only</EM> characters
- from the basic source character set, and there are <EM>only</EM>
+ <code>toupper/tolower</code>. This is absolutely guaranteed to work --
+ but <em>only</em> if the string contains <em>only</em> characters
+ from the basic source character set, and there are <em>only</em>
96 of those. Which means that not even all English text can be
represented (certain British spellings, proper names, and so forth).
So, if all your input forevermore consists of only those 96
characters (hahahahahaha), then you're done.
- </P>
- <P>At minimum, you can write short wrappers like
+ </p>
+ <p>At minimum, you can write short wrappers like
<PRE>
char toLower (char c)
{
return tolower(static_cast&lt;unsigned char&gt;(c));
}</PRE>
- </P>
- <P>The correct method is to use a facet for a particular locale
+ </p>
+ <p>The correct method is to use a facet for a particular locale
and call its conversion functions. These are discussed more in
Chapter 22; the specific part is
- <A HREF="../22_locale/howto.html#5">here</A>, which shows the
+ <a href="../22_locale/howto.html#5">here</a>, which shows the
final version of this code. (Thanks to James Kanze for assistance
and suggestions on all of this.)
- </P>
- <P>Another common operation is trimming off excess whitespace. Much
+ </p>
+ <p>Another common operation is trimming off excess whitespace. Much
like transformations, this task is trivial with the use of string's
- <TT>find</TT> family. These examples are broken into multiple
+ <code>find</code> family. These examples are broken into multiple
statements for readability:
<PRE>
std::string str (" \t blah blah blah \n ");
@@ -313,26 +313,26 @@
// trim trailing whitespace
notwhite = str.find_last_not_of(" \t\n");
str.erase(notwhite+1); </PRE>
- Obviously, the calls to <TT>find</TT> could be inserted directly
- into the calls to <TT>erase</TT>, in case your compiler does not
+ Obviously, the calls to <code>find</code> could be inserted directly
+ into the calls to <code>erase</code>, in case your compiler does not
optimize named temporaries out of existance.
- </P>
- <P>Return <A HREF="#top">to top of page</A> or
- <A HREF="../faq/index.html">to the FAQ</A>.
- </P>
+ </p>
+ <p>Return <a href="#top">to top of page</a> or
+ <a href="../faq/index.html">to the FAQ</a>.
+ </p>
<!-- ####################################################### -->
-<HR>
-<P CLASS="fineprint"><EM>
+<hr>
+<P CLASS="fineprint"><em>
Comments and suggestions are welcome, and may be sent to
-<A HREF="mailto:libstdc++@gcc.gnu.org">the mailing list</A>.
-<BR> $Id: howto.html,v 1.2 2001/02/07 00:03:20 pme Exp $
-</EM></P>
+<a href="mailto:libstdc++@gcc.gnu.org">the mailing list</a>.
+<br> $Id: howto.html,v 1.3 2001/04/03 00:26:55 pme Exp $
+</em></p>
-</BODY>
-</HTML>
+</body>
+</html>
OpenPOWER on IntegriCloud