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 <boost/locale/detail/facet_id.hpp>
12#include <boost/locale/detail/is_supported_char.hpp>
13#include <locale>
14#include <vector>
15
16#ifdef BOOST_MSVC
17# pragma warning(push)
18# pragma warning(disable : 4275 4251 4231 4660)
19#endif
20
21namespace boost { namespace locale {
22
23 /// \brief This namespace contains all operations required for boundary analysis of text
24 namespace boundary {
25 /// \addtogroup boundary
26 ///
27 /// @{
28
29 /// \brief This structure is used for representing boundary points
30 /// that follow the offset.
31 struct break_info {
32 /// Create empty break point at beginning
33 break_info() : offset(0), rule(0) {}
34
35 /// Create an empty break point at offset v.
36 /// it is useful for order comparison with other points.
37 break_info(size_t v) : offset(v), rule(0) {}
38
39 /// Offset from the beginning of the text where a break occurs.
40 size_t offset;
41 /// The identification of this break point according to
42 /// various break types
43 rule_type rule;
44
45 /// Compare two break points' offset. Allows to search with
46 /// standard algorithms over the index.
47 bool operator<(const break_info& other) const { return offset < other.offset; }
48 };
49
50 /// This type holds the analysis of the text - all its break points
51 /// with marks
52 typedef std::vector<break_info> index_type;
53
54 /// \brief This facet generates an index for boundary analysis of a given text.
55 ///
56 /// It is implemented for supported character types, at least \c char, \c wchar_t
57 template<typename Char>
58 class BOOST_SYMBOL_VISIBLE boundary_indexing : public std::locale::facet,
59 public boost::locale::detail::facet_id<boundary_indexing<Char>> {
60 BOOST_LOCALE_ASSERT_IS_SUPPORTED(Char);
61
62 public:
63 /// Default constructor typical for facets
64 boundary_indexing(size_t refs = 0) : std::locale::facet(refs) {}
65
66 /// Create index for boundary type \a t for text in range [begin,end)
67 ///
68 /// The returned value is an index of type \ref index_type. Note that this
69 /// index is never empty, even if the range [begin,end) is empty it consists
70 /// of at least one boundary point with the offset 0.
71 virtual index_type map(boundary_type t, const Char* begin, const Char* end) const = 0;
72 };
73
74 /// @}
75 } // namespace boundary
76
77}} // namespace boost::locale
78
79#ifdef BOOST_MSVC
80# pragma warning(pop)
81#endif
82
83#endif
84

source code of boost/libs/locale/include/boost/locale/boundary/facets.hpp