Chris@16: // Chris@16: // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: #ifndef BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED Chris@16: #define BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED Chris@16: Chris@16: #include Chris@16: #include Chris@16: #ifdef BOOST_MSVC Chris@16: # pragma warning(push) Chris@16: # pragma warning(disable : 4275 4251 4231 4660) Chris@16: #endif Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: namespace locale { Chris@16: Chris@16: /// Chris@16: /// \brief This namespae contains all operations required for boundary analysis of text Chris@16: /// Chris@16: namespace boundary { Chris@16: /// Chris@16: /// \addtogroup boundary Chris@16: /// Chris@16: /// @{ Chris@16: /// Chris@16: Chris@16: Chris@16: /// Chris@16: /// \brief This structure is used for representing boundary point Chris@16: /// that follows the offset. Chris@16: /// Chris@16: struct break_info { Chris@16: Chris@16: /// Chris@16: /// Create empty break point at beginning Chris@16: /// Chris@16: break_info() : Chris@16: offset(0), Chris@16: rule(0) Chris@16: { Chris@16: } Chris@16: /// Chris@16: /// Create empty break point at offset v. Chris@16: /// it is useful for order comparison with other points. Chris@16: /// Chris@16: break_info(size_t v) : Chris@16: offset(v), Chris@16: rule(0) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Offset from the beggining of the text where a break occurs. Chris@16: /// Chris@16: size_t offset; Chris@16: /// Chris@16: /// The identification of this break point according to Chris@16: /// various break types Chris@16: /// Chris@16: rule_type rule; Chris@16: Chris@16: /// Chris@16: /// Compare two break points' offset. Allows to search with Chris@16: /// standard algorithms over the index. Chris@16: /// Chris@16: bool operator<(break_info const &other) const Chris@16: { Chris@16: return offset < other.offset; Chris@16: } Chris@16: }; Chris@16: Chris@16: /// Chris@16: /// This type holds the analysis of the text - all its break points Chris@16: /// with marks Chris@16: /// Chris@16: typedef std::vector index_type; Chris@16: Chris@16: Chris@16: template Chris@16: class boundary_indexing; Chris@16: Chris@16: #ifdef BOOST_LOCALE_DOXYGEN Chris@16: /// Chris@16: /// \brief This facet generates an index for boundary analysis Chris@16: /// for a given text. Chris@16: /// Chris@16: /// It is specialized for 4 types of characters \c char_t, \c wchar_t, \c char16_t and \c char32_t Chris@16: /// Chris@16: template Chris@16: class BOOST_LOCALE_DECL boundary_indexing : public std::locale::facet { Chris@16: public: Chris@16: /// Chris@16: /// Default constructor typical for facets Chris@16: /// Chris@16: boundary_indexing(size_t refs=0) : std::locale::facet(refs) Chris@16: { Chris@16: } Chris@16: /// Chris@16: /// Create index for boundary type \a t for text in range [begin,end) Chris@16: /// Chris@16: /// The returned value is an index of type \ref index_type. Note that this Chris@16: /// index is never empty, even if the range [begin,end) is empty it consists Chris@16: /// of at least one boundary point with the offset 0. Chris@16: /// Chris@16: virtual index_type map(boundary_type t,Char const *begin,Char const *end) const = 0; Chris@16: /// Chris@16: /// Identification of this facet Chris@16: /// Chris@16: static std::locale::id id; Chris@16: Chris@16: #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) Chris@16: std::locale::id& __get_id (void) const { return id; } Chris@16: #endif Chris@16: }; Chris@16: Chris@16: #else Chris@16: Chris@16: template<> Chris@16: class BOOST_LOCALE_DECL boundary_indexing : public std::locale::facet { Chris@16: public: Chris@16: boundary_indexing(size_t refs=0) : std::locale::facet(refs) Chris@16: { Chris@16: } Chris@16: virtual index_type map(boundary_type t,char const *begin,char const *end) const = 0; Chris@16: static std::locale::id id; Chris@16: #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) Chris@16: std::locale::id& __get_id (void) const { return id; } Chris@16: #endif Chris@16: }; Chris@16: Chris@16: template<> Chris@16: class BOOST_LOCALE_DECL boundary_indexing : public std::locale::facet { Chris@16: public: Chris@16: boundary_indexing(size_t refs=0) : std::locale::facet(refs) Chris@16: { Chris@16: } Chris@16: virtual index_type map(boundary_type t,wchar_t const *begin,wchar_t const *end) const = 0; Chris@16: Chris@16: static std::locale::id id; Chris@16: #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) Chris@16: std::locale::id& __get_id (void) const { return id; } Chris@16: #endif Chris@16: }; Chris@16: Chris@16: #ifdef BOOST_HAS_CHAR16_T Chris@16: template<> Chris@16: class BOOST_LOCALE_DECL boundary_indexing : public std::locale::facet { Chris@16: public: Chris@16: boundary_indexing(size_t refs=0) : std::locale::facet(refs) Chris@16: { Chris@16: } Chris@16: virtual index_type map(boundary_type t,char16_t const *begin,char16_t const *end) const = 0; Chris@16: static std::locale::id id; Chris@16: #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) Chris@16: std::locale::id& __get_id (void) const { return id; } Chris@16: #endif Chris@16: }; Chris@16: #endif Chris@16: Chris@16: #ifdef BOOST_HAS_CHAR32_T Chris@16: template<> Chris@16: class BOOST_LOCALE_DECL boundary_indexing : public std::locale::facet { Chris@16: public: Chris@16: boundary_indexing(size_t refs=0) : std::locale::facet(refs) Chris@16: { Chris@16: } Chris@16: virtual index_type map(boundary_type t,char32_t const *begin,char32_t const *end) const = 0; Chris@16: static std::locale::id id; Chris@16: #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) Chris@16: std::locale::id& __get_id (void) const { return id; } Chris@16: #endif Chris@16: }; Chris@16: #endif Chris@16: Chris@16: #endif Chris@16: Chris@16: /// Chris@16: /// @} Chris@16: /// Chris@16: Chris@16: Chris@16: } // boundary Chris@16: Chris@16: } // locale Chris@16: } // boost Chris@16: Chris@16: Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: #endif Chris@16: // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4