1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
|
/*
*
* Copyright (c) 1998-2002
* John Maddock
*
* Use, modification and distribution are subject to the
* Boost Software License, Version 1.0. (See accompanying file
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE sub_match.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares template class sub_match.
*/
#ifndef BOOST_REGEX_V4_SUB_MATCH_HPP
#define BOOST_REGEX_V4_SUB_MATCH_HPP
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable: 4103)
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
namespace boost{
template <class BidiIterator>
struct sub_match : public std::pair<BidiIterator, BidiIterator>
{
typedef typename re_detail::regex_iterator_traits<BidiIterator>::value_type value_type;
#if defined(BOOST_NO_STD_ITERATOR_TRAITS) || defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef std::ptrdiff_t difference_type;
#else
typedef typename re_detail::regex_iterator_traits<BidiIterator>::difference_type difference_type;
#endif
typedef BidiIterator iterator_type;
typedef BidiIterator iterator;
typedef BidiIterator const_iterator;
bool matched;
sub_match() : std::pair<BidiIterator, BidiIterator>(), matched(false) {}
sub_match(BidiIterator i) : std::pair<BidiIterator, BidiIterator>(i, i), matched(false) {}
#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\
&& !BOOST_WORKAROUND(BOOST_MSVC, < 1310)\
&& !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551)\
&& !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
template <class T, class A>
operator std::basic_string<value_type, T, A> ()const
{
return matched ? std::basic_string<value_type, T, A>(this->first, this->second) : std::basic_string<value_type, T, A>();
}
#else
operator std::basic_string<value_type> ()const
{
return str();
}
#endif
difference_type BOOST_REGEX_CALL length()const
{
difference_type n = matched ? ::boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second) : 0;
return n;
}
std::basic_string<value_type> str()const
{
std::basic_string<value_type> result;
if(matched)
{
std::size_t len = ::boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second);
result.reserve(len);
BidiIterator i = this->first;
while(i != this->second)
{
result.append(1, *i);
++i;
}
}
return result;
}
int compare(const sub_match& s)const
{
if(matched != s.matched)
return static_cast<int>(matched) - static_cast<int>(s.matched);
return str().compare(s.str());
}
int compare(const std::basic_string<value_type>& s)const
{
return str().compare(s);
}
int compare(const value_type* p)const
{
return str().compare(p);
}
bool operator==(const sub_match& that)const
{ return compare(that) == 0; }
bool BOOST_REGEX_CALL operator !=(const sub_match& that)const
{ return compare(that) != 0; }
bool operator<(const sub_match& that)const
{ return compare(that) < 0; }
bool operator>(const sub_match& that)const
{ return compare(that) > 0; }
bool operator<=(const sub_match& that)const
{ return compare(that) <= 0; }
bool operator>=(const sub_match& that)const
{ return compare(that) >= 0; }
#ifdef BOOST_REGEX_MATCH_EXTRA
typedef std::vector<sub_match<BidiIterator> > capture_sequence_type;
const capture_sequence_type& captures()const
{
if(!m_captures)
m_captures.reset(new capture_sequence_type());
return *m_captures;
}
//
// Private implementation API: DO NOT USE!
//
capture_sequence_type& get_captures()const
{
if(!m_captures)
m_captures.reset(new capture_sequence_type());
return *m_captures;
}
private:
mutable boost::scoped_ptr<capture_sequence_type> m_captures;
public:
#endif
sub_match(const sub_match& that, bool
#ifdef BOOST_REGEX_MATCH_EXTRA
deep_copy
#endif
= true
)
: std::pair<BidiIterator, BidiIterator>(that),
matched(that.matched)
{
#ifdef BOOST_REGEX_MATCH_EXTRA
if(that.m_captures)
if(deep_copy)
m_captures.reset(new capture_sequence_type(*(that.m_captures)));
#endif
}
sub_match& operator=(const sub_match& that)
{
this->first = that.first;
this->second = that.second;
matched = that.matched;
#ifdef BOOST_REGEX_MATCH_EXTRA
if(that.m_captures)
get_captures() = *(that.m_captures);
#endif
return *this;
}
#ifdef BOOST_OLD_REGEX_H
//
// the following are deprecated, do not use!!
//
operator int()const;
operator unsigned int()const;
operator short()const
{
return (short)(int)(*this);
}
operator unsigned short()const
{
return (unsigned short)(unsigned int)(*this);
}
#endif
};
typedef sub_match<const char*> csub_match;
typedef sub_match<std::string::const_iterator> ssub_match;
#ifndef BOOST_NO_WREGEX
typedef sub_match<const wchar_t*> wcsub_match;
typedef sub_match<std::wstring::const_iterator> wssub_match;
#endif
// comparison to std::basic_string<> part 1:
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator == (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,
const sub_match<RandomAccessIterator>& m)
{ return s.compare(m.str()) == 0; }
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator != (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,
const sub_match<RandomAccessIterator>& m)
{ return s.compare(m.str()) != 0; }
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator < (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,
const sub_match<RandomAccessIterator>& m)
{ return s.compare(m.str()) < 0; }
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator <= (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,
const sub_match<RandomAccessIterator>& m)
{ return s.compare(m.str()) <= 0; }
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator >= (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,
const sub_match<RandomAccessIterator>& m)
{ return s.compare(m.str()) >= 0; }
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator > (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,
const sub_match<RandomAccessIterator>& m)
{ return s.compare(m.str()) > 0; }
// comparison to std::basic_string<> part 2:
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator == (const sub_match<RandomAccessIterator>& m,
const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s)
{ return m.str().compare(s) == 0; }
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator != (const sub_match<RandomAccessIterator>& m,
const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s)
{ return m.str().compare(s) != 0; }
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator < (const sub_match<RandomAccessIterator>& m,
const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s)
{ return m.str().compare(s) < 0; }
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator > (const sub_match<RandomAccessIterator>& m,
const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s)
{ return m.str().compare(s) > 0; }
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator <= (const sub_match<RandomAccessIterator>& m,
const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s)
{ return m.str().compare(s) <= 0; }
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator >= (const sub_match<RandomAccessIterator>& m,
const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s)
{ return m.str().compare(s) >= 0; }
// comparison to const charT* part 1:
template <class RandomAccessIterator>
inline bool operator == (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s)
{ return m.str().compare(s) == 0; }
template <class RandomAccessIterator>
inline bool operator != (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s)
{ return m.str().compare(s) != 0; }
template <class RandomAccessIterator>
inline bool operator > (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s)
{ return m.str().compare(s) > 0; }
template <class RandomAccessIterator>
inline bool operator < (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s)
{ return m.str().compare(s) < 0; }
template <class RandomAccessIterator>
inline bool operator >= (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s)
{ return m.str().compare(s) >= 0; }
template <class RandomAccessIterator>
inline bool operator <= (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s)
{ return m.str().compare(s) <= 0; }
// comparison to const charT* part 2:
template <class RandomAccessIterator>
inline bool operator == (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(s) == 0; }
template <class RandomAccessIterator>
inline bool operator != (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(s) != 0; }
template <class RandomAccessIterator>
inline bool operator < (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(s) > 0; }
template <class RandomAccessIterator>
inline bool operator > (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(s) < 0; }
template <class RandomAccessIterator>
inline bool operator <= (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(s) >= 0; }
template <class RandomAccessIterator>
inline bool operator >= (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(s) <= 0; }
// comparison to const charT& part 1:
template <class RandomAccessIterator>
inline bool operator == (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s)
{ return m.str().compare(0, m.length(), &s, 1) == 0; }
template <class RandomAccessIterator>
inline bool operator != (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s)
{ return m.str().compare(0, m.length(), &s, 1) != 0; }
template <class RandomAccessIterator>
inline bool operator > (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s)
{ return m.str().compare(0, m.length(), &s, 1) > 0; }
template <class RandomAccessIterator>
inline bool operator < (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s)
{ return m.str().compare(0, m.length(), &s, 1) < 0; }
template <class RandomAccessIterator>
inline bool operator >= (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s)
{ return m.str().compare(0, m.length(), &s, 1) >= 0; }
template <class RandomAccessIterator>
inline bool operator <= (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s)
{ return m.str().compare(0, m.length(), &s, 1) <= 0; }
// comparison to const charT* part 2:
template <class RandomAccessIterator>
inline bool operator == (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(0, m.length(), &s, 1) == 0; }
template <class RandomAccessIterator>
inline bool operator != (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(0, m.length(), &s, 1) != 0; }
template <class RandomAccessIterator>
inline bool operator < (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(0, m.length(), &s, 1) > 0; }
template <class RandomAccessIterator>
inline bool operator > (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(0, m.length(), &s, 1) < 0; }
template <class RandomAccessIterator>
inline bool operator <= (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(0, m.length(), &s, 1) >= 0; }
template <class RandomAccessIterator>
inline bool operator >= (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s,
const sub_match<RandomAccessIterator>& m)
{ return m.str().compare(0, m.length(), &s, 1) <= 0; }
// addition operators:
template <class RandomAccessIterator, class traits, class Allocator>
inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>
operator + (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,
const sub_match<RandomAccessIterator>& m)
{
std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator> result;
result.reserve(s.size() + m.length() + 1);
return result.append(s).append(m.first, m.second);
}
template <class RandomAccessIterator, class traits, class Allocator>
inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>
operator + (const sub_match<RandomAccessIterator>& m,
const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s)
{
std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator> result;
result.reserve(s.size() + m.length() + 1);
return result.append(m.first, m.second).append(s);
}
#if !(defined(__GNUC__) && defined(BOOST_NO_STD_LOCALE))
template <class RandomAccessIterator>
inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
operator + (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s,
const sub_match<RandomAccessIterator>& m)
{
std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result;
result.reserve(std::char_traits<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>::length(s) + m.length() + 1);
return result.append(s).append(m.first, m.second);
}
template <class RandomAccessIterator>
inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
operator + (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const * s)
{
std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result;
result.reserve(std::char_traits<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>::length(s) + m.length() + 1);
return result.append(m.first, m.second).append(s);
}
#else
// worwaround versions:
template <class RandomAccessIterator>
inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
operator + (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s,
const sub_match<RandomAccessIterator>& m)
{
return s + m.str();
}
template <class RandomAccessIterator>
inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
operator + (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const * s)
{
return m.str() + s;
}
#endif
template <class RandomAccessIterator>
inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
operator + (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s,
const sub_match<RandomAccessIterator>& m)
{
std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result;
result.reserve(m.length() + 2);
return result.append(1, s).append(m.first, m.second);
}
template <class RandomAccessIterator>
inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
operator + (const sub_match<RandomAccessIterator>& m,
typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s)
{
std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result;
result.reserve(m.length() + 2);
return result.append(m.first, m.second).append(1, s);
}
template <class RandomAccessIterator>
inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
operator + (const sub_match<RandomAccessIterator>& m1,
const sub_match<RandomAccessIterator>& m2)
{
std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result;
result.reserve(m1.length() + m2.length() + 1);
return result.append(m1.first, m1.second).append(m2.first, m2.second);
}
#ifndef BOOST_NO_STD_LOCALE
template <class charT, class traits, class RandomAccessIterator>
std::basic_ostream<charT, traits>&
operator << (std::basic_ostream<charT, traits>& os,
const sub_match<RandomAccessIterator>& s)
{
return (os << s.str());
}
#else
template <class RandomAccessIterator>
std::ostream& operator << (std::ostream& os,
const sub_match<RandomAccessIterator>& s)
{
return (os << s.str());
}
#endif
#ifdef BOOST_OLD_REGEX_H
namespace re_detail{
template <class BidiIterator, class charT>
int do_toi(BidiIterator i, BidiIterator j, char c, int radix)
{
std::string s(i, j);
char* p;
int result = std::strtol(s.c_str(), &p, radix);
if(*p)raise_regex_exception("Bad sub-expression");
return result;
}
//
// helper:
template <class I, class charT>
int do_toi(I& i, I j, charT c)
{
int result = 0;
while((i != j) && (isdigit(*i)))
{
result = result*10 + (*i - '0');
++i;
}
return result;
}
}
template <class BidiIterator>
sub_match<BidiIterator>::operator int()const
{
BidiIterator i = first;
BidiIterator j = second;
if(i == j)raise_regex_exception("Bad sub-expression");
int neg = 1;
if((i != j) && (*i == '-'))
{
neg = -1;
++i;
}
neg *= re_detail::do_toi(i, j, *i);
if(i != j)raise_regex_exception("Bad sub-expression");
return neg;
}
template <class BidiIterator>
sub_match<BidiIterator>::operator unsigned int()const
{
BidiIterator i = first;
BidiIterator j = second;
if(i == j)
raise_regex_exception("Bad sub-expression");
return re_detail::do_toi(i, j, *first);
}
#endif
} // namespace boost
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable: 4103)
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
|