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