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 { namespace locale {
20 
22  namespace boundary {
26 
29  struct break_info {
31  break_info() : offset(0), rule(0) {}
32 
35  break_info(size_t v) : offset(v), rule(0) {}
36 
38  size_t offset;
42 
45  bool operator<(const break_info& other) const { return offset < other.offset; }
46  };
47 
50  typedef std::vector<break_info> index_type;
51 
52  template<typename CharType>
54 
55 #ifdef BOOST_LOCALE_DOXYGEN
56  template<typename Char>
61  class BOOST_LOCALE_DECL boundary_indexing : public std::locale::facet {
62  public:
64  boundary_indexing(size_t refs = 0) : std::locale::facet(refs) {}
65 
71  virtual index_type map(boundary_type t, const Char* begin, const Char* end) const = 0;
72 
74  static std::locale::id id;
75  };
76 
77 #else
78 
79  template<>
80  class BOOST_LOCALE_DECL boundary_indexing<char> : public std::locale::facet {
81  public:
82  boundary_indexing(size_t refs = 0) : std::locale::facet(refs) {}
83  ~boundary_indexing();
84  virtual index_type map(boundary_type t, const char* begin, const char* end) const = 0;
85  static std::locale::id id;
86  };
87 
88  template<>
89  class BOOST_LOCALE_DECL boundary_indexing<wchar_t> : public std::locale::facet {
90  public:
91  boundary_indexing(size_t refs = 0) : std::locale::facet(refs) {}
92  ~boundary_indexing();
93  virtual index_type map(boundary_type t, const wchar_t* begin, const wchar_t* end) const = 0;
94 
95  static std::locale::id id;
96  };
97 
98 # ifdef BOOST_LOCALE_ENABLE_CHAR16_T
99  template<>
100  class BOOST_LOCALE_DECL boundary_indexing<char16_t> : public std::locale::facet {
101  public:
102  boundary_indexing(size_t refs = 0) : std::locale::facet(refs) {}
103  ~boundary_indexing();
104  virtual index_type map(boundary_type t, const char16_t* begin, const char16_t* end) const = 0;
105  static std::locale::id id;
106  };
107 # endif
108 
109 # ifdef BOOST_LOCALE_ENABLE_CHAR32_T
110  template<>
111  class BOOST_LOCALE_DECL boundary_indexing<char32_t> : public std::locale::facet {
112  public:
113  boundary_indexing(size_t refs = 0) : std::locale::facet(refs) {}
114  ~boundary_indexing();
115  virtual index_type map(boundary_type t, const char32_t* begin, const char32_t* end) const = 0;
116  static std::locale::id id;
117  };
118 # endif
119 
120 #endif
121 
123  } // namespace boundary
124 
125 }} // namespace boost::locale
126 
127 #ifdef BOOST_MSVC
128 # pragma warning(pop)
129 #endif
130 
131 #endif
This facet generates an index for boundary analysis for a given text.
Definition: facets.hpp:53
boundary_type
This type describes a possible boundary analysis alternatives.
Definition: types.hpp:30
break_info()
Create empty break point at beginning.
Definition: facets.hpp:31
break_info(size_t v)
Definition: facets.hpp:35
This structure is used for representing boundary points that follow the offset.
Definition: facets.hpp:29
uint32_t rule_type
Flags used with word boundary analysis – the type of the word, line or sentence boundary found.
Definition: types.hpp:40
bool operator<(const break_info &other) const
Definition: facets.hpp:45
rule_type rule
Definition: facets.hpp:41
boundary_indexing(size_t refs=0)
Default constructor typical for facets.
Definition: facets.hpp:64
static std::locale::id id
Identification of this facet.
Definition: facets.hpp:74
size_t offset
Offset from the beginning of the text where a break occurs.
Definition: facets.hpp:38
Generate boundary analysis facet.
std::vector< break_info > index_type
Definition: facets.hpp:50