Boost.Locale
facets.hpp
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 #ifndef BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED
8 #define BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED
9 
10 #include <boost/locale/boundary/types.hpp>
11 #include <locale>
12 #include <vector>
13 
14 #ifdef BOOST_MSVC
15 # pragma warning(push)
16 # pragma warning(disable : 4275 4251 4231 4660)
17 #endif
18 
19 namespace boost {
20 
21  namespace locale {
22 
26  namespace boundary {
32 
33 
38  struct break_info {
39 
44  offset(0),
45  rule(0)
46  {
47  }
52  break_info(size_t v) :
53  offset(v),
54  rule(0)
55  {
56  }
57 
61  size_t offset;
67 
72  bool operator<(break_info const &other) const
73  {
74  return offset < other.offset;
75  }
76  };
77 
82  typedef std::vector<break_info> index_type;
83 
84 
85  template<typename CharType>
87 
88  #ifdef BOOST_LOCALE_DOXYGEN
89  template<typename Char>
96  class BOOST_LOCALE_DECL boundary_indexing : public std::locale::facet {
97  public:
101  boundary_indexing(size_t refs=0) : std::locale::facet(refs)
102  {
103  }
111  virtual index_type map(boundary_type t,Char const *begin,Char const *end) const = 0;
115  static std::locale::id id;
116 
117  #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
118  std::locale::id& __get_id (void) const { return id; }
119  #endif
120  };
121 
122  #else
123 
124  template<>
125  class BOOST_LOCALE_DECL boundary_indexing<char> : public std::locale::facet {
126  public:
127  boundary_indexing(size_t refs=0) : std::locale::facet(refs)
128  {
129  }
130  ~boundary_indexing();
131  virtual index_type map(boundary_type t,char const *begin,char const *end) const = 0;
132  static std::locale::id id;
133  #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
134  std::locale::id& __get_id (void) const { return id; }
135  #endif
136  };
137 
138  template<>
139  class BOOST_LOCALE_DECL boundary_indexing<wchar_t> : public std::locale::facet {
140  public:
141  boundary_indexing(size_t refs=0) : std::locale::facet(refs)
142  {
143  }
144  ~boundary_indexing();
145  virtual index_type map(boundary_type t,wchar_t const *begin,wchar_t const *end) const = 0;
146 
147  static std::locale::id id;
148  #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
149  std::locale::id& __get_id (void) const { return id; }
150  #endif
151  };
152 
153  #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
154  template<>
155  class BOOST_LOCALE_DECL boundary_indexing<char16_t> : public std::locale::facet {
156  public:
157  boundary_indexing(size_t refs=0) : std::locale::facet(refs)
158  {
159  }
160  ~boundary_indexing();
161  virtual index_type map(boundary_type t,char16_t const *begin,char16_t const *end) const = 0;
162  static std::locale::id id;
163  #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
164  std::locale::id& __get_id (void) const { return id; }
165  #endif
166  };
167  #endif
168 
169  #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
170  template<>
171  class BOOST_LOCALE_DECL boundary_indexing<char32_t> : public std::locale::facet {
172  public:
173  boundary_indexing(size_t refs=0) : std::locale::facet(refs)
174  {
175  }
176  ~boundary_indexing();
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; }
181  #endif
182  };
183  #endif
184 
185  #endif
186 
190 
191 
192  } // boundary
193 
194  } // locale
195 } // boost
196 
197 
198 #ifdef BOOST_MSVC
199 #pragma warning(pop)
200 #endif
201 
202 #endif
This facet generates an index for boundary analysis for a given text.
Definition: facets.hpp:86
boundary_type
Definition: types.hpp:38
break_info()
Definition: facets.hpp:43
break_info(size_t v)
Definition: facets.hpp:52
This structure is used for representing boundary point that follows the offset.
Definition: facets.hpp:38
uint32_t rule_type
Flags used with word boundary analysis – the type of the word, line or sentence boundary found.
Definition: types.hpp:50
rule_type rule
Definition: facets.hpp:66
boundary_indexing(size_t refs=0)
Definition: facets.hpp:101
static std::locale::id id
Definition: facets.hpp:115
size_t offset
Definition: facets.hpp:61
bool operator<(break_info const &other) const
Definition: facets.hpp:72
std::vector< break_info > index_type
Definition: facets.hpp:82