Chris@16: /* Chris@16: * Chris@16: * Copyright (c) 2004 Chris@16: * John Maddock Chris@16: * Chris@16: * Use, modification and distribution are subject to the Chris@16: * Boost Software License, Version 1.0. (See accompanying file Chris@16: * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Chris@16: */ Chris@16: Chris@16: /* Chris@16: * LOCATION: see http://www.boost.org for most recent version. Chris@16: * FILE w32_regex_traits.hpp Chris@16: * VERSION see Chris@16: * DESCRIPTION: Declares regular expression traits class w32_regex_traits. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_W32_REGEX_TRAITS_HPP_INCLUDED Chris@16: #define BOOST_W32_REGEX_TRAITS_HPP_INCLUDED Chris@16: Chris@16: #ifndef BOOST_RE_PAT_EXCEPT_HPP Chris@16: #include Chris@16: #endif Chris@16: #ifndef BOOST_REGEX_TRAITS_DEFAULTS_HPP_INCLUDED Chris@16: #include Chris@16: #endif Chris@16: #ifdef BOOST_HAS_THREADS Chris@16: #include Chris@16: #endif Chris@16: #ifndef BOOST_REGEX_PRIMARY_TRANSFORM Chris@16: #include Chris@16: #endif Chris@16: #ifndef BOOST_REGEX_OBJECT_CACHE_HPP Chris@16: #include Chris@16: #endif Chris@16: Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(push) Chris@16: #pragma warning(disable: 4103) Chris@16: #endif Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: # include BOOST_ABI_PREFIX Chris@16: #endif Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(push) Chris@16: #pragma warning(disable:4786) Chris@16: #pragma warning(disable:4800) Chris@16: #endif Chris@16: Chris@16: namespace boost{ Chris@16: Chris@16: // Chris@16: // forward declaration is needed by some compilers: Chris@16: // Chris@16: template Chris@16: class w32_regex_traits; Chris@16: Chris@16: namespace re_detail{ Chris@16: Chris@16: // Chris@16: // start by typedeffing the types we'll need: Chris@16: // Chris@16: typedef ::boost::uint32_t lcid_type; // placeholder for LCID. Chris@16: typedef ::boost::shared_ptr cat_type; // placeholder for dll HANDLE. Chris@16: Chris@16: // Chris@16: // then add wrappers around the actual Win32 API's (ie implementation hiding): Chris@16: // Chris@16: BOOST_REGEX_DECL lcid_type BOOST_REGEX_CALL w32_get_default_locale(); Chris@16: BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(char, lcid_type); Chris@16: #ifndef BOOST_NO_WREGEX Chris@16: BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(wchar_t, lcid_type); Chris@16: #ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T Chris@16: BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(unsigned short ca, lcid_type state_id); Chris@16: #endif Chris@16: #endif Chris@16: BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(char, lcid_type); Chris@16: #ifndef BOOST_NO_WREGEX Chris@16: BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(wchar_t, lcid_type); Chris@16: #ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T Chris@16: BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(unsigned short ca, lcid_type state_id); Chris@16: #endif Chris@16: #endif Chris@16: BOOST_REGEX_DECL cat_type BOOST_REGEX_CALL w32_cat_open(const std::string& name); Chris@16: BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type state_id, int i, const std::string& def); Chris@16: #ifndef BOOST_NO_WREGEX Chris@16: BOOST_REGEX_DECL std::wstring BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type state_id, int i, const std::wstring& def); Chris@16: #ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T Chris@16: BOOST_REGEX_DECL std::basic_string BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type, int i, const std::basic_string& def); Chris@16: #endif Chris@16: #endif Chris@16: BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_transform(lcid_type state_id, const char* p1, const char* p2); Chris@16: #ifndef BOOST_NO_WREGEX Chris@16: BOOST_REGEX_DECL std::wstring BOOST_REGEX_CALL w32_transform(lcid_type state_id, const wchar_t* p1, const wchar_t* p2); Chris@16: #ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T Chris@16: BOOST_REGEX_DECL std::basic_string BOOST_REGEX_CALL w32_transform(lcid_type state_id, const unsigned short* p1, const unsigned short* p2); Chris@16: #endif Chris@16: #endif Chris@16: BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_tolower(char c, lcid_type); Chris@16: #ifndef BOOST_NO_WREGEX Chris@16: BOOST_REGEX_DECL wchar_t BOOST_REGEX_CALL w32_tolower(wchar_t c, lcid_type); Chris@16: #ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T Chris@16: BOOST_REGEX_DECL unsigned short BOOST_REGEX_CALL w32_tolower(unsigned short c, lcid_type state_id); Chris@16: #endif Chris@16: #endif Chris@16: BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_toupper(char c, lcid_type); Chris@16: #ifndef BOOST_NO_WREGEX Chris@16: BOOST_REGEX_DECL wchar_t BOOST_REGEX_CALL w32_toupper(wchar_t c, lcid_type); Chris@16: #endif Chris@16: BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type, boost::uint32_t mask, char c); Chris@16: #ifndef BOOST_NO_WREGEX Chris@16: BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type, boost::uint32_t mask, wchar_t c); Chris@16: #ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T Chris@16: BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type state_id, boost::uint32_t m, unsigned short c); Chris@16: #endif Chris@16: #endif Chris@16: // Chris@16: // class w32_regex_traits_base: Chris@16: // acts as a container for locale and the facets we are using. Chris@16: // Chris@16: template Chris@16: struct w32_regex_traits_base Chris@16: { Chris@16: w32_regex_traits_base(lcid_type l) Chris@16: { imbue(l); } Chris@16: lcid_type imbue(lcid_type l); Chris@16: Chris@16: lcid_type m_locale; Chris@16: }; Chris@16: Chris@16: template Chris@16: inline lcid_type w32_regex_traits_base::imbue(lcid_type l) Chris@16: { Chris@16: lcid_type result(m_locale); Chris@16: m_locale = l; Chris@16: return result; Chris@16: } Chris@16: Chris@16: // Chris@16: // class w32_regex_traits_char_layer: Chris@16: // implements methods that require specialisation for narrow characters: Chris@16: // Chris@16: template Chris@16: class w32_regex_traits_char_layer : public w32_regex_traits_base Chris@16: { Chris@16: typedef std::basic_string string_type; Chris@16: typedef std::map map_type; Chris@16: typedef typename map_type::const_iterator map_iterator_type; Chris@16: public: Chris@16: w32_regex_traits_char_layer(const lcid_type l); Chris@16: Chris@16: regex_constants::syntax_type syntax_type(charT c)const Chris@16: { Chris@16: map_iterator_type i = m_char_map.find(c); Chris@16: return ((i == m_char_map.end()) ? 0 : i->second); Chris@16: } Chris@16: regex_constants::escape_syntax_type escape_syntax_type(charT c) const Chris@16: { Chris@16: map_iterator_type i = m_char_map.find(c); Chris@16: if(i == m_char_map.end()) Chris@16: { Chris@16: if(::boost::re_detail::w32_is_lower(c, this->m_locale)) return regex_constants::escape_type_class; Chris@16: if(::boost::re_detail::w32_is_upper(c, this->m_locale)) return regex_constants::escape_type_not_class; Chris@16: return 0; Chris@16: } Chris@16: return i->second; Chris@16: } Chris@16: charT tolower(charT c)const Chris@16: { Chris@16: return ::boost::re_detail::w32_tolower(c, this->m_locale); Chris@16: } Chris@16: bool isctype(boost::uint32_t mask, charT c)const Chris@16: { Chris@16: return ::boost::re_detail::w32_is(this->m_locale, mask, c); Chris@16: } Chris@16: Chris@16: private: Chris@16: string_type get_default_message(regex_constants::syntax_type); Chris@16: // TODO: use a hash table when available! Chris@16: map_type m_char_map; Chris@16: }; Chris@16: Chris@16: template Chris@16: w32_regex_traits_char_layer::w32_regex_traits_char_layer(::boost::re_detail::lcid_type l) Chris@16: : w32_regex_traits_base(l) Chris@16: { Chris@16: // we need to start by initialising our syntax map so we know which Chris@16: // character is used for which purpose: Chris@16: cat_type cat; Chris@16: std::string cat_name(w32_regex_traits::get_catalog_name()); Chris@16: if(cat_name.size()) Chris@16: { Chris@16: cat = ::boost::re_detail::w32_cat_open(cat_name); Chris@16: if(!cat) Chris@16: { Chris@16: std::string m("Unable to open message catalog: "); Chris@16: std::runtime_error err(m + cat_name); Chris@16: boost::re_detail::raise_runtime_error(err); Chris@16: } Chris@16: } Chris@16: // Chris@16: // if we have a valid catalog then load our messages: Chris@16: // Chris@16: if(cat) Chris@16: { Chris@16: for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i) Chris@16: { Chris@16: string_type mss = ::boost::re_detail::w32_cat_get(cat, this->m_locale, i, get_default_message(i)); Chris@16: for(typename string_type::size_type j = 0; j < mss.size(); ++j) Chris@16: { Chris@16: this->m_char_map[mss[j]] = i; Chris@16: } Chris@16: } Chris@16: } Chris@16: else Chris@16: { Chris@16: for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i) Chris@16: { Chris@16: const char* ptr = get_default_syntax(i); Chris@16: while(ptr && *ptr) Chris@16: { Chris@16: this->m_char_map[static_cast(*ptr)] = i; Chris@16: ++ptr; Chris@16: } Chris@16: } Chris@16: } Chris@16: } Chris@16: Chris@16: template Chris@16: typename w32_regex_traits_char_layer::string_type Chris@16: w32_regex_traits_char_layer::get_default_message(regex_constants::syntax_type i) Chris@16: { Chris@16: const char* ptr = get_default_syntax(i); Chris@16: string_type result; Chris@16: while(ptr && *ptr) Chris@16: { Chris@16: result.append(1, static_cast(*ptr)); Chris@16: ++ptr; Chris@16: } Chris@16: return result; Chris@16: } Chris@16: Chris@16: // Chris@16: // specialised version for narrow characters: Chris@16: // Chris@16: template <> Chris@16: class BOOST_REGEX_DECL w32_regex_traits_char_layer : public w32_regex_traits_base Chris@16: { Chris@16: typedef std::string string_type; Chris@16: public: Chris@16: w32_regex_traits_char_layer(::boost::re_detail::lcid_type l) Chris@16: : w32_regex_traits_base(l) Chris@16: { Chris@16: init(); Chris@16: } Chris@16: Chris@16: regex_constants::syntax_type syntax_type(char c)const Chris@16: { Chris@16: return m_char_map[static_cast(c)]; Chris@16: } Chris@16: regex_constants::escape_syntax_type escape_syntax_type(char c) const Chris@16: { Chris@16: return m_char_map[static_cast(c)]; Chris@16: } Chris@16: char tolower(char c)const Chris@16: { Chris@16: return m_lower_map[static_cast(c)]; Chris@16: } Chris@16: bool isctype(boost::uint32_t mask, char c)const Chris@16: { Chris@16: return m_type_map[static_cast(c)] & mask; Chris@16: } Chris@16: Chris@16: private: Chris@16: regex_constants::syntax_type m_char_map[1u << CHAR_BIT]; Chris@16: char m_lower_map[1u << CHAR_BIT]; Chris@16: boost::uint16_t m_type_map[1u << CHAR_BIT]; Chris@16: void init(); Chris@16: }; Chris@16: Chris@16: // Chris@16: // class w32_regex_traits_implementation: Chris@16: // provides pimpl implementation for w32_regex_traits. Chris@16: // Chris@16: template Chris@16: class w32_regex_traits_implementation : public w32_regex_traits_char_layer Chris@16: { Chris@16: public: Chris@16: typedef typename w32_regex_traits::char_class_type char_class_type; Chris@16: BOOST_STATIC_CONSTANT(char_class_type, mask_word = 0x0400); // must be C1_DEFINED << 1 Chris@16: BOOST_STATIC_CONSTANT(char_class_type, mask_unicode = 0x0800); // must be C1_DEFINED << 2 Chris@16: BOOST_STATIC_CONSTANT(char_class_type, mask_horizontal = 0x1000); // must be C1_DEFINED << 3 Chris@16: BOOST_STATIC_CONSTANT(char_class_type, mask_vertical = 0x2000); // must be C1_DEFINED << 4 Chris@16: BOOST_STATIC_CONSTANT(char_class_type, mask_base = 0x3ff); // all the masks used by the CT_CTYPE1 group Chris@16: Chris@16: typedef std::basic_string string_type; Chris@16: typedef charT char_type; Chris@16: w32_regex_traits_implementation(::boost::re_detail::lcid_type l); Chris@16: std::string error_string(regex_constants::error_type n) const Chris@16: { Chris@16: if(!m_error_strings.empty()) Chris@16: { Chris@16: std::map::const_iterator p = m_error_strings.find(n); Chris@16: return (p == m_error_strings.end()) ? std::string(get_default_error_string(n)) : p->second; Chris@16: } Chris@16: return get_default_error_string(n); Chris@16: } Chris@16: char_class_type lookup_classname(const charT* p1, const charT* p2) const Chris@16: { Chris@16: char_class_type result = lookup_classname_imp(p1, p2); Chris@16: if(result == 0) Chris@16: { Chris@16: typedef typename string_type::size_type size_type; Chris@16: string_type temp(p1, p2); Chris@16: for(size_type i = 0; i < temp.size(); ++i) Chris@16: temp[i] = this->tolower(temp[i]); Chris@16: result = lookup_classname_imp(&*temp.begin(), &*temp.begin() + temp.size()); Chris@16: } Chris@16: return result; Chris@16: } Chris@16: string_type lookup_collatename(const charT* p1, const charT* p2) const; Chris@16: string_type transform_primary(const charT* p1, const charT* p2) const; Chris@16: string_type transform(const charT* p1, const charT* p2) const Chris@16: { Chris@16: return ::boost::re_detail::w32_transform(this->m_locale, p1, p2); Chris@16: } Chris@16: private: Chris@16: std::map m_error_strings; // error messages indexed by numberic ID Chris@16: std::map m_custom_class_names; // character class names Chris@16: std::map m_custom_collate_names; // collating element names Chris@16: unsigned m_collate_type; // the form of the collation string Chris@16: charT m_collate_delim; // the collation group delimiter Chris@16: // Chris@16: // helpers: Chris@16: // Chris@16: char_class_type lookup_classname_imp(const charT* p1, const charT* p2) const; Chris@16: }; Chris@16: Chris@16: template Chris@16: typename w32_regex_traits_implementation::string_type Chris@16: w32_regex_traits_implementation::transform_primary(const charT* p1, const charT* p2) const Chris@16: { Chris@16: string_type result; Chris@16: // Chris@16: // What we do here depends upon the format of the sort key returned by Chris@16: // sort key returned by this->transform: Chris@16: // Chris@16: switch(m_collate_type) Chris@16: { Chris@16: case sort_C: Chris@16: case sort_unknown: Chris@16: // the best we can do is translate to lower case, then get a regular sort key: Chris@16: { Chris@16: result.assign(p1, p2); Chris@16: typedef typename string_type::size_type size_type; Chris@16: for(size_type i = 0; i < result.size(); ++i) Chris@16: result[i] = this->tolower(result[i]); Chris@16: result = this->transform(&*result.begin(), &*result.begin() + result.size()); Chris@16: break; Chris@16: } Chris@16: case sort_fixed: Chris@16: { Chris@16: // get a regular sort key, and then truncate it: Chris@16: result.assign(this->transform(p1, p2)); Chris@16: result.erase(this->m_collate_delim); Chris@16: break; Chris@16: } Chris@16: case sort_delim: Chris@16: // get a regular sort key, and then truncate everything after the delim: Chris@16: result.assign(this->transform(p1, p2)); Chris@16: std::size_t i; Chris@16: for(i = 0; i < result.size(); ++i) Chris@16: { Chris@16: if(result[i] == m_collate_delim) Chris@16: break; Chris@16: } Chris@16: result.erase(i); Chris@16: break; Chris@16: } Chris@16: if(result.empty()) Chris@16: result = string_type(1, charT(0)); Chris@16: return result; Chris@16: } Chris@16: Chris@16: template Chris@16: typename w32_regex_traits_implementation::string_type Chris@16: w32_regex_traits_implementation::lookup_collatename(const charT* p1, const charT* p2) const Chris@16: { Chris@16: typedef typename std::map::const_iterator iter_type; Chris@16: if(m_custom_collate_names.size()) Chris@16: { Chris@16: iter_type pos = m_custom_collate_names.find(string_type(p1, p2)); Chris@16: if(pos != m_custom_collate_names.end()) Chris@16: return pos->second; Chris@16: } Chris@16: #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\ Chris@16: && !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551) Chris@16: std::string name(p1, p2); Chris@16: #else Chris@16: std::string name; Chris@16: const charT* p0 = p1; Chris@16: while(p0 != p2) Chris@16: name.append(1, char(*p0++)); Chris@16: #endif Chris@16: name = lookup_default_collate_name(name); Chris@16: #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\ Chris@16: && !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551) Chris@16: if(name.size()) Chris@16: return string_type(name.begin(), name.end()); Chris@16: #else Chris@16: if(name.size()) Chris@16: { Chris@16: string_type result; Chris@16: typedef std::string::const_iterator iter; Chris@16: iter b = name.begin(); Chris@16: iter e = name.end(); Chris@16: while(b != e) Chris@16: result.append(1, charT(*b++)); Chris@16: return result; Chris@16: } Chris@16: #endif Chris@16: if(p2 - p1 == 1) Chris@16: return string_type(1, *p1); Chris@16: return string_type(); Chris@16: } Chris@16: Chris@16: template Chris@16: w32_regex_traits_implementation::w32_regex_traits_implementation(::boost::re_detail::lcid_type l) Chris@16: : w32_regex_traits_char_layer(l) Chris@16: { Chris@16: cat_type cat; Chris@16: std::string cat_name(w32_regex_traits::get_catalog_name()); Chris@16: if(cat_name.size()) Chris@16: { Chris@16: cat = ::boost::re_detail::w32_cat_open(cat_name); Chris@16: if(!cat) Chris@16: { Chris@16: std::string m("Unable to open message catalog: "); Chris@16: std::runtime_error err(m + cat_name); Chris@16: boost::re_detail::raise_runtime_error(err); Chris@16: } Chris@16: } Chris@16: // Chris@16: // if we have a valid catalog then load our messages: Chris@16: // Chris@16: if(cat) Chris@16: { Chris@16: // Chris@16: // Error messages: Chris@16: // Chris@16: for(boost::regex_constants::error_type i = static_cast(0); Chris@16: i <= boost::regex_constants::error_unknown; Chris@16: i = static_cast(i + 1)) Chris@16: { Chris@16: const char* p = get_default_error_string(i); Chris@16: string_type default_message; Chris@16: while(*p) Chris@16: { Chris@16: default_message.append(1, static_cast(*p)); Chris@16: ++p; Chris@16: } Chris@16: string_type s = ::boost::re_detail::w32_cat_get(cat, this->m_locale, i+200, default_message); Chris@16: std::string result; Chris@16: for(std::string::size_type j = 0; j < s.size(); ++j) Chris@16: { Chris@16: result.append(1, static_cast(s[j])); Chris@16: } Chris@16: m_error_strings[i] = result; Chris@16: } Chris@16: // Chris@16: // Custom class names: Chris@16: // Chris@16: static const char_class_type masks[14] = Chris@16: { Chris@16: 0x0104u, // C1_ALPHA | C1_DIGIT Chris@16: 0x0100u, // C1_ALPHA Chris@16: 0x0020u, // C1_CNTRL Chris@16: 0x0004u, // C1_DIGIT Chris@16: (~(0x0020u|0x0008u) & 0x01ffu) | 0x0400u, // not C1_CNTRL or C1_SPACE Chris@16: 0x0002u, // C1_LOWER Chris@16: (~0x0020u & 0x01ffu) | 0x0400, // not C1_CNTRL Chris@16: 0x0010u, // C1_PUNCT Chris@16: 0x0008u, // C1_SPACE Chris@16: 0x0001u, // C1_UPPER Chris@16: 0x0080u, // C1_XDIGIT Chris@16: 0x0040u, // C1_BLANK Chris@16: w32_regex_traits_implementation::mask_word, Chris@16: w32_regex_traits_implementation::mask_unicode, Chris@16: }; Chris@16: static const string_type null_string; Chris@16: for(unsigned int j = 0; j <= 13; ++j) Chris@16: { Chris@16: string_type s(::boost::re_detail::w32_cat_get(cat, this->m_locale, j+300, null_string)); Chris@16: if(s.size()) Chris@16: this->m_custom_class_names[s] = masks[j]; Chris@16: } Chris@16: } Chris@16: // Chris@16: // get the collation format used by m_pcollate: Chris@16: // Chris@16: m_collate_type = re_detail::find_sort_syntax(this, &m_collate_delim); Chris@16: } Chris@16: Chris@16: template Chris@16: typename w32_regex_traits_implementation::char_class_type Chris@16: w32_regex_traits_implementation::lookup_classname_imp(const charT* p1, const charT* p2) const Chris@16: { Chris@16: static const char_class_type masks[22] = Chris@16: { Chris@16: 0, Chris@16: 0x0104u, // C1_ALPHA | C1_DIGIT Chris@16: 0x0100u, // C1_ALPHA Chris@16: 0x0040u, // C1_BLANK Chris@16: 0x0020u, // C1_CNTRL Chris@16: 0x0004u, // C1_DIGIT Chris@16: 0x0004u, // C1_DIGIT Chris@16: (~(0x0020u|0x0008u|0x0040) & 0x01ffu) | 0x0400u, // not C1_CNTRL or C1_SPACE or C1_BLANK Chris@16: w32_regex_traits_implementation::mask_horizontal, Chris@16: 0x0002u, // C1_LOWER Chris@16: 0x0002u, // C1_LOWER Chris@16: (~0x0020u & 0x01ffu) | 0x0400, // not C1_CNTRL Chris@16: 0x0010u, // C1_PUNCT Chris@16: 0x0008u, // C1_SPACE Chris@16: 0x0008u, // C1_SPACE Chris@16: 0x0001u, // C1_UPPER Chris@16: w32_regex_traits_implementation::mask_unicode, Chris@16: 0x0001u, // C1_UPPER Chris@16: w32_regex_traits_implementation::mask_vertical, Chris@16: 0x0104u | w32_regex_traits_implementation::mask_word, Chris@16: 0x0104u | w32_regex_traits_implementation::mask_word, Chris@16: 0x0080u, // C1_XDIGIT Chris@16: }; Chris@16: if(m_custom_class_names.size()) Chris@16: { Chris@16: typedef typename std::map, char_class_type>::const_iterator map_iter; Chris@16: map_iter pos = m_custom_class_names.find(string_type(p1, p2)); Chris@16: if(pos != m_custom_class_names.end()) Chris@16: return pos->second; Chris@16: } Chris@16: std::size_t state_id = 1 + re_detail::get_default_class_id(p1, p2); Chris@16: if(state_id < sizeof(masks) / sizeof(masks[0])) Chris@16: return masks[state_id]; Chris@16: return masks[0]; Chris@16: } Chris@16: Chris@16: Chris@16: template Chris@101: boost::shared_ptr > create_w32_regex_traits(::boost::re_detail::lcid_type l) Chris@16: { Chris@16: // TODO: create a cache for previously constructed objects. Chris@16: return boost::object_cache< ::boost::re_detail::lcid_type, w32_regex_traits_implementation >::get(l, 5); Chris@16: } Chris@16: Chris@16: } // re_detail Chris@16: Chris@16: template Chris@16: class w32_regex_traits Chris@16: { Chris@16: public: Chris@16: typedef charT char_type; Chris@16: typedef std::size_t size_type; Chris@16: typedef std::basic_string string_type; Chris@16: typedef ::boost::re_detail::lcid_type locale_type; Chris@16: typedef boost::uint_least32_t char_class_type; Chris@16: Chris@16: struct boost_extensions_tag{}; Chris@16: Chris@16: w32_regex_traits() Chris@16: : m_pimpl(re_detail::create_w32_regex_traits(::boost::re_detail::w32_get_default_locale())) Chris@16: { } Chris@16: static size_type length(const char_type* p) Chris@16: { Chris@16: return std::char_traits::length(p); Chris@16: } Chris@16: regex_constants::syntax_type syntax_type(charT c)const Chris@16: { Chris@16: return m_pimpl->syntax_type(c); Chris@16: } Chris@16: regex_constants::escape_syntax_type escape_syntax_type(charT c) const Chris@16: { Chris@16: return m_pimpl->escape_syntax_type(c); Chris@16: } Chris@16: charT translate(charT c) const Chris@16: { Chris@16: return c; Chris@16: } Chris@16: charT translate_nocase(charT c) const Chris@16: { Chris@16: return this->m_pimpl->tolower(c); Chris@16: } Chris@16: charT translate(charT c, bool icase) const Chris@16: { Chris@16: return icase ? this->m_pimpl->tolower(c) : c; Chris@16: } Chris@16: charT tolower(charT c) const Chris@16: { Chris@16: return this->m_pimpl->tolower(c); Chris@16: } Chris@16: charT toupper(charT c) const Chris@16: { Chris@16: return ::boost::re_detail::w32_toupper(c, this->m_pimpl->m_locale); Chris@16: } Chris@16: string_type transform(const charT* p1, const charT* p2) const Chris@16: { Chris@16: return ::boost::re_detail::w32_transform(this->m_pimpl->m_locale, p1, p2); Chris@16: } Chris@16: string_type transform_primary(const charT* p1, const charT* p2) const Chris@16: { Chris@16: return m_pimpl->transform_primary(p1, p2); Chris@16: } Chris@16: char_class_type lookup_classname(const charT* p1, const charT* p2) const Chris@16: { Chris@16: return m_pimpl->lookup_classname(p1, p2); Chris@16: } Chris@16: string_type lookup_collatename(const charT* p1, const charT* p2) const Chris@16: { Chris@16: return m_pimpl->lookup_collatename(p1, p2); Chris@16: } Chris@16: bool isctype(charT c, char_class_type f) const Chris@16: { Chris@16: if((f & re_detail::w32_regex_traits_implementation::mask_base) Chris@16: && (this->m_pimpl->isctype(f & re_detail::w32_regex_traits_implementation::mask_base, c))) Chris@16: return true; Chris@16: else if((f & re_detail::w32_regex_traits_implementation::mask_unicode) && re_detail::is_extended(c)) Chris@16: return true; Chris@16: else if((f & re_detail::w32_regex_traits_implementation::mask_word) && (c == '_')) Chris@16: return true; Chris@16: else if((f & re_detail::w32_regex_traits_implementation::mask_vertical) Chris@16: && (::boost::re_detail::is_separator(c) || (c == '\v'))) Chris@16: return true; Chris@16: else if((f & re_detail::w32_regex_traits_implementation::mask_horizontal) Chris@16: && this->isctype(c, 0x0008u) && !this->isctype(c, re_detail::w32_regex_traits_implementation::mask_vertical)) Chris@16: return true; Chris@16: return false; Chris@16: } Chris@16: int toi(const charT*& p1, const charT* p2, int radix)const Chris@16: { Chris@16: return ::boost::re_detail::global_toi(p1, p2, radix, *this); Chris@16: } Chris@16: int value(charT c, int radix)const Chris@16: { Chris@16: int result = ::boost::re_detail::global_value(c); Chris@16: return result < radix ? result : -1; Chris@16: } Chris@16: locale_type imbue(locale_type l) Chris@16: { Chris@16: ::boost::re_detail::lcid_type result(getloc()); Chris@16: m_pimpl = re_detail::create_w32_regex_traits(l); Chris@16: return result; Chris@16: } Chris@16: locale_type getloc()const Chris@16: { Chris@16: return m_pimpl->m_locale; Chris@16: } Chris@16: std::string error_string(regex_constants::error_type n) const Chris@16: { Chris@16: return m_pimpl->error_string(n); Chris@16: } Chris@16: Chris@16: // Chris@16: // extension: Chris@16: // set the name of the message catalog in use (defaults to "boost_regex"). Chris@16: // Chris@16: static std::string catalog_name(const std::string& name); Chris@16: static std::string get_catalog_name(); Chris@16: Chris@16: private: Chris@16: boost::shared_ptr > m_pimpl; Chris@16: // Chris@16: // catalog name handler: Chris@16: // Chris@16: static std::string& get_catalog_name_inst(); Chris@16: Chris@16: #ifdef BOOST_HAS_THREADS Chris@16: static static_mutex& get_mutex_inst(); Chris@16: #endif Chris@16: }; Chris@16: Chris@16: template Chris@16: std::string w32_regex_traits::catalog_name(const std::string& name) Chris@16: { Chris@16: #ifdef BOOST_HAS_THREADS Chris@16: static_mutex::scoped_lock lk(get_mutex_inst()); Chris@16: #endif Chris@16: std::string result(get_catalog_name_inst()); Chris@16: get_catalog_name_inst() = name; Chris@16: return result; Chris@16: } Chris@16: Chris@16: template Chris@16: std::string& w32_regex_traits::get_catalog_name_inst() Chris@16: { Chris@16: static std::string s_name; Chris@16: return s_name; Chris@16: } Chris@16: Chris@16: template Chris@16: std::string w32_regex_traits::get_catalog_name() Chris@16: { Chris@16: #ifdef BOOST_HAS_THREADS Chris@16: static_mutex::scoped_lock lk(get_mutex_inst()); Chris@16: #endif Chris@16: std::string result(get_catalog_name_inst()); Chris@16: return result; Chris@16: } Chris@16: Chris@16: #ifdef BOOST_HAS_THREADS Chris@16: template Chris@16: static_mutex& w32_regex_traits::get_mutex_inst() Chris@16: { Chris@16: static static_mutex s_mutex = BOOST_STATIC_MUTEX_INIT; Chris@16: return s_mutex; Chris@16: } Chris@16: #endif Chris@16: Chris@16: Chris@16: } // boost Chris@16: Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(push) Chris@16: #pragma warning(disable: 4103) Chris@16: #endif Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: # include BOOST_ABI_SUFFIX Chris@16: #endif Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: #endif