1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2<html xmlns="http://www.w3.org/1999/xhtml"> 3<head> 4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> 5<meta http-equiv="X-UA-Compatible" content="IE=9"/> 6<meta name="generator" content="Doxygen 1.8.6"/> 7<title>Boost.Locale: wboundary.cpp</title> 8<link href="tabs.css" rel="stylesheet" type="text/css"/> 9<script type="text/javascript" src="jquery.js"></script> 10<script type="text/javascript" src="dynsections.js"></script> 11<link href="navtree.css" rel="stylesheet" type="text/css"/> 12<script type="text/javascript" src="resize.js"></script> 13<script type="text/javascript" src="navtree.js"></script> 14<script type="text/javascript"> 15 $(document).ready(initResizable); 16 $(window).load(resizeHeight); 17</script> 18<link href="doxygen.css" rel="stylesheet" type="text/css" /> 19</head> 20<body> 21<div id="top"><!-- do not remove this div, it is closed by doxygen! --> 22<div id="titlearea"> 23<table cellspacing="0" cellpadding="0"> 24 <tbody> 25 <tr style="height: 56px;"> 26 <td id="projectlogo"><img alt="Logo" src="boost-small.png"/></td> 27 <td style="padding-left: 0.5em;"> 28 <div id="projectname">Boost.Locale 29 </div> 30 </td> 31 </tr> 32 </tbody> 33</table> 34</div> 35<!-- end header part --> 36<!-- Generated by Doxygen 1.8.6 --> 37 <div id="navrow1" class="tabs"> 38 <ul class="tablist"> 39 <li><a href="index.html"><span>Main Page</span></a></li> 40 <li><a href="pages.html"><span>Related Pages</span></a></li> 41 <li><a href="modules.html"><span>Modules</span></a></li> 42 <li><a href="namespaces.html"><span>Namespaces</span></a></li> 43 <li><a href="annotated.html"><span>Classes</span></a></li> 44 <li><a href="files.html"><span>Files</span></a></li> 45 <li><a href="examples.html"><span>Examples</span></a></li> 46 </ul> 47 </div> 48</div><!-- top --> 49<div id="side-nav" class="ui-resizable side-nav-resizable"> 50 <div id="nav-tree"> 51 <div id="nav-tree-contents"> 52 <div id="nav-sync" class="sync"></div> 53 </div> 54 </div> 55 <div id="splitbar" style="-moz-user-select:none;" 56 class="ui-resizable-handle"> 57 </div> 58</div> 59<script type="text/javascript"> 60$(document).ready(function(){initNavTree('wboundary_8cpp-example.html','');}); 61</script> 62<div id="doc-content"> 63<div class="header"> 64 <div class="headertitle"> 65<div class="title">wboundary.cpp</div> </div> 66</div><!--header--> 67<div class="contents"> 68<p>Example of using segment_index over wide strings</p> 69<div class="fragment"><div class="line"><span class="comment">//</span></div> 70<div class="line"><span class="comment">// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)</span></div> 71<div class="line"><span class="comment">//</span></div> 72<div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0. (See</span></div> 73<div class="line"><span class="comment">// accompanying file LICENSE_1_0.txt or copy at</span></div> 74<div class="line"><span class="comment">// http://www.boost.org/LICENSE_1_0.txt)</span></div> 75<div class="line"><span class="comment">//</span></div> 76<div class="line"></div> 77<div class="line"><span class="comment">//</span></div> 78<div class="line"><span class="comment">// ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !</span></div> 79<div class="line"><span class="comment">//</span></div> 80<div class="line"><span class="comment">// BIG FAT WARNING FOR Microsoft Visual Studio Users</span></div> 81<div class="line"><span class="comment">//</span></div> 82<div class="line"><span class="comment">// YOU NEED TO CONVERT THIS SOURCE FILE ENCODING TO UTF-8 WITH BOM ENCODING.</span></div> 83<div class="line"><span class="comment">//</span></div> 84<div class="line"><span class="comment">// Unfortunately MSVC understands that the source code is encoded as</span></div> 85<div class="line"><span class="comment">// UTF-8 only if you add useless BOM in the beginning.</span></div> 86<div class="line"><span class="comment">//</span></div> 87<div class="line"><span class="comment">// So, before you compile "wide" examples with MSVC, please convert them to text</span></div> 88<div class="line"><span class="comment">// files with BOM. There are two very simple ways to do it:</span></div> 89<div class="line"><span class="comment">//</span></div> 90<div class="line"><span class="comment">// 1. Open file with Notepad and save it from there. It would convert </span></div> 91<div class="line"><span class="comment">// it to file with BOM.</span></div> 92<div class="line"><span class="comment">// 2. In Visual Studio go File->Advances Save Options... and select</span></div> 93<div class="line"><span class="comment">// Unicode (UTF-8 with signature) Codepage 65001</span></div> 94<div class="line"><span class="comment">//</span></div> 95<div class="line"><span class="comment">// Note: once converted to UTF-8 with BOM, this source code would not</span></div> 96<div class="line"><span class="comment">// compile with other compilers, because no-one uses BOM with UTF-8 today</span></div> 97<div class="line"><span class="comment">// because it is absolutely meaningless in context of UTF-8.</span></div> 98<div class="line"><span class="comment">//</span></div> 99<div class="line"><span class="comment">// ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !</span></div> 100<div class="line"><span class="comment">//</span></div> 101<div class="line"><span class="preprocessor">#include <boost/locale.hpp></span></div> 102<div class="line"><span class="preprocessor">#include <iostream></span></div> 103<div class="line"><span class="preprocessor">#include <cassert></span></div> 104<div class="line"><span class="preprocessor">#include <ctime></span></div> 105<div class="line"></div> 106<div class="line"><span class="keywordtype">int</span> main()</div> 107<div class="line">{</div> 108<div class="line"> <span class="keyword">using namespace </span>boost::locale;</div> 109<div class="line"> <span class="keyword">using namespace </span>std;</div> 110<div class="line"></div> 111<div class="line"> <span class="comment">// Create system default locale</span></div> 112<div class="line"> <a name="_a0"></a><a class="code" href="classboost_1_1locale_1_1generator.html">generator</a> gen;</div> 113<div class="line"> locale loc=gen(<span class="stringliteral">""</span>);</div> 114<div class="line"> locale::global(loc); </div> 115<div class="line"> wcout.imbue(loc);</div> 116<div class="line"> </div> 117<div class="line"> <span class="comment">// This is needed to prevent C library to</span></div> 118<div class="line"> <span class="comment">// convert strings to narrow </span></div> 119<div class="line"> <span class="comment">// instead of C++ on some platforms</span></div> 120<div class="line"> std::ios_base::sync_with_stdio(<span class="keyword">false</span>);</div> 121<div class="line"></div> 122<div class="line"></div> 123<div class="line"> wstring text=L<span class="stringliteral">"Hello World! あにま! Linux2.6 and Windows7 is word and number. שָלוֹם עוֹלָם!"</span>;</div> 124<div class="line"></div> 125<div class="line"> wcout<<text<<endl;</div> 126<div class="line"></div> 127<div class="line"> <a name="_a1"></a><a class="code" href="classboost_1_1locale_1_1boundary_1_1segment__index.html">boundary::wssegment_index</a> index(<a name="a2"></a><a class="code" href="group__boundary.html#gga15de9963ce9bb6037c8525901dfbf641a99aad8b8a5e25baa9f695abe5e574bb6">boundary::word</a>,text.begin(),text.end());</div> 128<div class="line"> <a class="code" href="group__boundary.html#gaf7a775e77dbbca3495e11d646df96fd2">boundary::wssegment_index::iterator</a> p,e;</div> 129<div class="line"></div> 130<div class="line"> <span class="keywordflow">for</span>(p=index.begin(),e=index.end();p!=e;++p) {</div> 131<div class="line"> wcout<<L<span class="stringliteral">"Part ["</span><<*p<<L<span class="stringliteral">"] has "</span>;</div> 132<div class="line"> <span class="keywordflow">if</span>(p->rule() & <a name="a3"></a><a class="code" href="group__boundary.html#gaac78a3a6b9e671e253a2591cb56a479b">boundary::word_number</a>)</div> 133<div class="line"> wcout<<L<span class="stringliteral">"number(s) "</span>;</div> 134<div class="line"> <span class="keywordflow">if</span>(p->rule() & <a name="a4"></a><a class="code" href="group__boundary.html#ga8b7e6ce2fcb185845fa85a1a4c42b3c4">boundary::word_letter</a>)</div> 135<div class="line"> wcout<<L<span class="stringliteral">"letter(s) "</span>;</div> 136<div class="line"> <span class="keywordflow">if</span>(p->rule() & <a name="a5"></a><a class="code" href="group__boundary.html#ga52d8c63e1f3f8c898c645352206a78ef">boundary::word_kana</a>)</div> 137<div class="line"> wcout<<L<span class="stringliteral">"kana character(s) "</span>;</div> 138<div class="line"> <span class="keywordflow">if</span>(p->rule() & <a name="a6"></a><a class="code" href="group__boundary.html#ga705ab96f9e62810c8ed977c90d404ef8">boundary::word_ideo</a>)</div> 139<div class="line"> wcout<<L<span class="stringliteral">"ideographic character(s) "</span>;</div> 140<div class="line"> <span class="keywordflow">if</span>(p->rule() & <a name="a7"></a><a class="code" href="group__boundary.html#ga90cf4f01b95658f659685377226677e7">boundary::word_none</a>)</div> 141<div class="line"> wcout<<L<span class="stringliteral">"no word characters"</span>;</div> 142<div class="line"> wcout<<endl;</div> 143<div class="line"> }</div> 144<div class="line"></div> 145<div class="line"> index.<a name="a8"></a><a class="code" href="group__boundary.html#gafa2a756b10d3522743204b45b794bb3e">map</a>(<a name="a9"></a><a class="code" href="group__boundary.html#gga15de9963ce9bb6037c8525901dfbf641ae80c964112541d88af9b875dafb6605d">boundary::character</a>,text.begin(),text.end());</div> 146<div class="line"></div> 147<div class="line"> <span class="keywordflow">for</span>(p=index.begin(),e=index.end();p!=e;++p) {</div> 148<div class="line"> wcout<<L<span class="stringliteral">"|"</span> <<*p ;</div> 149<div class="line"> }</div> 150<div class="line"> wcout<<L<span class="stringliteral">"|\n\n"</span>;</div> 151<div class="line"></div> 152<div class="line"> index.map(<a name="a10"></a><a class="code" href="group__boundary.html#gga15de9963ce9bb6037c8525901dfbf641a72895419fdd7219b3695cf0abd602ea4">boundary::line</a>,text.begin(),text.end());</div> 153<div class="line"></div> 154<div class="line"> <span class="keywordflow">for</span>(p=index.begin(),e=index.end();p!=e;++p) {</div> 155<div class="line"> wcout<<L<span class="stringliteral">"|"</span> <<*p ;</div> 156<div class="line"> }</div> 157<div class="line"> wcout<<L<span class="stringliteral">"|\n\n"</span>;</div> 158<div class="line"></div> 159<div class="line"> index.map(<a name="a11"></a><a class="code" href="group__boundary.html#gga15de9963ce9bb6037c8525901dfbf641a88aa1509eace7589f5df87d4694871e9">boundary::sentence</a>,text.begin(),text.end());</div> 160<div class="line"></div> 161<div class="line"> <span class="keywordflow">for</span>(p=index.begin(),e=index.end();p!=e;++p) {</div> 162<div class="line"> wcout<<L<span class="stringliteral">"|"</span> <<*p ;</div> 163<div class="line"> }</div> 164<div class="line"> wcout<<<span class="stringliteral">"|\n\n"</span>;</div> 165<div class="line"> </div> 166<div class="line">}</div> 167<div class="line"></div> 168<div class="line"></div> 169<div class="line"><span class="comment">// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4</span></div> 170<div class="line"></div> 171<div class="line"><span class="comment">// boostinspect:noascii</span></div> 172<div class="line"></div> 173</div><!-- fragment --> </div><!-- contents --> 174</div><!-- doc-content --> 175 176 <li class="footer"> 177© Copyright 2009-2012 Artyom Beilis, Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License</a>, Version 1.0. 178 </li> 179 </ul> 180 </div> 181</body> 182</html> 183