Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:44:55

0001 //
0002 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0.
0005 // https://www.boost.org/LICENSE_1_0.txt
0006 
0007 #ifndef BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED
0008 #define BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED
0009 
0010 #include <boost/locale/boundary/types.hpp>
0011 #include <boost/locale/detail/facet_id.hpp>
0012 #include <boost/locale/detail/is_supported_char.hpp>
0013 #include <locale>
0014 #include <vector>
0015 
0016 #ifdef BOOST_MSVC
0017 #    pragma warning(push)
0018 #    pragma warning(disable : 4275 4251 4231 4660)
0019 #endif
0020 
0021 namespace boost { namespace locale {
0022 
0023     /// \brief This namespace contains all operations required for boundary analysis of text
0024     namespace boundary {
0025         /// \addtogroup boundary
0026         ///
0027         /// @{
0028 
0029         /// \brief This structure is used for representing boundary points
0030         /// that follow the offset.
0031         struct break_info {
0032             /// Create empty break point at beginning
0033             break_info() : offset(0), rule(0) {}
0034 
0035             /// Create an empty break point at offset v.
0036             /// it is useful for order comparison with other points.
0037             break_info(size_t v) : offset(v), rule(0) {}
0038 
0039             /// Offset from the beginning of the text where a break occurs.
0040             size_t offset;
0041             /// The identification of this break point according to
0042             /// various break types
0043             rule_type rule;
0044 
0045             /// Compare two break points' offset. Allows to search with
0046             /// standard algorithms over the index.
0047             bool operator<(const break_info& other) const { return offset < other.offset; }
0048         };
0049 
0050         /// This type holds the analysis of the text - all its break points
0051         /// with marks
0052         typedef std::vector<break_info> index_type;
0053 
0054         /// \brief This facet generates an index for boundary analysis of a given text.
0055         ///
0056         /// It is implemented for supported character types, at least \c char, \c wchar_t
0057         template<typename Char>
0058         class BOOST_SYMBOL_VISIBLE boundary_indexing : public std::locale::facet,
0059                                                        public boost::locale::detail::facet_id<boundary_indexing<Char>> {
0060             BOOST_LOCALE_ASSERT_IS_SUPPORTED(Char);
0061 
0062         public:
0063             /// Default constructor typical for facets
0064             boundary_indexing(size_t refs = 0) : std::locale::facet(refs) {}
0065 
0066             /// Create index for boundary type \a t for text in range [begin,end)
0067             ///
0068             /// The returned value is an index of type \ref index_type. Note that this
0069             /// index is never empty, even if the range [begin,end) is empty it consists
0070             /// of at least one boundary point with the offset 0.
0071             virtual index_type map(boundary_type t, const Char* begin, const Char* end) const = 0;
0072         };
0073 
0074         /// @}
0075     } // namespace boundary
0076 
0077 }} // namespace boost::locale
0078 
0079 #ifdef BOOST_MSVC
0080 #    pragma warning(pop)
0081 #endif
0082 
0083 #endif