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