diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2025-03-12 11:30:04 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2025-03-12 11:32:55 +0000 |
commit | 597ca24445462f11aaa3f7164a81f2f4f74bb80a (patch) | |
tree | 8ca58d5773ecb918dad6e7d2bd9db0fad9d7ee5c /libstdc++-v3/doc/html | |
parent | 503f10e34dcdeb8bd1cf78c2f14c7ac41cae31a5 (diff) | |
download | gcc-597ca24445462f11aaa3f7164a81f2f4f74bb80a.zip gcc-597ca24445462f11aaa3f7164a81f2f4f74bb80a.tar.gz gcc-597ca24445462f11aaa3f7164a81f2f4f74bb80a.tar.bz2 |
libstdc++: Add lambda example to case transformation docs
libstdc++-v3/ChangeLog:
* doc/xml/manual/strings.xml: Tweak formatting. Add example
using lambda.
* doc/html/manual/strings.html: Regenerate.
Diffstat (limited to 'libstdc++-v3/doc/html')
-rw-r--r-- | libstdc++-v3/doc/html/manual/strings.html | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/libstdc++-v3/doc/html/manual/strings.html b/libstdc++-v3/doc/html/manual/strings.html index 34a34df..5344d0e 100644 --- a/libstdc++-v3/doc/html/manual/strings.html +++ b/libstdc++-v3/doc/html/manual/strings.html @@ -50,10 +50,12 @@ </pre><p> <span class="emphasis"><em>Note</em></span> that these calls all involve the global C locale through the use of the C functions - <code class="code">toupper/tolower</code>. This is absolutely guaranteed to work -- - but <span class="emphasis"><em>only</em></span> if the string contains <span class="emphasis"><em>only</em></span> characters - from the basic source character set, and there are <span class="emphasis"><em>only</em></span> - 96 of those. Which means that not even all English text can be + <code class="code">toupper</code>/<code class="code">tolower</code>. + This is absolutely guaranteed to work + -- but <span class="emphasis"><em>only</em></span> if the string contains + <span class="emphasis"><em>only</em></span> characters from the basic source character set, + and there are <span class="emphasis"><em>only</em></span> 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); } </pre><p>(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> + Since C++11 the wrapper can be replaced with a lambda expression, + which can perform the conversion to <code class="code">unsigned char</code> and + also ensure the single-argument form of <code class="code">std::lower</code> is used: + </p><pre class="programlisting"> + std::transform (s.begin(), s.end(), capital_s.begin(), + [](unsigned char c) { return std::tolower(c); }); + </pre><p>Another common operation is trimming off excess whitespace. Much like transformations, this task is trivial with the use of string's <code class="code">find</code> family. These examples are broken into multiple statements for readability: |