aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/docs/html/22_locale/howto.html
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/docs/html/22_locale/howto.html')
-rw-r--r--libstdc++-v3/docs/html/22_locale/howto.html101
1 files changed, 53 insertions, 48 deletions
diff --git a/libstdc++-v3/docs/html/22_locale/howto.html b/libstdc++-v3/docs/html/22_locale/howto.html
index d8ada0464b1..d6a340c9e54 100644
--- a/libstdc++-v3/docs/html/22_locale/howto.html
+++ b/libstdc++-v3/docs/html/22_locale/howto.html
@@ -1,13 +1,17 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
-<html>
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
- <meta http-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 22.">
- <meta name="GENERATOR" content="vi and eight fingers">
+ <meta http-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 22." />
+ <meta name="GENERATOR" content="vi and eight fingers" />
<title>libstdc++-v3 HOWTO: Chapter 22</title>
-<link rel="StyleSheet" href="../lib3styles.css">
+<link rel="StyleSheet" href="../lib3styles.css" />
</head>
<body>
@@ -16,39 +20,40 @@
<p>Chapter 22 deals with the C++ localization facilities.
</p>
<!-- I wanted to write that sentence in something requiring an exotic font,
- like Cryllic or Kanji. Probably more work than such cuteness is worth,
+ like Cyrllic or Kanji. Probably more work than such cuteness is worth,
but I still think it'd be funny.
-->
<!-- ####################################################### -->
-<hr>
+<hr />
<h1>Contents</h1>
<ul>
- <li><a href="#1">class locale</a>
- <li><a href="#2">class codecvt</a>
- <li><a href="#3">class ctype</a>
- <li><a href="#4">class messages</a>
- <li><a href="#5">Bjarne Stroustrup on Locales</a>
- <li><a href="#6">Nathan Myers on Locales</a>
- <li><a href="#7">Correct Transformations</a>
+ <li><a href="#1">class locale</a></li>
+ <li><a href="#2">class codecvt</a></li>
+ <li><a href="#3">class ctype</a></li>
+ <li><a href="#4">class messages</a></li>
+ <li><a href="#5">Bjarne Stroustrup on Locales</a></li>
+ <li><a href="#6">Nathan Myers on Locales</a></li>
+ <li><a href="#7">Correct Transformations</a></li>
</ul>
<!-- ####################################################### -->
-<hr>
+<hr />
<h2><a name="1">class locale</a></h2>
<p>Notes made during the implementation of locales can be found
<a href="locale.html">here</a>.
</p>
-<hr>
+<hr />
<h2><a name="2">class codecvt</a></h2>
<p>Notes made during the implementation of codecvt can be found
<a href="codecvt.html">here</a>.
</p>
<p>The following is the abstract from the implementation notes:
+ </p>
<blockquote>
The standard class codecvt attempts to address conversions between
different character encoding schemes. In particular, the standard
@@ -64,21 +69,20 @@
the required specializations for wide and narrow characters and the
implementation-provided extended functionality are given.
</blockquote>
- </p>
-<hr>
+<hr />
<h2><a name="3">class ctype</a></h2>
<p>Notes made during the implementation of ctype can be found
<a href="ctype.html">here</a>.
</p>
-<hr>
+<hr />
<h2><a name="4">class messages</a></h2>
<p>Notes made during the implementation of messages can be found
<a href="messages.html">here</a>.
</p>
-<hr>
+<hr />
<h2><a name="5">Stroustrup on Locales</a></h2>
<p>Dr. Bjarne Stroustrup has released a
<a href="http://www.research.att.com/~bs/3rd_loc0.html">pointer</a>
@@ -88,22 +92,22 @@
description of locales and how to use them.
</p>
<p>He also writes:
+ </p>
<blockquote><em>
Please note that I still consider this detailed description of
locales beyond the needs of most C++ programmers. It is written
with experienced programmers in mind and novices will do best to
avoid it.
</em></blockquote>
- </p>
-<hr>
+<hr />
<h2><a name="6">Nathan Myers on Locales</a></h2>
<p>An article entitled &quot;The Standard C++ Locale&quot; was
published in Dr. Dobb's Journal and can be found
<a href="http://www.cantrip.org/locale.html">here</a>.
</p>
-<hr>
+<hr />
<h2><a name="7">Correct Transformations</a></h2>
<!-- Jumping directly to here from chapter 21. -->
<p>A very common question on newsgroups and mailing lists is, &quot;How
@@ -131,6 +135,7 @@
is created. Then member functions of that locale are called to
perform minor tasks. Continuing the example from Chapter 21, we wish
to use the following convenience functions:
+ </p>
<pre>
namespace std {
template &lt;class charT&gt;
@@ -140,6 +145,7 @@
charT
tolower (charT c, const locale&amp; loc) const;
}</pre>
+ <p>
This function extracts the appropriate &quot;facet&quot; from the
locale <em>loc</em> and calls the appropriate member function of that
facet, passing <em>c</em> as its argument. The resulting character
@@ -154,6 +160,7 @@
parameter. So we write simple wrapper structs to handle that.
</p>
<p>The next-to-final version of the code started in Chapter 21 looks like:
+ </p>
<pre>
#include &lt;iterator&gt; // for back_inserter
#include &lt;locale&gt;
@@ -161,45 +168,43 @@
#include &lt;algorithm&gt;
#include &lt;cctype&gt; // old &lt;ctype.h&gt;
- struct Toupper
+ struct ToUpper
{
- Toupper (std::locale const&amp; l) : loc(l) {;}
- char operator() (char c) { return std::toupper(c,loc); }
+ ToUpper(std::locale const&amp; l) : loc(l) {;}
+ char operator() (char c) const { return std::toupper(c,loc); }
private:
std::locale const&amp; loc;
};
- struct Tolower
+ struct ToLower
{
- Tolower (std::locale const&amp; l) : loc(l) {;}
- char operator() (char c) { return std::tolower(c,loc); }
+ ToLower(std::locale const&amp; l) : loc(l) {;}
+ char operator() (char c) const { return std::tolower(c,loc); }
private:
std::locale const&amp; loc;
};
int main ()
{
- std::string s ("Some Kind Of Initial Input Goes Here");
- Toupper up ( std::locale("C") );
- Tolower down ( std::locale("C") );
+ std::string s("Some Kind Of Initial Input Goes Here");
+ std::locale loc_c("C");
+ ToUpper up(loc_c);
+ ToLower down(loc_c);
- // Change everything into upper case
- std::transform (s.begin(), s.end(), s.begin(),
- up
- );
+ // Change everything into upper case.
+ std::transform(s.begin(), s.end(), s.begin(), up);
- // Change everything into lower case
- std::transform (s.begin(), s.end(), s.begin(),
- down
- );
+ // Change everything into lower case.
+ std::transform(s.begin(), s.end(), s.begin(), down);
// Change everything back into upper case, but store the
- // result in a different string
+ // result in a different string.
std::string capital_s;
- std::transform (s.begin(), s.end(), std::back_inserter(capital_s),
- up
- );
+ std::transform(s.begin(), s.end(), std::back_inserter(capital_s), up);
}</pre>
+ <p>The <code>ToUpper</code> and <code>ToLower</code> structs can be
+ generalized for other character types by making <code>operator()</code>
+ a member function template.
</p>
<p>The final version of the code uses <code>bind2nd</code> to eliminate
the wrapper structs, but the resulting code is tricky. I have not
@@ -210,7 +215,7 @@
<!-- ####################################################### -->
-<hr>
+<hr />
<p class="fineprint"><em>
See <a href="../17_intro/license.html">license.html</a> for copying conditions.
Comments and suggestions are welcome, and may be sent to