6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE cpp_regex_traits.cpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Implements cpp_regex_traits<char> (and associated helper classes).
19 #define BOOST_REGEX_SOURCE
20 #include <boost/config.hpp>
21 #ifndef BOOST_NO_STD_LOCALE
22 #include <boost/regex/regex_traits.hpp>
23 #include <boost/regex/pattern_except.hpp>
25 #ifdef BOOST_NO_STDC_NAMESPACE
31 namespace boost
{ namespace re_detail
{
33 void cpp_regex_traits_char_layer
<char>::init()
35 // we need to start by initialising our syntax map so we know which
36 // character is used for which purpose:
37 std::memset(m_char_map
, 0, sizeof(m_char_map
));
38 #ifndef BOOST_NO_STD_MESSAGES
40 std::messages
<char>::catalog cat
= static_cast<std::messages
<char>::catalog
>(-1);
42 std::messages
<char>::catalog cat
= reinterpret_cast<std::messages
<char>::catalog
>(-1);
44 std::string
cat_name(cpp_regex_traits
<char>::get_catalog_name());
45 if(cat_name
.size() && (m_pmessages
!= 0))
47 cat
= this->m_pmessages
->open(
52 std::string
m("Unable to open message catalog: ");
53 std::runtime_error
err(m
+ cat_name
);
54 boost::re_detail::raise_runtime_error(err
);
58 // if we have a valid catalog then load our messages:
62 #ifndef BOOST_NO_EXCEPTIONS
65 for(regex_constants::syntax_type i
= 1; i
< regex_constants::syntax_max
; ++i
)
67 string_type mss
= this->m_pmessages
->get(cat
, 0, i
, get_default_syntax(i
));
68 for(string_type::size_type j
= 0; j
< mss
.size(); ++j
)
70 m_char_map
[static_cast<unsigned char>(mss
[j
])] = i
;
73 this->m_pmessages
->close(cat
);
74 #ifndef BOOST_NO_EXCEPTIONS
78 this->m_pmessages
->close(cat
);
86 for(regex_constants::syntax_type j
= 1; j
< regex_constants::syntax_max
; ++j
)
88 const char* ptr
= get_default_syntax(j
);
91 m_char_map
[static_cast<unsigned char>(*ptr
)] = j
;
95 #ifndef BOOST_NO_STD_MESSAGES
99 // finish off by calculating our escape types:
101 unsigned char i
= 'A';
104 if(m_char_map
[i
] == 0)
106 if(this->m_pctype
->is(std::ctype_base::lower
, i
))
107 m_char_map
[i
] = regex_constants::escape_type_class
;
108 else if(this->m_pctype
->is(std::ctype_base::upper
, i
))
109 m_char_map
[i
] = regex_constants::escape_type_not_class
;