Files

118 lines
3.0 KiB
C++
Raw Permalink Normal View History

2000-09-26 11:48:28 +00:00
/*
*
2005-01-13 17:06:21 +00:00
* Copyright (c) 2004
2005-01-21 17:28:42 +00:00
* John Maddock
2000-09-26 11:48:28 +00:00
*
2003-10-04 11:29:20 +00:00
* Use, modification and distribution are subject to the
2003-09-30 13:02:51 +00:00
* Boost Software License, Version 1.0. (See accompanying file
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
2000-09-26 11:48:28 +00:00
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
2005-01-13 17:06:21 +00:00
* FILE cpp_regex_traits.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Implements cpp_regex_traits<char> (and associated helper classes).
2000-09-26 11:48:28 +00:00
*/
#define BOOST_REGEX_SOURCE
2005-01-13 17:06:21 +00:00
#include <boost/config.hpp>
#ifndef BOOST_NO_STD_LOCALE
#include <boost/regex/regex_traits.hpp>
#include <boost/regex/pattern_except.hpp>
2005-01-13 17:06:21 +00:00
#ifdef BOOST_NO_STDC_NAMESPACE
namespace std{
using ::memset;
}
#endif
2005-01-13 17:06:21 +00:00
namespace boost{ namespace re_detail{
2005-01-13 17:06:21 +00:00
void cpp_regex_traits_char_layer<char>::init()
2000-09-26 11:48:28 +00:00
{
2005-01-13 17:06:21 +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));
#ifndef BOOST_NO_STD_MESSAGES
2002-09-16 11:54:41 +00:00
#ifndef __IBMCPP__
2003-03-30 10:30:16 +00:00
std::messages<char>::catalog cat = static_cast<std::messages<char>::catalog>(-1);
2002-09-16 11:54:41 +00:00
#else
2003-03-30 10:30:16 +00:00
std::messages<char>::catalog cat = reinterpret_cast<std::messages<char>::catalog>(-1);
2002-09-16 11:54:41 +00:00
#endif
2005-01-13 17:06:21 +00:00
std::string cat_name(cpp_regex_traits<char>::get_catalog_name());
if(cat_name.size() && (m_pmessages != 0))
2002-01-07 13:03:50 +00:00
{
2005-01-13 17:06:21 +00:00
cat = this->m_pmessages->open(
cat_name,
this->m_locale);
if((int)cat < 0)
2002-01-07 13:03:50 +00:00
{
std::string m("Unable to open message catalog: ");
2005-01-13 17:06:21 +00:00
std::runtime_error err(m + cat_name);
boost::re_detail::raise_runtime_error(err);
2000-09-26 11:48:28 +00:00
}
}
//
2005-01-13 17:06:21 +00:00
// if we have a valid catalog then load our messages:
//
2000-09-26 11:48:28 +00:00
if((int)cat >= 0)
{
#ifndef BOOST_NO_EXCEPTIONS
2005-01-13 17:06:21 +00:00
try{
#endif
2005-01-13 17:06:21 +00:00
for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i)
{
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;
}
}
this->m_pmessages->close(cat);
#ifndef BOOST_NO_EXCEPTIONS
2002-01-07 13:03:50 +00:00
}
2005-01-13 17:06:21 +00:00
catch(...)
2000-09-26 11:48:28 +00:00
{
2005-01-13 17:06:21 +00:00
this->m_pmessages->close(cat);
throw;
2000-09-26 11:48:28 +00:00
}
#endif
2000-09-26 11:48:28 +00:00
}
else
{
2005-01-13 17:06:21 +00:00
#endif
for(regex_constants::syntax_type j = 1; j < regex_constants::syntax_max; ++j)
2000-09-26 11:48:28 +00:00
{
const char* ptr = get_default_syntax(j);
2005-01-13 17:06:21 +00:00
while(ptr && *ptr)
2000-09-26 11:48:28 +00:00
{
m_char_map[static_cast<unsigned char>(*ptr)] = j;
2005-01-13 17:06:21 +00:00
++ptr;
2000-09-26 11:48:28 +00:00
}
}
2005-01-13 17:06:21 +00:00
#ifndef BOOST_NO_STD_MESSAGES
2000-09-26 11:48:28 +00:00
}
2005-01-13 17:06:21 +00:00
#endif
2000-09-26 11:48:28 +00:00
//
2005-01-13 17:06:21 +00:00
// finish off by calculating our escape types:
2000-09-26 11:48:28 +00:00
//
2005-01-13 17:06:21 +00:00
unsigned char i = 'A';
do
2000-09-26 11:48:28 +00:00
{
2005-01-13 17:06:21 +00:00
if(m_char_map[i] == 0)
2000-09-26 11:48:28 +00:00
{
2005-01-13 17:06:21 +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;
2000-09-26 11:48:28 +00:00
}
2005-01-13 17:06:21 +00:00
}while(0xFF != i++);
2000-09-26 11:48:28 +00:00
}
2005-01-13 17:06:21 +00:00
} // re_detail
} // boost
2000-10-24 11:53:07 +00:00
#endif
2000-09-26 11:48:28 +00:00