mirror of
https://github.com/boostorg/locale.git
synced 2026-01-19 04:22:08 +00:00
116 lines
6.3 KiB
HTML
116 lines
6.3 KiB
HTML
<!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">
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||
<title>Boost.Locale: conversions.cpp</title>
|
||
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
||
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
|
||
<!--
|
||
Switch the lines for stand alone version
|
||
<link rel="stylesheet" type="text/css" href="http://www.boost.org/style-v2/section-basic.css">
|
||
-->
|
||
<link rel="stylesheet" type="text/css" href="../style/section-basic.css">
|
||
</head>
|
||
<body>
|
||
<div id="boost-common-heading-doc">
|
||
<div class="heading-inner">
|
||
<div class="heading-placard"></div>
|
||
|
||
<h1 class="heading-title">
|
||
<a href="http://www.boost.org/">
|
||
<!--
|
||
Switch the lines for stand alone version
|
||
<img src="http://www.boost.org/gfx/space.png" alt= "Boost C++ Libraries" class="heading-logo" />
|
||
-->
|
||
<img src="../style/space.png" alt= "Boost C++ Libraries" class="heading-logo" />
|
||
<span class="heading-boost">Boost</span>
|
||
<span class="heading-cpplibraries">C++ Libraries</span>
|
||
</a>
|
||
</h1>
|
||
|
||
<p class="heading-quote">
|
||
|
||
<q>...one of the most highly
|
||
regarded and expertly designed C++ library projects in the
|
||
world.</q>
|
||
|
||
<span class="heading-attribution">— <a href=
|
||
"http://www.gotw.ca/" class="external">Herb Sutter</a> and <a href=
|
||
"http://en.wikipedia.org/wiki/Andrei_Alexandrescu" class="external">Andrei
|
||
Alexandrescu</a>, <a href=
|
||
"http://safari.awprofessional.com/?XmlId=0321113586" class="external">C++
|
||
Coding Standards</a></span>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="boost-common-heading-doc-spacer"></div>
|
||
<!-- Generated by Doxygen 1.7.1 -->
|
||
<div class="navigation" id="top">
|
||
<div class="tabs">
|
||
<ul class="tablist">
|
||
<li><a href="main.html"><span>Main Page</span></a></li>
|
||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
||
<li><a href="annotated.html"><span>Classes</span></a></li>
|
||
<li><a href="files.html"><span>Files</span></a></li>
|
||
<li><a href="examples.html"><span>Examples</span></a></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div class="header">
|
||
<div class="headertitle">
|
||
<h1>conversions.cpp</h1> </div>
|
||
</div>
|
||
<div class="contents">
|
||
<p>Example of using various text conversion functions.</p>
|
||
<div class="fragment"><pre class="fragment"><span class="comment">//</span>
|
||
<span class="comment">// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)</span>
|
||
<span class="comment">//</span>
|
||
<span class="comment">// Distributed under the Boost Software License, Version 1.0. (See</span>
|
||
<span class="comment">// accompanying file LICENSE_1_0.txt or copy at</span>
|
||
<span class="comment">// http://www.boost.org/LICENSE_1_0.txt)</span>
|
||
<span class="comment">//</span>
|
||
<span class="preprocessor">#include <boost/locale.hpp></span>
|
||
<span class="preprocessor">#include <boost/algorithm/string/case_conv.hpp></span>
|
||
<span class="preprocessor">#include <iostream></span>
|
||
|
||
<span class="preprocessor">#include <ctime></span>
|
||
|
||
|
||
|
||
<span class="keywordtype">int</span> main()
|
||
{
|
||
<span class="keyword">using namespace </span>boost::locale;
|
||
<span class="keyword">using namespace </span>std;
|
||
<span class="comment">// Create system default locale</span>
|
||
<a name="_a0"></a><a class="code" href="classboost_1_1locale_1_1generator.html" title="the major class used for locale generation">generator</a> gen;
|
||
locale loc=gen(<span class="stringliteral">""</span>);
|
||
locale::global(loc);
|
||
cout.imbue(loc);
|
||
|
||
|
||
cout<<<span class="stringliteral">"Correct case conversion can't be done by simple, character by character conversion"</span><<endl;
|
||
cout<<<span class="stringliteral">"because case conversion is context sensitive and not 1-to-1 conversion"</span><<endl;
|
||
cout<<<span class="stringliteral">"For example:"</span><<endl;
|
||
cout<<<span class="stringliteral">" German grüßen correctly converted to "</span><<<a name="a1"></a><a class="code" href="group__convert.html#ga7889a57e1bc1059fbb107db0781d0b6d">to_upper</a>(<span class="stringliteral">"grüßen"</span>)<<<span class="stringliteral">", instead of incorrect "</span>
|
||
<<boost::to_upper_copy(std::string(<span class="stringliteral">"grüßen"</span>))<<endl;
|
||
cout<<<span class="stringliteral">" where ß is replaced with SS"</span><<endl;
|
||
cout<<<span class="stringliteral">" Greek ὈΔΥΣΣΕΎΣ is correctly converted to "</span><<<a name="a2"></a><a class="code" href="group__convert.html#ga33de83f16ff2c09cac780977c6f67099">to_lower</a>(<span class="stringliteral">"ὈΔΥΣΣΕΎΣ"</span>)<<<span class="stringliteral">", instead of incorrect "</span>
|
||
<<boost::to_lower_copy(std::string(<span class="stringliteral">"ὈΔΥΣΣΕΎΣ"</span>))<<endl;
|
||
cout<<<span class="stringliteral">" where Σ is converted to σ or to ς, according to position in the word"</span><<endl;
|
||
cout<<<span class="stringliteral">"Such type of conversion just can be done using std::toupper that work on character base, also std::toupper is "</span><<endl;
|
||
cout<<<span class="stringliteral">"not even applicable when working with variable character length like in UTF-8 or UTF-16 limiting the correct "</span><<endl;
|
||
cout<<<span class="stringliteral">"behavior to unicode subset BMP or ASCII only"</span><<endl;
|
||
|
||
}
|
||
|
||
<span class="comment">// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4</span>
|
||
</pre></div> </div>
|
||
</div>
|
||
<hr class="footer"/><address class="footer"><small>
|
||
© 2009-2011 Artyom Beilis, Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License</a>, Version 1.0.
|
||
</small></address>
|
||
</body>
|
||
</html>
|