diff --git a/libstdc++-v3/doc/html/manual/strings.html b/libstdc++-v3/doc/html/manual/strings.html index 34a34dfa980..5344d0e8923 100644 --- a/libstdc++-v3/doc/html/manual/strings.html +++ b/libstdc++-v3/doc/html/manual/strings.html @@ -50,10 +50,12 @@

Note that these calls all involve the global C locale through the use of the C functions - toupper/tolower. This is absolutely guaranteed to work -- - but only if the string contains only characters - from the basic source character set, and there are only - 96 of those. Which means that not even all English text can be + toupper/tolower. + This is absolutely guaranteed to work + -- but only if the string contains + only characters from the basic source character set, + and there are only 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. @@ -73,7 +75,14 @@ // std::tolower(c) is undefined if c < 0 so cast to unsigned char. return std::tolower((unsigned char)c); }

(Thanks to James Kanze for assistance and suggestions on all of this.) -

Another common operation is trimming off excess whitespace. Much +

+ Since C++11 the wrapper can be replaced with a lambda expression, + which can perform the conversion to unsigned char and + also ensure the single-argument form of std::lower is used: +

+     std::transform (s.begin(), s.end(), capital_s.begin(),
+                     [](unsigned char c) { return std::tolower(c); });
+   

Another common operation is trimming off excess whitespace. Much like transformations, this task is trivial with the use of string's find family. These examples are broken into multiple statements for readability: diff --git a/libstdc++-v3/doc/xml/manual/strings.xml b/libstdc++-v3/doc/xml/manual/strings.xml index 4a63dd96477..58a78d01d23 100644 --- a/libstdc++-v3/doc/xml/manual/strings.xml +++ b/libstdc++-v3/doc/xml/manual/strings.xml @@ -66,10 +66,12 @@ Note that these calls all involve the global C locale through the use of the C functions - toupper/tolower. This is absolutely guaranteed to work -- - but only if the string contains only characters - from the basic source character set, and there are only - 96 of those. Which means that not even all English text can be + toupper/tolower. + This is absolutely guaranteed to work + -- but only if the string contains + only characters from the basic source character set, + and there are only 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. @@ -93,6 +95,15 @@ } (Thanks to James Kanze for assistance and suggestions on all of this.) + + Since C++11 the wrapper can be replaced with a lambda expression, + which can perform the conversion to unsigned char and + also ensure the single-argument form of std::lower is used: + + + std::transform (s.begin(), s.end(), capital_s.begin(), + [](unsigned char c) { return std::tolower(c); }); + Another common operation is trimming off excess whitespace. Much like transformations, this task is trivial with the use of string's find family. These examples are broken into multiple