regex_traits.hpp
来自「CGAL is a collaborative effort of severa」· HPP 代码 · 共 1,199 行 · 第 1/3 页
HPP
1,199 行
#if !defined(BOOST_NO_STD_LOCALE)namespace re_detail{template <class charT>struct message_data;template <>struct message_data<char>;template <>struct message_data<regex_wchar_type>;struct BOOST_REGEX_DECL cpp_regex_traits_base : public regex_traits_base{ enum char_class_type { char_class_none = 0, char_class_alnum = std::ctype_base::alnum, char_class_alpha = std::ctype_base::alpha, char_class_cntrl = std::ctype_base::cntrl, char_class_digit = std::ctype_base::digit, char_class_graph = std::ctype_base::graph, char_class_lower = std::ctype_base::lower, char_class_print = std::ctype_base::print, char_class_punct = std::ctype_base::punct, char_class_space = std::ctype_base::space, char_class_upper = std::ctype_base::upper, char_class_xdigit = std::ctype_base::xdigit, char_class_blank = 1<<12, char_class_underscore = 1<<13, char_class_word = std::ctype_base::alnum | char_class_underscore, char_class_unicode = 1<<14, char_class_all_base = char_class_alnum | char_class_alpha | char_class_cntrl | char_class_digit | char_class_graph | char_class_lower | char_class_print | char_class_punct | char_class_space | char_class_upper | char_class_xdigit }; static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s);protected: static char regex_message_cat[BOOST_REGEX_MAX_PATH];};} // namespace re_detailtemplate <class charT>class cpp_regex_traits;template<>class BOOST_REGEX_DECL cpp_regex_traits<char> : public re_detail::cpp_regex_traits_base{ typedef re_detail::cpp_regex_traits_base base_type;private: re_detail::message_data<char>* pmd; const unsigned char* psyntax; char* lower_map; const std::ctype<char>* pctype; const std::collate<char>* pcollate; std::locale locale_inst; unsigned sort_type; char sort_delim; cpp_regex_traits(const cpp_regex_traits&); cpp_regex_traits& operator=(const cpp_regex_traits&);public: typedef char char_type; typedef unsigned char uchar_type; typedef unsigned int size_type; typedef std::string string_type; typedef std::locale locale_type; cpp_regex_traits(); ~cpp_regex_traits(); static std::size_t BOOST_REGEX_CALL length(const char_type* p) { return std::strlen(p); } unsigned int BOOST_REGEX_CALL syntax_type(size_type c)const { return psyntax[c]; } char BOOST_REGEX_CALL translate(char c, bool icase)const { return icase ? lower_map[(size_type)(uchar_type)c] : c; } void BOOST_REGEX_CALL transform(std::string& out, const std::string& in)const { out = pcollate->transform(in.c_str(), in.c_str() + in.size()).c_str(); } void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in)const; static bool BOOST_REGEX_CALL is_separator(char c) { return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r')); } static bool BOOST_REGEX_CALL is_combining(char) { return false; } bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f)const { if(pctype->is((std::ctype<char>::mask)(f & char_class_all_base), c)) return true; if((f & char_class_underscore) && (c == '_')) return true; if((f & char_class_blank) && ((c == ' ') || (c == '\t'))) return true; return false; } int BOOST_REGEX_CALL toi(char c)const; int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix)const; boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last)const; bool BOOST_REGEX_CALL lookup_collatename(std::string& s, const char* first, const char* last)const; std::string BOOST_REGEX_CALL error_string(unsigned id)const; locale_type BOOST_REGEX_CALL imbue(locale_type l); locale_type BOOST_REGEX_CALL getloc()const{ return locale_inst; } void swap(cpp_regex_traits&); struct sentry { sentry(const cpp_regex_traits<char>&){} operator void*() { return this; } };};#if !defined(BOOST_NO_WREGEX) && !defined(BOOST_NO_STD_WSTREAMBUF)template<>class BOOST_REGEX_DECL cpp_regex_traits<regex_wchar_type> : public re_detail::cpp_regex_traits_base{ typedef re_detail::cpp_regex_traits_base base_type;public: typedef regex_wchar_type char_type; typedef unsigned short uchar_type; typedef unsigned int size_type; typedef std::basic_string<regex_wchar_type> string_type; typedef std::locale locale_type;private: re_detail::message_data<regex_wchar_type>* pmd; const unsigned char* psyntax; regex_wchar_type* lower_map; const std::ctype<regex_wchar_type>* pctype; const std::collate<regex_wchar_type>* pcollate; const std::codecvt<regex_wchar_type, char, std::mbstate_t>* pcdv; std::locale locale_inst; unsigned int BOOST_REGEX_CALL do_syntax_type(size_type c)const; unsigned sort_type; regex_wchar_type sort_delim; cpp_regex_traits(const cpp_regex_traits&); cpp_regex_traits& operator=(const cpp_regex_traits&);public:#ifndef BOOST_REGEX_HAS_SHORT_WCHAR_T static std::size_t BOOST_REGEX_CALL length(const char_type* p) { return std::wcslen(p); }#else static std::size_t BOOST_REGEX_CALL length(const char_type* p) { return std::wcslen(reinterpret_cast<const wchar_t*>(p)); }#endif unsigned int BOOST_REGEX_CALL syntax_type(size_type c)const { return (c < UCHAR_MAX) ? psyntax[c] : do_syntax_type(c); } regex_wchar_type BOOST_REGEX_CALL translate(regex_wchar_type c, bool icase)const { return icase ? (((uchar_type)c) <= UCHAR_MAX) ? lower_map[c] : pctype->tolower(c) : c; } void BOOST_REGEX_CALL transform(std::basic_string<regex_wchar_type>& out, const std::basic_string<regex_wchar_type>& in)const { out = pcollate->transform(in.c_str(), in.c_str() + in.size()); } void BOOST_REGEX_CALL transform_primary(std::basic_string<regex_wchar_type>& out, const std::basic_string<regex_wchar_type>& in)const; static bool BOOST_REGEX_CALL is_separator(regex_wchar_type c) { return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (regex_wchar_type)0x2028) || (c == (regex_wchar_type)0x2029)); } static bool BOOST_REGEX_CALL is_combining(regex_wchar_type c) { return re_detail::is_combining(c); } bool BOOST_REGEX_CALL is_class(regex_wchar_type c, boost::uint_fast32_t f)const { if(pctype->is((std::ctype<regex_wchar_type>::mask)(f & char_class_all_base), c)) return true; if((f & char_class_underscore) && (c == '_')) return true; if((f & char_class_blank) && ((c == ' ') || (c == '\t'))) return true; if((f & char_class_unicode) && ((uchar_type)c > (uchar_type)255)) return true; return false; } int BOOST_REGEX_CALL toi(regex_wchar_type c)const; int BOOST_REGEX_CALL toi(const regex_wchar_type*& first, const regex_wchar_type* last, int radix)const; boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const regex_wchar_type* first, const regex_wchar_type* last)const; bool BOOST_REGEX_CALL lookup_collatename(std::basic_string<regex_wchar_type>& s, const regex_wchar_type* first, const regex_wchar_type* last)const; std::string BOOST_REGEX_CALL error_string(unsigned id)const; void swap(cpp_regex_traits&); cpp_regex_traits(); ~cpp_regex_traits(); locale_type BOOST_REGEX_CALL imbue(locale_type l); locale_type BOOST_REGEX_CALL getloc()const{ return locale_inst; } std::size_t BOOST_REGEX_CALL strwiden(regex_wchar_type *s1, std::size_t len, const char *s2)const; struct sentry { sentry(const cpp_regex_traits<regex_wchar_type>&){} operator void*() { return this; } };};#ifdef BOOST_REGEX_HAS_SHORT_WCHAR_T//// What follows here is Visual Studio specific - it is a thin wrapper// that redirects calls to cpp_regex_traits<unsigned short> to// cpp_regex_traits<__wchar_t>. This allows the library to be built// so that it supports programs built both with and without /Zc:wchar_t.//template<>class cpp_regex_traits<unsigned short> : public re_detail::cpp_regex_traits_base{ typedef re_detail::cpp_regex_traits_base base_type;public: typedef unsigned short char_type; typedef unsigned short uchar_type; typedef unsigned int size_type; typedef std::basic_string<unsigned short> string_type; typedef std::locale locale_type; static std::size_t BOOST_REGEX_CALL length(const char_type* p) { return cpp_regex_traits<regex_wchar_type>::length( reinterpret_cast<const regex_wchar_type*>(p)); } unsigned int BOOST_REGEX_CALL syntax_type(size_type c)const { return m_imp.syntax_type(c); } unsigned short BOOST_REGEX_CALL translate(unsigned short c, bool icase)const { return m_imp.translate(c, icase); } void BOOST_REGEX_CALL transform(std::basic_string<unsigned short>& out, const std::basic_string<unsigned short>& in)const { m_imp.transform( reinterpret_cast<std::basic_string<regex_wchar_type>&>(out), reinterpret_cast<const std::basic_string<regex_wchar_type>&>(in)); } void BOOST_REGEX_CALL transform_primary(std::basic_string<unsigned short>& out, const std::basic_string<unsigned short>& in)const { m_imp.transform_primary( reinterpret_cast<std::basic_string<regex_wchar_type>&>(out), reinterpret_cast<const std::basic_string<regex_wchar_type>&>(in)); } static bool BOOST_REGEX_CALL is_separator(unsigned short c) { return cpp_regex_traits<regex_wchar_type>::is_separator(c); } static bool BOOST_REGEX_CALL is_combining(unsigned short c) { return cpp_regex_traits<regex_wchar_type>::is_combining(c); } bool BOOST_REGEX_CALL is_class(unsigned short c, boost::uint_fast32_t f)const { return m_imp.is_class(c, f); } int BOOST_REGEX_CALL toi(unsigned short c)const { return m_imp.toi(c); } int BOOST_REGEX_CALL toi(const unsigned short*& first, const unsigned short* last, int radix)const { return m_imp.toi( reinterpret_cast<const regex_wchar_type*&>(first), reinterpret_cast<const regex_wchar_type*>(last), radix); } boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const unsigned short* first, const unsigned short* last)const { return m_imp.lookup_classname( reinterpret_cast<const regex_wchar_type*>(first), reinterpret_cast<const regex_wchar_type*>(last)); } bool BOOST_REGEX_CALL lookup_collatename(std::basic_string<unsigned short>& s, const unsigned short* first, const unsigned short* last)const { return m_imp.lookup_collatename( reinterpret_cast<std::basic_string<regex_wchar_type>&>(s), reinterpret_cast<const regex_wchar_type*>(first), reinterpret_cast<const regex_wchar_type*>(last)); } locale_type BOOST_REGEX_CALL imbue(locale_type l) { return m_imp.imbue(l); } locale_type BOOST_REGEX_CALL getloc()const { return m_imp.getloc(); } struct sentry { sentry(const cpp_regex_traits<unsigned short>&){} operator void*() { return this; } }; void swap(cpp_regex_traits& that) { m_imp.swap(that.m_imp); } cpp_regex_traits(){}; ~cpp_regex_traits(){}; std::size_t BOOST_REGEX_CALL strwiden(unsigned short *s1, std::size_t len, const char *s2)const { return m_imp.strwiden( reinterpret_cast<regex_wchar_type *>(s1), len, s2); } std::string BOOST_REGEX_CALL error_string(unsigned id)const { return m_imp.error_string(id); }private: cpp_regex_traits<regex_wchar_type> m_imp;};#endif // BOOST_REGEX_HAS_SHORT_WCHAR_T#endif // BOOST_NO_WREGEX#endif // BOOST_NO_STD_LOCALE#ifdef BOOST_REGEX_USE_WIN32_LOCALEtemplate <class charT>class regex_traits : public w32_regex_traits<charT>{};#elif defined(BOOST_REGEX_USE_C_LOCALE)template <class charT>class regex_traits : public c_regex_traits<charT>{};#elif defined(BOOST_REGEX_USE_CPP_LOCALE)template <class charT>class regex_traits : public cpp_regex_traits<charT>{};#else#error No default localisation model defined#endif#ifdef BOOST_HAS_ABI_HEADERS# include BOOST_ABI_SUFFIX#endif} // namespace boost#endif // include
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?