2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
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)
8 #ifndef BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED
9 #define BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED
11 #include <boost/locale/config.hpp>
12 #include <boost/locale/boundary/types.hpp>
14 # pragma warning(push)
15 # pragma warning(disable : 4275 4251 4231 4660)
28 /// \brief This namespae contains all operations required for boundary analysis of text
32 /// \addtogroup boundary
39 /// \brief This structure is used for representing boundary point
40 /// that follows the offset.
45 /// Create empty break point at beginning
53 /// Create empty break point at offset v.
54 /// it is useful for order comparison with other points.
56 break_info(size_t v) :
63 /// Offset from the beggining of the text where a break occurs.
67 /// The identification of this break point according to
68 /// various break types
73 /// Compare two break points' offset. Allows to search with
74 /// standard algorithms over the index.
76 bool operator<(break_info const &other) const
78 return offset < other.offset;
83 /// This type holds the analysis of the text - all its break points
86 typedef std::vector<break_info> index_type;
89 template<typename CharType>
90 class boundary_indexing;
92 #ifdef BOOST_LOCALE_DOXYGEN
94 /// \brief This facet generates an index for boundary analysis
97 /// It is specialized for 4 types of characters \c char_t, \c wchar_t, \c char16_t and \c char32_t
99 template<typename Char>
100 class BOOST_LOCALE_DECL boundary_indexing : public std::locale::facet {
103 /// Default constructor typical for facets
105 boundary_indexing(size_t refs=0) : std::locale::facet(refs)
109 /// Create index for boundary type \a t for text in range [begin,end)
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.
115 virtual index_type map(boundary_type t,Char const *begin,Char const *end) const = 0;
117 /// Identification of this facet
119 static std::locale::id id;
121 #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
122 std::locale::id& __get_id (void) const { return id; }
129 class BOOST_LOCALE_DECL boundary_indexing<char> : public std::locale::facet {
131 boundary_indexing(size_t refs=0) : std::locale::facet(refs)
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)
137 std::locale::id& __get_id (void) const { return id; }
142 class BOOST_LOCALE_DECL boundary_indexing<wchar_t> : public std::locale::facet {
144 boundary_indexing(size_t refs=0) : std::locale::facet(refs)
147 virtual index_type map(boundary_type t,wchar_t const *begin,wchar_t const *end) const = 0;
149 static std::locale::id id;
150 #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
151 std::locale::id& __get_id (void) const { return id; }
155 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
157 class BOOST_LOCALE_DECL boundary_indexing<char16_t> : public std::locale::facet {
159 boundary_indexing(size_t refs=0) : std::locale::facet(refs)
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)
165 std::locale::id& __get_id (void) const { return id; }
170 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
172 class BOOST_LOCALE_DECL boundary_indexing<char32_t> : public std::locale::facet {
174 boundary_indexing(size_t refs=0) : std::locale::facet(refs)
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)
180 std::locale::id& __get_id (void) const { return id; }
203 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4