]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/locale/examples/wboundary.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / locale / examples / wboundary.cpp
1 //
2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8
9 //
10 // ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
11 //
12 // BIG FAT WARNING FOR Microsoft Visual Studio Users
13 //
14 // YOU NEED TO CONVERT THIS SOURCE FILE ENCODING TO UTF-8 WITH BOM ENCODING.
15 //
16 // Unfortunately MSVC understands that the source code is encoded as
17 // UTF-8 only if you add useless BOM in the beginning.
18 //
19 // So, before you compile "wide" examples with MSVC, please convert them to text
20 // files with BOM. There are two very simple ways to do it:
21 //
22 // 1. Open file with Notepad and save it from there. It would convert
23 // it to file with BOM.
24 // 2. In Visual Studio go File->Advances Save Options... and select
25 // Unicode (UTF-8 with signature) Codepage 65001
26 //
27 // Note: once converted to UTF-8 with BOM, this source code would not
28 // compile with other compilers, because no-one uses BOM with UTF-8 today
29 // because it is absolutely meaningless in context of UTF-8.
30 //
31 // ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
32 //
33 #include <boost/locale.hpp>
34 #include <iostream>
35 #include <cassert>
36 #include <ctime>
37
38 int main()
39 {
40 using namespace boost::locale;
41 using namespace std;
42
43 // Create system default locale
44 generator gen;
45 locale loc=gen("");
46 locale::global(loc);
47 wcout.imbue(loc);
48
49 // This is needed to prevent C library to
50 // convert strings to narrow
51 // instead of C++ on some platforms
52 std::ios_base::sync_with_stdio(false);
53
54
55 wstring text=L"Hello World! あにま! Linux2.6 and Windows7 is word and number. שָלוֹם עוֹלָם!";
56
57 wcout<<text<<endl;
58
59 boundary::wssegment_index index(boundary::word,text.begin(),text.end());
60 boundary::wssegment_index::iterator p,e;
61
62 for(p=index.begin(),e=index.end();p!=e;++p) {
63 wcout<<L"Part ["<<*p<<L"] has ";
64 if(p->rule() & boundary::word_number)
65 wcout<<L"number(s) ";
66 if(p->rule() & boundary::word_letter)
67 wcout<<L"letter(s) ";
68 if(p->rule() & boundary::word_kana)
69 wcout<<L"kana character(s) ";
70 if(p->rule() & boundary::word_ideo)
71 wcout<<L"ideographic character(s) ";
72 if(p->rule() & boundary::word_none)
73 wcout<<L"no word characters";
74 wcout<<endl;
75 }
76
77 index.map(boundary::character,text.begin(),text.end());
78
79 for(p=index.begin(),e=index.end();p!=e;++p) {
80 wcout<<L"|" <<*p ;
81 }
82 wcout<<L"|\n\n";
83
84 index.map(boundary::line,text.begin(),text.end());
85
86 for(p=index.begin(),e=index.end();p!=e;++p) {
87 wcout<<L"|" <<*p ;
88 }
89 wcout<<L"|\n\n";
90
91 index.map(boundary::sentence,text.begin(),text.end());
92
93 for(p=index.begin(),e=index.end();p!=e;++p) {
94 wcout<<L"|" <<*p ;
95 }
96 wcout<<"|\n\n";
97
98 }
99
100
101 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
102
103 // boostinspect:noascii
104