diff options
author | Phil Edwards <pme@gcc.gnu.org> | 2000-09-19 21:44:30 +0000 |
---|---|---|
committer | Phil Edwards <pme@gcc.gnu.org> | 2000-09-19 21:44:30 +0000 |
commit | 3c1fd79ba934a549aa176c21322794975313fa88 (patch) | |
tree | cdf51e0ed813b71eda9ea7f814c5b9e3a13f7bd9 | |
parent | 7eea5554ce33c1031a635d538695de0de1e5d97b (diff) | |
download | gcc-3c1fd79ba934a549aa176c21322794975313fa88.zip gcc-3c1fd79ba934a549aa176c21322794975313fa88.tar.gz gcc-3c1fd79ba934a549aa176c21322794975313fa88.tar.bz2 |
thanks.html: More thanks.
2000-09-19 Phil Edwards <pme@sources.redhat.com>
* docs/thanks.html: More thanks.
* docs/18_support/howto.html: Fix thinko.
* docs/21_strings/howto.html: Minor tweaks and updates to URLs.
Redo the string transformation notes and link to...
* docs/22_locale/howto.html: ...here.
From-SVN: r36546
-rw-r--r-- | libstdc++-v3/ChangeLog | 8 | ||||
-rw-r--r-- | libstdc++-v3/docs/18_support/howto.html | 6 | ||||
-rw-r--r-- | libstdc++-v3/docs/21_strings/howto.html | 87 | ||||
-rw-r--r-- | libstdc++-v3/docs/22_locale/howto.html | 121 | ||||
-rw-r--r-- | libstdc++-v3/docs/thanks.html | 3 |
5 files changed, 187 insertions, 38 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6921b77..4ddca7d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2000-09-19 Phil Edwards <pme@sources.redhat.com> + + * docs/thanks.html: More thanks. + * docs/18_support/howto.html: Fix thinko. + * docs/21_strings/howto.html: Minor tweaks and updates to URLs. + Redo the string transformation notes and link to... + * docs/22_locale/howto.html: ...here. + 2000-09-18 Benjamin Kosnik <bkoz@purist.soma.redhat.com> * src/locale-inst.cc: Add time_put_byname and diff --git a/libstdc++-v3/docs/18_support/howto.html b/libstdc++-v3/docs/18_support/howto.html index 7f37026..1b79cb7 100644 --- a/libstdc++-v3/docs/18_support/howto.html +++ b/libstdc++-v3/docs/18_support/howto.html @@ -9,7 +9,7 @@ <TITLE>libstdc++-v3 HOWTO: Chapter 18</TITLE> <LINK REL="home" HREF="http://sources.redhat.com/libstdc++/docs/18_support/"> <LINK REL=StyleSheet HREF="../lib3styles.css"> -<!-- $Id: howto.html,v 1.3 2000/07/11 21:45:07 pme Exp $ --> +<!-- $Id: howto.html,v 1.4 2000/07/19 20:20:51 pme Exp $ --> </HEAD> <BODY> @@ -228,7 +228,7 @@ void my_new_handler () { - delete safety; + delete[] safety; popup_window ("Dude, you are running low on heap memory. You should, like, close some windows, or something. The next time you run out, we're gonna burn!"); @@ -262,7 +262,7 @@ Comments and suggestions are welcome, and may be sent to <A HREF="mailto:pme@sources.redhat.com">Phil Edwards</A> or <A HREF="mailto:gdr@egcs.cygnus.com">Gabriel Dos Reis</A>. -<BR> $Id: howto.html,v 1.3 2000/07/11 21:45:07 pme Exp $ +<BR> $Id: howto.html,v 1.4 2000/07/19 20:20:51 pme Exp $ </EM></P> diff --git a/libstdc++-v3/docs/21_strings/howto.html b/libstdc++-v3/docs/21_strings/howto.html index 9e64cca..1875447 100644 --- a/libstdc++-v3/docs/21_strings/howto.html +++ b/libstdc++-v3/docs/21_strings/howto.html @@ -9,7 +9,7 @@ <TITLE>libstdc++-v3 HOWTO: Chapter 21</TITLE> <LINK REL="home" HREF="http://sources.redhat.com/libstdc++/docs/21_strings/"> <LINK REL=StyleSheet HREF="../lib3styles.css"> -<!-- $Id: howto.html,v 1.2 2000/07/07 21:13:28 pme Exp $ --> +<!-- $Id: howto.html,v 1.3 2000/07/11 21:45:07 pme Exp $ --> </HEAD> <BODY> @@ -42,7 +42,7 @@ are relying on special functons offered by the CString class. </P> <P>Things are not as bad as they seem. In - <A HREF="http://egcs.cygnus.com/ml/egcs/1999-04/msg00233.html">this + <A HREF="http://gcc.gnu.org/ml/egcs/1999-04/msg00233.html">this message</A>, Joe Buck points out a few very important things: <UL> <LI>The Standard <TT>string</TT> supports all the operations @@ -66,7 +66,7 @@ #include <string> #include <sstream> - string f (string& incoming) // incoming is something like "foo N" + string f (string& incoming) // incoming is "foo N" { istringstream incoming_stream(incoming); string the_word; @@ -88,7 +88,7 @@ CString suffers from a common programming error that results in poor performance. Consider the following code: - CString n_copies_of (const CString& foo, unsigned n) + CString n_copies_of (const CString& foo, unsigned n) { CString tmp; for (unsigned i = 0; i < n; i++) @@ -158,8 +158,10 @@ </P> <P>The solution is surprisingly easy. The original answer pages - on the GotW website have been removed into cold storage, in - preparation for a published book of GotW notes. Before being + 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 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>. @@ -170,7 +172,7 @@ 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 production code. (The GotW answer mentions one of the principle - difficulties; this article mentions more.) + 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 @@ -178,6 +180,11 @@ 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 + 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> @@ -204,9 +211,9 @@ a more general (but less readable) form of it for parsing command strings and the like. If you compiled and ran this code using it: <PRE> - std::list<string> ls; + std::list<string> ls; stringtok (ls, " this \t is\t\n a test "); - for (std::list<string>::const_iterator i = ls.begin(); + for (std::list<string>const_iterator i = ls.begin(); i != ls.end(); ++i) { std::cerr << ':' << (*i) << ":\n"; @@ -226,8 +233,9 @@ <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 given below. If you are comfortable with - reading the new function names, this version is recommended as an example. + transformation functions mentioned below. If you are comfortable + with reading the new function names, this version is recommended + as an example. </P> <P>Return <A HREF="#top">to top of page</A> or <A HREF="../faq/index.html">to the FAQ</A>. @@ -240,30 +248,45 @@ to all upper case." The word transformations is especially apt, because the standard template function <TT>transform<></TT> is used. + </P> + <P>This code will go through some iterations (no pun). Here's the + simplistic version usually seen on Usenet: <PRE> - #include <string> - #include <algorithm> - #include <cctype> // old <ctype.h> - std::string s ("Some Kind Of Initial Input Goes Here"); - - // Change everything into upper case - std::transform (s.begin(), s.end(), s.begin(), toupper); - - // Change everything into lower case - std::transform (s.begin(), s.end(), s.begin(), tolower); - - // Change everything back into upper case, but store the - // result in a different string - std::string capital_s; - capital_s.reserve(s.size()); - std::transform (s.begin(), s.end(), capital_s.begin(), tolower); </PRE> + #include <string> + #include <algorithm> + #include <cctype> // old <ctype.h> + + std::string s ("Some Kind Of Initial Input Goes Here"); + + // Change everything into upper case + std::transform (s.begin(), s.end(), s.begin(), toupper); + + // Change everything into lower case + std::transform (s.begin(), s.end(), s.begin(), tolower); + + // Change everything back into upper case, but store the + // result in a different string + std::string capital_s; + capital_s.reserve(s.size()); + 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 only if you're using English text (bummer). A much better and - more portable solution is to use a facet for a particular locale - and call its conversion functions. (These are discussed more in - Chapter 22.) + 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 + </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 + 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 like transformations, this task is trivial with the use of string's @@ -297,7 +320,7 @@ Comments and suggestions are welcome, and may be sent to <A HREF="mailto:pme@sources.redhat.com">Phil Edwards</A> or <A HREF="mailto:gdr@egcs.cygnus.com">Gabriel Dos Reis</A>. -<BR> $Id: howto.html,v 1.2 2000/07/07 21:13:28 pme Exp $ +<BR> $Id: howto.html,v 1.3 2000/07/11 21:45:07 pme Exp $ </EM></P> diff --git a/libstdc++-v3/docs/22_locale/howto.html b/libstdc++-v3/docs/22_locale/howto.html index c464bf1..2a438ed 100644 --- a/libstdc++-v3/docs/22_locale/howto.html +++ b/libstdc++-v3/docs/22_locale/howto.html @@ -9,7 +9,7 @@ <TITLE>libstdc++-v3 HOWTO: Chapter 22</TITLE> <LINK REL="home" HREF="http://sources.redhat.com/libstdc++/docs/22_locale/"> <LINK REL=StyleSheet HREF="../lib3styles.css"> -<!-- $Id: howto.html,v 1.3 2000/08/25 08:52:56 bkoz Exp $ --> +<!-- $Id: howto.html,v 1.4 2000/08/31 01:17:53 bkoz Exp $ --> </HEAD> <BODY> @@ -27,6 +27,7 @@ <LI><A HREF="#2">Nathan Myers on Locales</A> <LI><A HREF="#3">codecvt</A> <LI><A HREF="#4">ctype</A> + <LI><A HREF="#5">Correct Transformations</A> </UL> <HR> @@ -41,6 +42,14 @@ Programming Language (3rd Edition)</A>. It is a detailed description of locales and how to use them. </P> + <P>He also writes: + <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> <P>Return <A HREF="#top">to top of page</A> or <A HREF="../faq/index.html">to the FAQ</A>. </P> @@ -92,6 +101,114 @@ functionality are given. <A HREF="../faq/index.html">to the FAQ</A>. </P> +<HR> +<H2><A NAME="5">Correct Transformations</A></H2> + <!-- Jumping directly here from chapter 21. --> + <P>A very common question on newsgroups and mailing lists is, "How + do I do <foo> to a character string?" where <foo> is + a task such as changing all the letters to uppercase, to lowercase, + testing for digits, etc. A skilled and conscientious programmer + will follow the question with another, "And how do I make the + code portable?" + </P> + <P>(Poor innocent programmer, you have no idea the depths of trouble + you are getting yourself into. 'Twould be best for your sanity if + you dropped the whole idea and took up basket weaving instead. No? + Fine, you asked for it...) + </P> + <P>The task of changing the case of a letter or classifying a character + as numeric, graphical, etc, all depends on the cultural context of the + program at runtime. So, first you must take the portability question + into account. Once you have localized the program to a particular + natural language, only then can you perform the specific task. + Unfortunately, specializing a function for a human language is not + as simple as declaring + <TT> extern "Danish" int tolower (int); </TT>. + </P> + <P>The C++ code to do all this proceeds in the same way. First, a locale + 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: + <PRE> + namespace std { + template <class charT> + charT + toupper (charT c, const locale& loc) const; + template <class charT> + charT + tolower (charT c, const locale& loc) const; + }</PRE> + This function extracts the appropriate "facet" 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 + is returned. + </P> + <P>For the C/POSIX locale, the results are the same as calling the + classic C <TT>toupper/tolower</TT> function that was used in previous + examples. For other locales, the code should Do The Right Thing. + </P> + <P>Of course, these functions take a second argument, and the + transformation algorithm's operator argument can only take a single + 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: + <PRE> + #include <iterator> // for back_inserter + #include <locale> + #include <string> + #include <algorithm> + #include <cctype> // old <ctype.h> + + struct Toupper + { + Toupper (std::locale const& l) : loc(l) {;} + char operator() (char c) { return std::toupper(c,loc); } + private: + std::locale const& loc; + }; + + struct Tolower + { + Tolower (std::locale const& l) : loc(l) {;} + char operator() (char c) { return std::tolower(c,loc); } + private: + std::locale const& loc; + }; + + int main () + { + std::string s ("Some Kind Of Initial Input Goes Here"); + Toupper up ( std::locale("C") ); + Tolower down ( std::locale("C") ); + + // 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 back into upper case, but store the + // result in a different string + std::string capital_s; + std::transform (s.begin(), s.end(), std::back_inserter(capital_s), + up + ); + }</PRE> + </P> + <P>The final version of the code uses <TT>bind2nd</TT> to eliminate + the wrapper structs, but the resulting code is tricky. I have not + shown it here because no compilers currently available to me will + handle it. + </P> + <P>Return <A HREF="#top">to top of page</A> or + <A HREF="../faq/index.html">to the FAQ</A>. + </P> + + <!-- ####################################################### --> @@ -101,7 +218,7 @@ functionality are given. Comments and suggestions are welcome, and may be sent to <A HREF="mailto:pme@sources.redhat.com">Phil Edwards</A> or <A HREF="mailto:gdr@egcs.cygnus.com">Gabriel Dos Reis</A>. -<BR> $Id: howto.html,v 1.3 2000/08/25 08:52:56 bkoz Exp $ +<BR> $Id: howto.html,v 1.4 2000/08/31 01:17:53 bkoz Exp $ </EM></P> diff --git a/libstdc++-v3/docs/thanks.html b/libstdc++-v3/docs/thanks.html index 27a3f87..54d4fca 100644 --- a/libstdc++-v3/docs/thanks.html +++ b/libstdc++-v3/docs/thanks.html @@ -92,12 +92,13 @@ <P>We'd also like to thank the folks who have contributed time and energy in testing libstdc++-v3, especially those sending in testsuite - evaluations: + evaluations and documentation corrections: <UL> <LI>Levente Farkas <LI>Jürgen Freyh + <LI>James Kanze <LI>llewelly <!-- Honest, that's the only name in the messages. --> <LI>Loren James Rittle <LI>George Talbot |