Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/regex/src/cpp_regex_traits.cpp @ 45

Last change on this file since 45 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 3.0 KB
Line 
1/*
2 *
3 * Copyright (c) 2004
4 * John Maddock
5 *
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)
9 *
10 */
11 
12 /*
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).
17  */
18
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>
24
25#ifdef BOOST_NO_STDC_NAMESPACE
26namespace std{
27   using ::memset;
28}
29#endif
30
31namespace boost{ namespace re_detail{
32
33void cpp_regex_traits_char_layer<char>::init() 
34{
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
39#ifndef __IBMCPP__
40   std::messages<char>::catalog cat = static_cast<std::messages<char>::catalog>(-1);
41#else
42   std::messages<char>::catalog cat = reinterpret_cast<std::messages<char>::catalog>(-1);
43#endif
44   std::string cat_name(cpp_regex_traits<char>::get_catalog_name());
45   if(cat_name.size())
46   {
47      cat = this->m_pmessages->open(
48         cat_name, 
49         this->m_locale);
50      if((int)cat < 0)
51      {
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);
55      }
56   }
57   //
58   // if we have a valid catalog then load our messages:
59   //
60   if((int)cat >= 0)
61   {
62#ifndef BOOST_NO_EXCEPTIONS
63      try{
64#endif
65         for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i)
66         {
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)
69            {
70               m_char_map[static_cast<unsigned char>(mss[j])] = i;
71            }
72         }
73         this->m_pmessages->close(cat);
74#ifndef BOOST_NO_EXCEPTIONS
75      }
76      catch(...)
77      {
78         this->m_pmessages->close(cat);
79         throw;
80      }
81#endif
82   }
83   else
84   {
85#endif
86      for(regex_constants::syntax_type j = 1; j < regex_constants::syntax_max; ++j)
87      {
88         const char* ptr = get_default_syntax(j);
89         while(ptr && *ptr)
90         {
91            m_char_map[static_cast<unsigned char>(*ptr)] = j;
92            ++ptr;
93         }
94      }
95#ifndef BOOST_NO_STD_MESSAGES
96   }
97#endif
98   //
99   // finish off by calculating our escape types:
100   //
101   unsigned char i = 'A';
102   do
103   {
104      if(m_char_map[i] == 0)
105      {
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;
110      }
111   }while(0xFF != i++);
112}
113
114} // re_detail
115} // boost
116#endif
117
Note: See TracBrowser for help on using the repository browser.