2002-05-24 12:53:12 +00:00
|
|
|
/*
|
|
|
|
*
|
2006-03-05 18:22:35 +00:00
|
|
|
* Copyright (c) 2004
|
|
|
|
* John Maddock
|
2002-05-24 12:53:12 +00:00
|
|
|
*
|
2004-02-05 09:14:22 +00:00
|
|
|
* Use, modification and distribution are subject to the
|
|
|
|
* Boost Software License, Version 1.0. (See accompanying file
|
|
|
|
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
2002-05-24 12:53:12 +00:00
|
|
|
*
|
|
|
|
*/
|
2004-02-05 09:14:22 +00:00
|
|
|
|
2002-05-24 12:53:12 +00:00
|
|
|
/*
|
|
|
|
* LOCATION: see http://www.boost.org for most recent version.
|
2006-03-05 18:22:35 +00:00
|
|
|
* FILE cpp_regex_traits.cpp
|
|
|
|
* VERSION see <boost/version.hpp>
|
|
|
|
* DESCRIPTION: Implements cpp_regex_traits<char> (and associated helper classes).
|
2002-05-24 12:53:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define BOOST_REGEX_SOURCE
|
2006-03-05 18:22:35 +00:00
|
|
|
#include <boost/config.hpp>
|
|
|
|
#ifndef BOOST_NO_STD_LOCALE
|
2002-05-24 12:53:12 +00:00
|
|
|
#include <boost/regex/regex_traits.hpp>
|
2006-03-05 18:22:35 +00:00
|
|
|
#include <boost/regex/pattern_except.hpp>
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
#ifdef BOOST_NO_STDC_NAMESPACE
|
|
|
|
namespace std{
|
|
|
|
using ::memset;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
#endif
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
namespace boost{ namespace re_detail{
|
2002-05-24 12:53:12 +00:00
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
void cpp_regex_traits_char_layer<char>::init()
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
// we need to start by initialising our syntax map so we know which
|
|
|
|
// character is used for which purpose:
|
|
|
|
std::memset(m_char_map, 0, sizeof(m_char_map));
|
2002-05-24 12:53:12 +00:00
|
|
|
#ifndef BOOST_NO_STD_MESSAGES
|
2002-10-15 17:51:41 +00:00
|
|
|
#ifndef __IBMCPP__
|
2004-02-05 09:14:22 +00:00
|
|
|
std::messages<char>::catalog cat = static_cast<std::messages<char>::catalog>(-1);
|
2002-10-15 17:51:41 +00:00
|
|
|
#else
|
2004-02-05 09:14:22 +00:00
|
|
|
std::messages<char>::catalog cat = reinterpret_cast<std::messages<char>::catalog>(-1);
|
2002-10-15 17:51:41 +00:00
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
std::string cat_name(cpp_regex_traits<char>::get_catalog_name());
|
|
|
|
if(cat_name.size())
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
cat = this->m_pmessages->open(
|
|
|
|
cat_name,
|
|
|
|
this->m_locale);
|
|
|
|
if((int)cat < 0)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2002-10-15 17:51:41 +00:00
|
|
|
std::string m("Unable to open message catalog: ");
|
2006-03-05 18:22:35 +00:00
|
|
|
std::runtime_error err(m + cat_name);
|
|
|
|
boost::re_detail::raise_runtime_error(err);
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
2006-03-05 18:22:35 +00:00
|
|
|
// if we have a valid catalog then load our messages:
|
2002-05-24 12:53:12 +00:00
|
|
|
//
|
|
|
|
if((int)cat >= 0)
|
|
|
|
{
|
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2006-03-05 18:22:35 +00:00
|
|
|
try{
|
2002-05-24 12:53:12 +00:00
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i)
|
2002-10-15 17:51:41 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
string_type mss = this->m_pmessages->get(cat, 0, i, get_default_syntax(i));
|
|
|
|
for(string_type::size_type j = 0; j < mss.size(); ++j)
|
|
|
|
{
|
|
|
|
m_char_map[static_cast<unsigned char>(mss[j])] = i;
|
|
|
|
}
|
2002-10-15 17:51:41 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
this->m_pmessages->close(cat);
|
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
catch(...)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
this->m_pmessages->close(cat);
|
|
|
|
throw;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2002-10-15 17:51:41 +00:00
|
|
|
#endif
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
else
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
|
|
|
#endif
|
2006-03-05 18:22:35 +00:00
|
|
|
for(regex_constants::syntax_type j = 1; j < regex_constants::syntax_max; ++j)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
const char* ptr = get_default_syntax(j);
|
|
|
|
while(ptr && *ptr)
|
2002-10-15 17:51:41 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
m_char_map[static_cast<unsigned char>(*ptr)] = j;
|
|
|
|
++ptr;
|
2002-10-15 17:51:41 +00:00
|
|
|
}
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
#ifndef BOOST_NO_STD_MESSAGES
|
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
#endif
|
|
|
|
//
|
|
|
|
// finish off by calculating our escape types:
|
|
|
|
//
|
|
|
|
unsigned char i = 'A';
|
|
|
|
do
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
if(m_char_map[i] == 0)
|
2002-05-24 12:53:12 +00:00
|
|
|
{
|
2006-03-05 18:22:35 +00:00
|
|
|
if(this->m_pctype->is(std::ctype_base::lower, i))
|
|
|
|
m_char_map[i] = regex_constants::escape_type_class;
|
|
|
|
else if(this->m_pctype->is(std::ctype_base::upper, i))
|
|
|
|
m_char_map[i] = regex_constants::escape_type_not_class;
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
2006-03-05 18:22:35 +00:00
|
|
|
}while(0xFF != i++);
|
2002-05-24 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 18:22:35 +00:00
|
|
|
} // re_detail
|
|
|
|
} // boost
|
2002-05-24 12:53:12 +00:00
|
|
|
#endif
|
2004-02-05 09:14:22 +00:00
|
|
|
|