]> git.lyx.org Git - lyx.git/blob - boost/boost/regex/regex_traits.hpp
major boost update
[lyx.git] / boost / boost / regex / regex_traits.hpp
1 /*
2  *
3  * Copyright (c) 1998-2002
4  * Dr John Maddock
5  *
6  * Permission to use, copy, modify, distribute and sell this software
7  * and its documentation for any purpose is hereby granted without fee,
8  * provided that the above copyright notice appear in all copies and
9  * that both that copyright notice and this permission notice appear
10  * in supporting documentation.  Dr John Maddock makes no representations
11  * about the suitability of this software for any purpose.  
12  * It is provided "as is" without express or implied warranty.
13  *
14  */
15  
16  /*
17   *   LOCATION:    see http://www.boost.org for most recent version.
18   *   FILE         regex_traits.hpp
19   *   VERSION      see <boost/version.hpp>
20   *   DESCRIPTION: Declares regular expression traits classes.
21   */
22
23 #ifndef BOOST_REGEX_TRAITS_HPP
24 #define BOOST_REGEX_TRAITS_HPP
25
26 #include <boost/cregex.hpp>
27 #include <boost/static_assert.hpp>
28 #include <boost/regex/detail/regex_cstring.hpp>
29
30 namespace boost{
31
32 #ifdef __BORLANDC__
33    #pragma option push -a4 -b -Ve -pc
34 #endif
35
36 template <class charT>
37 class c_regex_traits;
38
39 namespace re_detail{
40
41 struct mss
42 {
43    unsigned int id;
44    const char* what;
45 };
46
47 BOOST_REGEX_DECL bool BOOST_REGEX_CALL re_lookup_def_collate_name(std::string& buf, const char* name);
48 BOOST_REGEX_DECL std::size_t BOOST_REGEX_CALL re_get_default_message(char* buf, std::size_t len, std::size_t id);
49 extern BOOST_REGEX_DECL const char *re_default_error_messages[];
50 BOOST_REGEX_DECL bool BOOST_REGEX_CALL re_lookup_def_collate_name(std::string& buf, const char* name);
51 //extern BOOST_REGEX_DECL const wchar_t combining_ranges[];
52
53 #ifndef BOOST_NO_WREGEX
54 extern BOOST_REGEX_DECL wchar_t wide_lower_case_map[];
55 extern BOOST_REGEX_DECL unsigned short wide_unicode_classes[];
56 BOOST_REGEX_DECL bool BOOST_REGEX_CALL is_combining(wchar_t c);
57 #endif
58
59
60 struct BOOST_REGEX_DECL regex_traits_base
61 {
62    enum char_syntax_type
63    {
64       syntax_char = 0,
65       syntax_open_bracket = 1,                  // (
66       syntax_close_bracket = 2,                 // )
67       syntax_dollar = 3,                        // $
68       syntax_caret = 4,                         // ^
69       syntax_dot = 5,                           // .
70       syntax_star = 6,                          // *
71       syntax_plus = 7,                          // +
72       syntax_question = 8,                      // ?
73       syntax_open_set = 9,                      // [
74       syntax_close_set = 10,                    // ]
75       syntax_or = 11,                           // |
76       syntax_slash = 12,                        //
77       syntax_hash = 13,                         // #
78       syntax_dash = 14,                         // -
79       syntax_open_brace = 15,                   // {
80       syntax_close_brace = 16,                  // }
81       syntax_digit = 17,                        // 0-9
82       syntax_b = 18,                            // for \b
83       syntax_B = 19,                            // for \B
84       syntax_left_word = 20,                    // for \<
85       syntax_right_word = 21,                   // for \>
86       syntax_w = 22,                            // for \w
87       syntax_W = 23,                            // for \W
88       syntax_start_buffer = 24,                 // for \`
89       syntax_end_buffer = 25,                   // for \'
90       syntax_newline = 26,                      // for newline alt
91       syntax_comma = 27,                        // for {x,y}
92
93       syntax_a = 28,                            // for \a
94       syntax_f = 29,                            // for \f
95       syntax_n = 30,                            // for \n
96       syntax_r = 31,                            // for \r
97       syntax_t = 32,                            // for \t
98       syntax_v = 33,                            // for \v
99       syntax_x = 34,                            // for \xdd
100       syntax_c = 35,                            // for \cx
101       syntax_colon = 36,                        // for [:...:]
102       syntax_equal = 37,                        // for [=...=]
103    
104       // perl ops:
105       syntax_e = 38,                            // for \e
106       syntax_l = 39,                            // for \l
107       syntax_L = 40,                            // for \L
108       syntax_u = 41,                            // for \u
109       syntax_U = 42,                            // for \U
110       syntax_s = 43,                            // for \s
111       syntax_S = 44,                            // for \S
112       syntax_d = 45,                            // for \d
113       syntax_D = 46,                            // for \D
114       syntax_E = 47,                            // for \Q\E
115       syntax_Q = 48,                            // for \Q\E
116       syntax_X = 49,                            // for \X
117       syntax_C = 50,                            // for \C
118       syntax_Z = 51,                            // for \Z
119       syntax_G = 52,                            // for \G
120
121       // new extentions:
122       syntax_not = 53,                          // for (?!...)
123
124       syntax_max = 54
125    };
126 };
127
128 struct BOOST_REGEX_DECL c_traits_base : public regex_traits_base
129 {
130 public:
131    enum{
132       char_class_none = 0,
133       char_class_alpha = 0x0001,
134       char_class_cntrl = 0x0002,
135       char_class_digit = 0x0004,
136       char_class_lower = 0x0008,
137       char_class_punct = 0x0010,
138       char_class_space = 0x0020,
139       char_class_upper = 0x0040,
140       char_class_xdigit = 0x0080,
141       char_class_blank = 0x0100,
142       char_class_underscore = 0x4000,
143       char_class_unicode = 0x8000,
144
145       char_class_alnum = char_class_alpha | char_class_digit,
146       char_class_graph = char_class_alpha | char_class_digit | char_class_punct | char_class_underscore,
147       char_class_print = char_class_alpha | char_class_digit | char_class_punct | char_class_underscore | char_class_blank,
148       char_class_word = char_class_alpha | char_class_digit | char_class_underscore
149    };
150    static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s);
151 protected:
152 #if defined(__MWERKS__) && __MWERKS__ <= 0x6000
153    friend class c_regex_traits<char>;
154    friend class c_regex_traits<wchar_t>;
155 #endif 
156
157    static char regex_message_catalogue[BOOST_REGEX_MAX_PATH];
158    enum syntax_map_size
159    {
160       map_size = UCHAR_MAX + 1
161    };
162
163    static unsigned char syntax_map[map_size];
164    static unsigned short class_map[map_size];
165    static char lower_case_map[map_size];
166
167    static boost::uint_fast32_t BOOST_REGEX_CALL do_lookup_class(const char* p);
168    static bool BOOST_REGEX_CALL do_lookup_collate(std::string& buf, const char* p);
169    static void BOOST_REGEX_CALL do_update_ctype();
170    static void BOOST_REGEX_CALL do_update_collate();
171 public:
172    static std::string BOOST_REGEX_CALL error_string(unsigned id);
173    static char* BOOST_REGEX_CALL get_catalogue() { return regex_message_catalogue; }
174 };
175
176 } // namespace re_detail
177
178
179 template<>
180 class BOOST_REGEX_DECL c_regex_traits<char> : public re_detail::c_traits_base
181 {
182    typedef re_detail::c_traits_base base_type;
183 public:
184    typedef char char_type;
185    typedef unsigned char uchar_type;
186    typedef unsigned int size_type;
187    typedef std::string string_type;
188    typedef int locale_type;
189
190    static std::size_t BOOST_REGEX_CALL length(const char_type* p)
191    {
192       return std::strlen(p);
193    }
194    static unsigned int BOOST_REGEX_CALL syntax_type(size_type c)
195    {
196       return syntax_map[c];
197    }
198    static char BOOST_REGEX_CALL translate(char c, bool icase)
199    {
200       return icase ? lower_case_map[(size_type)(uchar_type)c] : c;
201    }
202    static void BOOST_REGEX_CALL transform(std::string& out, const std::string& in);
203
204    static void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in);
205
206    static bool BOOST_REGEX_CALL is_separator(char c)
207    {
208       return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r'));
209    }
210
211    static bool BOOST_REGEX_CALL is_combining(char)
212    {
213       return false;
214    }
215    
216    static bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f)
217    {
218       return BOOST_REGEX_MAKE_BOOL(class_map[(size_type)(uchar_type)c] & f);
219    }
220
221    static int BOOST_REGEX_CALL toi(char c);
222    static int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix);
223
224    static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last)
225    {
226       std::string s(first, last);
227       return do_lookup_class(s.c_str());
228    }
229
230    static bool BOOST_REGEX_CALL lookup_collatename(std::string& buf, const char* first, const char* last)
231    {
232       std::string s(first, last);
233       return do_lookup_collate(buf, s.c_str());
234    }
235
236    static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; }
237    locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); }
238
239    c_regex_traits()
240    {
241       init();
242    }
243    ~c_regex_traits()
244    {
245       m_free();
246    }
247    struct sentry
248    {
249       sentry(const c_regex_traits<char>&)
250       { c_regex_traits<char>::update(); }
251       operator void*() { return this; }
252    };
253    static void BOOST_REGEX_CALL update();
254 private:
255    static void BOOST_REGEX_CALL init();
256    static void BOOST_REGEX_CALL m_free();
257    static c_regex_traits<char> i;
258
259    static unsigned sort_type;
260    static char sort_delim;
261 };
262
263 #ifndef BOOST_NO_WREGEX
264 template<>
265 class BOOST_REGEX_DECL c_regex_traits<wchar_t> : public re_detail::c_traits_base
266 {
267    typedef re_detail::c_traits_base base_type;
268 public:
269    typedef wchar_t char_type;
270    typedef unsigned short uchar_type;
271    typedef unsigned int size_type;
272    typedef std::basic_string<wchar_t> string_type;
273    typedef int locale_type; 
274    static std::size_t BOOST_REGEX_CALL length(const char_type* p)
275    {
276       return std::wcslen(p);
277    }
278    static unsigned int BOOST_REGEX_CALL syntax_type(size_type c);
279    static wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase)
280    {
281       return icase ? ((c < 256) ? re_detail::wide_lower_case_map[(uchar_type)c] : std::towlower(c)) : c;
282    }
283
284    static void BOOST_REGEX_CALL transform(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in);
285
286    static void BOOST_REGEX_CALL transform_primary(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in);
287
288    static bool BOOST_REGEX_CALL is_separator(wchar_t c)
289    {
290       return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029));
291    }
292
293    static bool BOOST_REGEX_CALL is_combining(wchar_t c)
294    { return re_detail::is_combining(c); }
295    
296    static bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f)
297    {
298       return BOOST_REGEX_MAKE_BOOL(((uchar_type)c < 256) ? (re_detail::wide_unicode_classes[(size_type)(uchar_type)c] & f) : do_iswclass(c, f));
299    }
300
301    static int BOOST_REGEX_CALL toi(wchar_t c);
302    static int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix);
303
304    static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last);
305
306    static bool BOOST_REGEX_CALL lookup_collatename(std::basic_string<wchar_t>& s, const wchar_t* first, const wchar_t* last);
307
308    static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; }
309    locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); }
310    c_regex_traits<wchar_t>()
311    { init(); }
312    ~c_regex_traits<wchar_t>()
313    { m_free(); }
314    struct sentry
315    {
316       sentry(const c_regex_traits<wchar_t>&)
317       { c_regex_traits<wchar_t>::update(); }
318       operator void*() { return this; }
319    };
320    static void BOOST_REGEX_CALL update();
321    static std::size_t BOOST_REGEX_CALL strnarrow(char *s1, std::size_t len, const wchar_t *s2);
322    static std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2);
323 private:
324    static bool BOOST_REGEX_CALL do_iswclass(wchar_t c, boost::uint_fast32_t f);
325    static void BOOST_REGEX_CALL m_free();
326    static void BOOST_REGEX_CALL init();
327    static bool BOOST_REGEX_CALL do_lookup_collate(std::basic_string<wchar_t>& out, const wchar_t* first, const wchar_t* last);
328    static c_regex_traits<wchar_t> init_;
329
330    static unsigned sort_type;
331    static wchar_t sort_delim;
332 };
333 #endif
334
335 #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
336
337 namespace re_detail{
338
339 struct BOOST_REGEX_DECL w32_traits_base : public regex_traits_base
340 {
341    enum{
342    char_class_none = 0,
343    char_class_alnum = C1_ALPHA | C1_DIGIT,
344    char_class_alpha = C1_ALPHA,
345    char_class_cntrl = C1_CNTRL,
346    char_class_digit = C1_DIGIT,
347    char_class_graph = C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA,
348    char_class_lower = C1_LOWER,
349    char_class_print = C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_BLANK | C1_ALPHA,
350    char_class_punct = C1_PUNCT,
351    char_class_space = C1_SPACE,
352    char_class_upper = C1_UPPER,
353    char_class_xdigit = C1_XDIGIT,
354    char_class_blank = C1_BLANK,
355    char_class_underscore = 0x4000,
356    char_class_word = C1_ALPHA | C1_DIGIT | char_class_underscore,
357    char_class_unicode = 0x8000,
358    char_class_win = 0x01FF
359    };
360
361
362 public:
363    static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s);
364 protected:
365    static char regex_message_catalogue[BOOST_REGEX_MAX_PATH];
366    enum syntax_map_size
367    {
368       map_size = UCHAR_MAX + 1
369    };
370
371    static unsigned char syntax_map[map_size];
372    static unsigned short class_map[map_size];
373    static char lower_case_map[map_size];
374
375    static boost::uint_fast32_t BOOST_REGEX_CALL do_lookup_class(const char* p);
376    static bool BOOST_REGEX_CALL do_lookup_collate(std::string& buf, const char* p);
377    static void BOOST_REGEX_CALL do_free();
378    static void BOOST_REGEX_CALL do_init();
379 public:
380    static std::string BOOST_REGEX_CALL error_string(unsigned id);
381    static char* BOOST_REGEX_CALL get_catalogue() { return regex_message_catalogue; }
382 };
383
384
385 } // namespace re_detail
386
387 template<class charT>
388 class w32_regex_traits;
389
390 template<>
391 class BOOST_REGEX_DECL w32_regex_traits<char> : public re_detail::w32_traits_base
392 {
393    typedef re_detail::w32_traits_base base_type;
394 public:
395    typedef char char_type;
396    typedef unsigned char uchar_type;
397    typedef unsigned int size_type;
398    typedef std::string string_type;
399    typedef int locale_type;
400
401    static std::size_t BOOST_REGEX_CALL length(const char_type* p)
402    {
403       return std::strlen(p);
404    }
405    static unsigned int BOOST_REGEX_CALL syntax_type(size_type c)
406    {
407       return syntax_map[c];
408    }
409    static char BOOST_REGEX_CALL translate(char c, bool icase)
410    {
411       return icase ? lower_case_map[(size_type)(uchar_type)c] : c;
412    }
413    static void BOOST_REGEX_CALL transform(std::string& out, const std::string& in);
414
415    static void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in);
416
417    static bool BOOST_REGEX_CALL is_separator(char c)
418    {
419       return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r'));
420    }
421
422    static bool BOOST_REGEX_CALL is_combining(char)
423    {
424       return false;
425    }
426    
427    static bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f)
428    {
429       return BOOST_REGEX_MAKE_BOOL(class_map[(size_type)(uchar_type)c] & f);
430    }
431
432    static int BOOST_REGEX_CALL toi(char c);
433    static int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix);
434
435    static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last)
436    {
437       std::string s(first, last);
438       return do_lookup_class(s.c_str());
439    }
440
441    static bool BOOST_REGEX_CALL lookup_collatename(std::string& buf, const char* first, const char* last)
442    {
443       std::string s(first, last);
444       return do_lookup_collate(buf, s.c_str());
445    }
446
447    static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; }
448    locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); }
449
450    struct sentry
451    {
452       sentry(const w32_regex_traits<char>&)
453       { w32_regex_traits<char>::update(); }
454       ~sentry(){}
455       operator void*() { return this; }
456    };
457    static void BOOST_REGEX_CALL update();
458    w32_regex_traits();
459    ~w32_regex_traits();
460 private:
461    static w32_regex_traits<char> i;
462 };
463
464 #ifndef BOOST_NO_WREGEX
465 template<>
466 class BOOST_REGEX_DECL w32_regex_traits<wchar_t> : public re_detail::w32_traits_base
467 {
468    typedef re_detail::w32_traits_base base_type;
469 public:
470    typedef wchar_t char_type;
471    typedef unsigned short uchar_type;
472    typedef unsigned int size_type;
473    typedef std::basic_string<wchar_t> string_type;
474    typedef int locale_type; 
475    static std::size_t BOOST_REGEX_CALL length(const char_type* p)
476    {
477       return std::wcslen(p);
478    }
479    static unsigned int BOOST_REGEX_CALL syntax_type(size_type c);
480    static wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase)
481    {
482       return icase ? ((c < 256) ? re_detail::wide_lower_case_map[(uchar_type)c] : wtolower(c)) : c;
483    }
484
485    static void BOOST_REGEX_CALL transform(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in);
486
487    static void BOOST_REGEX_CALL transform_primary(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in);
488
489    static bool BOOST_REGEX_CALL is_separator(wchar_t c)
490    {
491       return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029));
492    }
493
494    static bool BOOST_REGEX_CALL is_combining(wchar_t c)
495    { return re_detail::is_combining(c); }
496    
497    static bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f)
498    {
499       return BOOST_REGEX_MAKE_BOOL(((uchar_type)c < 256) ? (wide_unicode_classes[(size_type)(uchar_type)c] & f) : do_iswclass(c, f));
500    }
501
502    static int BOOST_REGEX_CALL toi(wchar_t c);
503    static int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix);
504
505    static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last);
506
507    static bool BOOST_REGEX_CALL lookup_collatename(std::basic_string<wchar_t>& s, const wchar_t* first, const wchar_t* last);
508
509    static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; }
510    locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); }
511
512    struct sentry
513    {
514       sentry(const w32_regex_traits<wchar_t>&)
515       { w32_regex_traits<wchar_t>::update(); }
516       ~sentry(){}
517       operator void*() { return this; }
518    };
519    static void BOOST_REGEX_CALL update();
520    w32_regex_traits();
521    ~w32_regex_traits();
522    static std::size_t BOOST_REGEX_CALL strnarrow(char *s1, std::size_t len, const wchar_t *s2);
523    static std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2);
524
525 private:
526    static bool BOOST_REGEX_CALL do_iswclass(wchar_t c, boost::uint_fast32_t f);
527    static bool BOOST_REGEX_CALL do_lookup_collate(std::basic_string<wchar_t>& out, const wchar_t* first, const wchar_t* last);
528    static w32_regex_traits<wchar_t> init_;
529    static wchar_t BOOST_REGEX_CALL wtolower(wchar_t c);
530    static unsigned short wide_unicode_classes[];
531 };
532 #endif // Wide strings
533 #endif // Win32
534
535 #ifndef BOOST_NO_STD_LOCALE
536
537 } // namspace boost
538
539 #ifdef __BORLANDC__
540   #pragma option pop
541 #endif
542 #include <locale>
543 #ifdef __BORLANDC__
544    #pragma option push -a4 -b -Ve -pc
545 #endif
546
547 namespace boost{
548
549 namespace re_detail
550 {
551
552 template <class charT>
553 struct message_data;
554
555 template <>
556 struct message_data<char>;
557
558 template <>
559 struct message_data<wchar_t>;
560
561 struct BOOST_REGEX_DECL cpp_regex_traits_base : public regex_traits_base
562 {
563    enum char_class_type
564    {
565       char_class_none = 0,
566       char_class_alnum = std::ctype_base::alnum,
567       char_class_alpha = std::ctype_base::alpha,
568       char_class_cntrl = std::ctype_base::cntrl,
569       char_class_digit = std::ctype_base::digit,
570       char_class_graph = std::ctype_base::graph,
571       char_class_lower = std::ctype_base::lower,
572       char_class_print = std::ctype_base::print,
573       char_class_punct = std::ctype_base::punct,
574       char_class_space = std::ctype_base::space,
575       char_class_upper = std::ctype_base::upper,
576       char_class_xdigit = std::ctype_base::xdigit,
577       char_class_blank = 1<<12,
578       char_class_underscore = 1<<13,
579       char_class_word = std::ctype_base::alnum | char_class_underscore,
580       char_class_unicode = 1<<14,
581       char_class_all_base = char_class_alnum | char_class_alpha | char_class_cntrl
582                          | char_class_digit | char_class_graph | char_class_lower
583                          | char_class_print | char_class_punct | char_class_space
584                          | char_class_upper | char_class_xdigit
585    };
586
587    static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s);
588 protected:
589    static char regex_message_cat[BOOST_REGEX_MAX_PATH];
590 };
591
592 } // namespace re_detail
593
594 template <class charT>
595 class cpp_regex_traits;
596
597 template<>
598 class BOOST_REGEX_DECL cpp_regex_traits<char> : public re_detail::cpp_regex_traits_base
599 {
600    typedef re_detail::cpp_regex_traits_base base_type;
601 private:
602    re_detail::message_data<char>* pmd;
603    const unsigned char* psyntax;
604    char* lower_map;
605    const std::ctype<char>* pctype;
606    const std::collate<char>* pcollate;
607    std::locale locale_inst;
608    unsigned sort_type;
609    char sort_delim;
610
611    cpp_regex_traits(const cpp_regex_traits&);
612    cpp_regex_traits& operator=(const cpp_regex_traits&);
613
614 public:
615    typedef char char_type;
616    typedef unsigned char uchar_type;
617    typedef unsigned int size_type;
618    typedef std::string string_type;
619    typedef std::locale locale_type;
620
621    cpp_regex_traits();
622    ~cpp_regex_traits();
623
624    static std::size_t BOOST_REGEX_CALL length(const char_type* p)
625    {
626       return std::strlen(p);
627    }
628    unsigned int BOOST_REGEX_CALL syntax_type(size_type c)const
629    {
630       return psyntax[c];
631    }
632    char BOOST_REGEX_CALL translate(char c, bool icase)const
633    {
634       return icase ? lower_map[(size_type)(uchar_type)c] : c;
635    }
636    void BOOST_REGEX_CALL transform(std::string& out, const std::string& in)const
637    {
638       out = pcollate->transform(in.c_str(), in.c_str() + in.size()).c_str();
639    }
640
641    void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in)const;
642
643    static bool BOOST_REGEX_CALL is_separator(char c)
644    {
645       return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r'));
646    }
647
648    static bool BOOST_REGEX_CALL is_combining(char)
649    {
650       return false;
651    }
652    
653    bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f)const
654    {
655       if(pctype->is((std::ctype<char>::mask)(f & char_class_all_base), c))
656          return true;
657       if((f & char_class_underscore) && (c == '_'))
658          return true;
659       if((f & char_class_blank) && ((c == ' ') || (c == '\t')))
660          return true;
661       return false;
662    }
663
664    int BOOST_REGEX_CALL toi(char c)const;
665    int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix)const;
666
667    boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last)const;
668    bool BOOST_REGEX_CALL lookup_collatename(std::string& s, const char* first, const char* last)const;
669
670    std::string BOOST_REGEX_CALL error_string(unsigned id)const;
671    locale_type BOOST_REGEX_CALL imbue(locale_type l);
672    locale_type BOOST_REGEX_CALL getloc()const{ return locale_inst; }
673
674    struct sentry
675    {
676       sentry(const cpp_regex_traits<char>&){}
677       operator void*() { return this; }
678    };
679 };
680
681 #ifndef BOOST_NO_WREGEX
682 template<>
683 class BOOST_REGEX_DECL cpp_regex_traits<wchar_t> : public re_detail::cpp_regex_traits_base
684 {
685    typedef re_detail::cpp_regex_traits_base base_type;
686 public:
687    typedef wchar_t char_type;
688    typedef unsigned short uchar_type;
689    typedef unsigned int size_type;
690    typedef std::basic_string<wchar_t> string_type;
691    typedef std::locale locale_type;
692
693 private:
694    re_detail::message_data<wchar_t>* pmd;
695    const unsigned char* psyntax;
696    wchar_t* lower_map;
697    const std::ctype<wchar_t>* pctype;
698    const std::collate<wchar_t>* pcollate;
699    const std::codecvt<wchar_t, char, std::mbstate_t>* pcdv;
700    std::locale locale_inst;
701    unsigned int BOOST_REGEX_CALL do_syntax_type(size_type c)const;
702    unsigned sort_type;
703    wchar_t sort_delim;
704
705    cpp_regex_traits(const cpp_regex_traits&);
706    cpp_regex_traits& operator=(const cpp_regex_traits&);
707
708 public:
709
710    static std::size_t BOOST_REGEX_CALL length(const char_type* p)
711    {
712       return std::wcslen(p);
713    }
714    unsigned int BOOST_REGEX_CALL syntax_type(size_type c)const
715    {
716       return (c < UCHAR_MAX) ? psyntax[c] : do_syntax_type(c);
717    }
718    wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase)const
719    {
720       return icase ? (((uchar_type)c) <= UCHAR_MAX) ? lower_map[c] : pctype->tolower(c) : c;
721    }
722    void BOOST_REGEX_CALL transform(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in)const
723    {
724       out = pcollate->transform(in.c_str(), in.c_str() + in.size());
725    }
726
727    void BOOST_REGEX_CALL transform_primary(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in)const;
728
729    static bool BOOST_REGEX_CALL is_separator(wchar_t c)
730    {
731       return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029));
732    }
733
734    static bool BOOST_REGEX_CALL is_combining(wchar_t c)
735    { return re_detail::is_combining(c); }
736    
737    bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f)const
738    {
739       if(pctype->is((std::ctype<wchar_t>::mask)(f & char_class_all_base), c))
740          return true;
741       if((f & char_class_underscore) && (c == '_'))
742          return true;
743       if((f & char_class_blank) && ((c == ' ') || (c == '\t')))
744          return true;
745       if((f & char_class_unicode) && ((uchar_type)c > (uchar_type)255))
746          return true;
747       return false;
748    }
749
750    int BOOST_REGEX_CALL toi(wchar_t c)const;
751    int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix)const;
752
753    boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last)const;
754    bool BOOST_REGEX_CALL lookup_collatename(std::basic_string<wchar_t>& s, const wchar_t* first, const wchar_t* last)const;
755
756    std::string BOOST_REGEX_CALL error_string(unsigned id)const;
757    cpp_regex_traits();
758    ~cpp_regex_traits();
759    locale_type BOOST_REGEX_CALL imbue(locale_type l);
760    locale_type BOOST_REGEX_CALL getloc()const{ return locale_inst; }
761    std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2)const;
762
763    struct sentry
764    {
765       sentry(const cpp_regex_traits<wchar_t>&){}
766       operator void*() { return this; }
767    };
768 };
769 #endif // BOOST_NO_WREGEX
770
771 #endif // BOOST_NO_STD_LOCALE
772
773 #ifdef BOOST_REGEX_USE_WIN32_LOCALE
774
775 template <class charT>
776 class regex_traits : public w32_regex_traits<charT>
777 {
778 };
779
780 #elif defined(BOOST_REGEX_USE_C_LOCALE)
781
782 template <class charT>
783 class regex_traits : public c_regex_traits<charT>
784 {
785 };
786
787 #elif defined(BOOST_REGEX_USE_CPP_LOCALE)
788
789 template <class charT>
790 class regex_traits : public cpp_regex_traits<charT>
791 {
792 };
793
794 #else
795 #error No default localisation model defined
796 #endif
797
798 #ifdef __BORLANDC__
799   #pragma option pop
800 #endif
801
802 } // namespace boost
803
804 #endif // include
805
806
807