1//
2// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3//
4// Distributed under the Boost Software License, Version 1.0.
5// https://www.boost.org/LICENSE_1_0.txt
6
7#include <boost/locale.hpp>
8#include <ctime>
9#include <iostream>
10
11int main()
12{
13 using namespace boost::locale;
14
15 generator gen;
16 // Make system default locale global
17 std::locale loc = gen("");
18 // We need the boundary facet, currently only available via ICU
19 if(!std::has_facet<boundary::boundary_indexing<char>>(loc: loc)) {
20 std::cout << "boundary detection not implemented in this environment\n";
21 return 0;
22 }
23 std::locale::global(loc: loc);
24 std::cout.imbue(loc: loc);
25
26 std::string text = "Hello World! あにま! Linux2.6 and Windows7 is word and number. שָלוֹם עוֹלָם!";
27
28 std::cout << text << std::endl;
29
30 boundary::ssegment_index index(boundary::word, text.begin(), text.end());
31
32 for(boundary::ssegment_index::iterator p = index.begin(), e = index.end(); p != e; ++p) {
33 std::cout << "Part [" << *p << "] has ";
34 if(p->rule() & boundary::word_number)
35 std::cout << "number(s) ";
36 if(p->rule() & boundary::word_letter)
37 std::cout << "letter(s) ";
38 if(p->rule() & boundary::word_kana)
39 std::cout << "kana character(s) ";
40 if(p->rule() & boundary::word_ideo)
41 std::cout << "ideographic character(s) ";
42 if(p->rule() & boundary::word_none)
43 std::cout << "no word characters";
44 std::cout << std::endl;
45 }
46
47 index.map(type: boundary::character, begin: text.begin(), end: text.end());
48
49 for(const boundary::ssegment& p : index)
50 std::cout << "|" << p;
51 std::cout << "|\n\n";
52
53 index.map(type: boundary::line, begin: text.begin(), end: text.end());
54
55 for(const boundary::ssegment& p : index)
56 std::cout << "|" << p;
57 std::cout << "|\n\n";
58
59 index.map(type: boundary::sentence, begin: text.begin(), end: text.end());
60
61 for(const boundary::ssegment& p : index)
62 std::cout << "|" << p;
63 std::cout << "|\n\n";
64}
65
66// boostinspect:noascii
67

source code of boost/libs/locale/examples/boundary.cpp