~ubuntu-branches/ubuntu/breezy/aqsis/breezy

« back to all changes in this revision

Viewing changes to boost/boost/regex/v3/regex_traits.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Will Newton
  • Date: 2004-12-07 20:06:49 UTC
  • Revision ID: james.westby@ubuntu.com-20041207200649-fccswkrvp4oc8lmn
Tags: upstream-0.9.3
ImportĀ upstreamĀ versionĀ 0.9.3

Show diffs side-by-side

added added

removed removed

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