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