diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6921b7776971..4ddca7d81dc0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2000-09-19 Phil Edwards + + * 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 * 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 7f37026cfbe2..1b79cb734f85 100644 --- a/libstdc++-v3/docs/18_support/howto.html +++ b/libstdc++-v3/docs/18_support/howto.html @@ -9,7 +9,7 @@ libstdc++-v3 HOWTO: Chapter 18 - + @@ -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 Phil Edwards or Gabriel Dos Reis. -
$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 $

diff --git a/libstdc++-v3/docs/21_strings/howto.html b/libstdc++-v3/docs/21_strings/howto.html index 9e64cca9f40e..1875447cc9c3 100644 --- a/libstdc++-v3/docs/21_strings/howto.html +++ b/libstdc++-v3/docs/21_strings/howto.html @@ -9,7 +9,7 @@ libstdc++-v3 HOWTO: Chapter 21 - + @@ -42,7 +42,7 @@ are relying on special functons offered by the CString class.

Things are not as bad as they seem. In - this + this message, Joe Buck points out a few very important things:


@@ -41,6 +42,14 @@ Programming Language (3rd Edition). It is a detailed description of locales and how to use them.

+

He also writes: +

+ 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. +
+

Return to top of page or to the FAQ.

@@ -92,6 +101,114 @@ functionality are given. to the FAQ.

+
+

Correct Transformations

+ +

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?" +

+

(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...) +

+

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 + extern "Danish" int tolower (int); . +

+

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: +

+   namespace std {
+     template <class charT>
+       charT
+       toupper (charT c, const locale& loc) const;
+     template <class charT>
+       charT
+       tolower (charT c, const locale& loc) const;
+   }
+ This function extracts the appropriate "facet" from the + locale loc and calls the appropriate member function of that + facet, passing c as its argument. The resulting character + is returned. +

+

For the C/POSIX locale, the results are the same as calling the + classic C toupper/tolower function that was used in previous + examples. For other locales, the code should Do The Right Thing. +

+

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. +

+

The next-to-final version of the code started in Chapter 21 looks like: +

+   #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
+                     );
+   }
+

+

The final version of the code uses bind2nd 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. +

+

Return to top of page or + to the FAQ. +

+ + @@ -101,7 +218,7 @@ functionality are given. Comments and suggestions are welcome, and may be sent to Phil Edwards or Gabriel Dos Reis. -
$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 $

diff --git a/libstdc++-v3/docs/thanks.html b/libstdc++-v3/docs/thanks.html index 27a3f87032b9..54d4fcadb874 100644 --- a/libstdc++-v3/docs/thanks.html +++ b/libstdc++-v3/docs/thanks.html @@ -92,12 +92,13 @@

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: