• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED
9 #define BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED
10 
11 #include <boost/locale/config.hpp>
12 #include <boost/locale/boundary/types.hpp>
13 #ifdef BOOST_MSVC
14 #  pragma warning(push)
15 #  pragma warning(disable : 4275 4251 4231 4660)
16 #endif
17 #include <locale>
18 #include <vector>
19 
20 
21 
22 
23 namespace boost {
24 
25     namespace locale {
26 
27         ///
28         /// \brief This namespae contains all operations required for boundary analysis of text
29         ///
30         namespace boundary {
31             ///
32             /// \addtogroup boundary
33             ///
34             /// @{
35             ///
36 
37 
38             ///
39             /// \brief This structure is used for representing boundary point
40             /// that follows the offset.
41             ///
42             struct break_info {
43 
44                 ///
45                 /// Create empty break point at beginning
46                 ///
break_infoboost::locale::boundary::break_info47                 break_info() :
48                     offset(0),
49                     rule(0)
50                 {
51                 }
52                 ///
53                 /// Create empty break point at offset v.
54                 /// it is useful for order comparison with other points.
55                 ///
break_infoboost::locale::boundary::break_info56                 break_info(size_t v) :
57                     offset(v),
58                     rule(0)
59                 {
60                 }
61 
62                 ///
63                 /// Offset from the beggining of the text where a break occurs.
64                 ///
65                 size_t offset;
66                 ///
67                 /// The identification of this break point according to
68                 /// various break types
69                 ///
70                 rule_type rule;
71 
72                 ///
73                 /// Compare two break points' offset. Allows to search with
74                 /// standard algorithms over the index.
75                 ///
operator <boost::locale::boundary::break_info76                 bool operator<(break_info const &other) const
77                 {
78                     return offset < other.offset;
79                 }
80             };
81 
82             ///
83             /// This type holds the analysis of the text - all its break points
84             /// with marks
85             ///
86             typedef std::vector<break_info> index_type;
87 
88 
89             template<typename CharType>
90             class boundary_indexing;
91 
92             #ifdef BOOST_LOCALE_DOXYGEN
93             ///
94             /// \brief This facet generates an index for boundary analysis
95             /// for a given text.
96             ///
97             /// It is specialized for 4 types of characters \c char_t, \c wchar_t, \c char16_t and \c char32_t
98             ///
99             template<typename Char>
100             class BOOST_LOCALE_DECL boundary_indexing : public std::locale::facet {
101             public:
102                 ///
103                 /// Default constructor typical for facets
104                 ///
boundary_indexing(size_t refs=0)105                 boundary_indexing(size_t refs=0) : std::locale::facet(refs)
106                 {
107                 }
108                 ///
109                 /// Create index for boundary type \a t for text in range [begin,end)
110                 ///
111                 /// The returned value is an index of type \ref index_type. Note that this
112                 /// index is never empty, even if the range [begin,end) is empty it consists
113                 /// of at least one boundary point with the offset 0.
114                 ///
115                 virtual index_type map(boundary_type t,Char const *begin,Char const *end) const = 0;
116                 ///
117                 /// Identification of this facet
118                 ///
119                 static std::locale::id id;
120 
121                 #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
__get_id(void) const122                 std::locale::id& __get_id (void) const { return id; }
123                 #endif
124             };
125 
126             #else
127 
128             template<>
129             class BOOST_LOCALE_DECL boundary_indexing<char> : public std::locale::facet {
130             public:
boundary_indexing(size_t refs=0)131                 boundary_indexing(size_t refs=0) : std::locale::facet(refs)
132                 {
133                 }
134                 virtual index_type map(boundary_type t,char const *begin,char const *end) const = 0;
135                 static std::locale::id id;
136                 #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
__get_id(void) const137                 std::locale::id& __get_id (void) const { return id; }
138                 #endif
139             };
140 
141             template<>
142             class BOOST_LOCALE_DECL boundary_indexing<wchar_t> : public std::locale::facet {
143             public:
boundary_indexing(size_t refs=0)144                 boundary_indexing(size_t refs=0) : std::locale::facet(refs)
145                 {
146                 }
147                 virtual index_type map(boundary_type t,wchar_t const *begin,wchar_t const *end) const = 0;
148 
149                 static std::locale::id id;
150                 #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
__get_id(void) const151                 std::locale::id& __get_id (void) const { return id; }
152                 #endif
153             };
154 
155             #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
156             template<>
157             class BOOST_LOCALE_DECL boundary_indexing<char16_t> : public std::locale::facet {
158             public:
boundary_indexing(size_t refs=0)159                 boundary_indexing(size_t refs=0) : std::locale::facet(refs)
160                 {
161                 }
162                 virtual index_type map(boundary_type t,char16_t const *begin,char16_t const *end) const = 0;
163                 static std::locale::id id;
164                 #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
__get_id(void) const165                 std::locale::id& __get_id (void) const { return id; }
166                 #endif
167             };
168             #endif
169 
170             #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
171             template<>
172             class BOOST_LOCALE_DECL boundary_indexing<char32_t> : public std::locale::facet {
173             public:
boundary_indexing(size_t refs=0)174                 boundary_indexing(size_t refs=0) : std::locale::facet(refs)
175                 {
176                 }
177                 virtual index_type map(boundary_type t,char32_t const *begin,char32_t const *end) const = 0;
178                 static std::locale::id id;
179                 #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
__get_id(void) const180                 std::locale::id& __get_id (void) const { return id; }
181                 #endif
182             };
183             #endif
184 
185             #endif
186 
187             ///
188             /// @}
189             ///
190 
191 
192         } // boundary
193 
194     } // locale
195 } // boost
196 
197 
198 #ifdef BOOST_MSVC
199 #pragma warning(pop)
200 #endif
201 
202 #endif
203 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
204