OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [or1knd-elf/] [include/] [c++/] [4.8.0/] [ext/] [vstring.h] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
// Versatile string -*- C++ -*-
2
 
3
// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4
// Free Software Foundation, Inc.
5
//
6
// This file is part of the GNU ISO C++ Library.  This library is free
7
// software; you can redistribute it and/or modify it under the
8
// terms of the GNU General Public License as published by the
9
// Free Software Foundation; either version 3, or (at your option)
10
// any later version.
11
 
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
 
17
// Under Section 7 of GPL version 3, you are granted additional
18
// permissions described in the GCC Runtime Library Exception, version
19
// 3.1, as published by the Free Software Foundation.
20
 
21
// You should have received a copy of the GNU General Public License and
22
// a copy of the GCC Runtime Library Exception along with this program;
23
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24
// <http://www.gnu.org/licenses/>.
25
 
26
/** @file ext/vstring.h
27
 *  This file is a GNU extension to the Standard C++ Library.
28
 */
29
 
30
#ifndef _VSTRING_H
31
#define _VSTRING_H 1
32
 
33
#pragma GCC system_header
34
 
35
#if __cplusplus >= 201103L
36
#include <initializer_list>
37
#endif
38
 
39
#include <ext/vstring_util.h>
40
#include <ext/rc_string_base.h>
41
#include <ext/sso_string_base.h>
42
 
43
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
44
{
45
_GLIBCXX_BEGIN_NAMESPACE_VERSION
46
 
47
  /**
48
   *  @class __versa_string vstring.h
49
   *  @brief  Template class __versa_string.
50
   *  @ingroup extensions
51
   *
52
   *  Data structure managing sequences of characters and
53
   *  character-like objects.
54
   */
55
  template<typename _CharT, typename _Traits, typename _Alloc,
56
           template <typename, typename, typename> class _Base>
57
    class __versa_string
58
    : private _Base<_CharT, _Traits, _Alloc>
59
    {
60
      typedef _Base<_CharT, _Traits, _Alloc>                __vstring_base;
61
      typedef typename __vstring_base::_CharT_alloc_type    _CharT_alloc_type;
62
 
63
      // Types:
64
    public:
65
      typedef _Traits                                       traits_type;
66
      typedef typename _Traits::char_type                   value_type;
67
      typedef _Alloc                                        allocator_type;
68
      typedef typename _CharT_alloc_type::size_type         size_type;
69
      typedef typename _CharT_alloc_type::difference_type   difference_type;
70
      typedef value_type&                                   reference;
71
      typedef const value_type&                             const_reference;
72
      typedef typename _CharT_alloc_type::pointer           pointer;
73
      typedef typename _CharT_alloc_type::const_pointer     const_pointer;
74
      typedef __gnu_cxx::__normal_iterator<pointer, __versa_string>  iterator;
75
      typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
76
                                                            const_iterator;
77
      typedef std::reverse_iterator<const_iterator>     const_reverse_iterator;
78
      typedef std::reverse_iterator<iterator>               reverse_iterator;
79
 
80
      // Data Member (public):
81
      ///  Value returned by various member functions when they fail.
82
      static const size_type    npos = static_cast<size_type>(-1);
83
 
84
    private:
85
      size_type
86
      _M_check(size_type __pos, const char* __s) const
87
      {
88
        if (__pos > this->size())
89
          std::__throw_out_of_range(__N(__s));
90
        return __pos;
91
      }
92
 
93
      void
94
      _M_check_length(size_type __n1, size_type __n2, const char* __s) const
95
      {
96
        if (this->max_size() - (this->size() - __n1) < __n2)
97
          std::__throw_length_error(__N(__s));
98
      }
99
 
100
      // NB: _M_limit doesn't check for a bad __pos value.
101
      size_type
102
      _M_limit(size_type __pos, size_type __off) const
103
      {
104
        const bool __testoff =  __off < this->size() - __pos;
105
        return __testoff ? __off : this->size() - __pos;
106
      }
107
 
108
      // True if _Rep and source do not overlap.
109
      bool
110
      _M_disjunct(const _CharT* __s) const
111
      {
112
        return (std::less<const _CharT*>()(__s, this->_M_data())
113
                || std::less<const _CharT*>()(this->_M_data()
114
                                              + this->size(), __s));
115
      }
116
 
117
      // For the internal use we have functions similar to `begin'/`end'
118
      // but they do not call _M_leak.
119
      iterator
120
      _M_ibegin() const
121
      { return iterator(this->_M_data()); }
122
 
123
      iterator
124
      _M_iend() const
125
      { return iterator(this->_M_data() + this->_M_length()); }
126
 
127
    public:
128
      // Construct/copy/destroy:
129
      // NB: We overload ctors in some cases instead of using default
130
      // arguments, per 17.4.4.4 para. 2 item 2.
131
 
132
      /**
133
       *  @brief  Default constructor creates an empty string.
134
       */
135
      __versa_string()
136
      : __vstring_base() { }
137
 
138
      /**
139
       *  @brief  Construct an empty string using allocator @a a.
140
       */
141
      explicit
142
      __versa_string(const _Alloc& __a)
143
      : __vstring_base(__a) { }
144
 
145
      // NB: per LWG issue 42, semantics different from IS:
146
      /**
147
       *  @brief  Construct string with copy of value of @a __str.
148
       *  @param  __str  Source string.
149
       */
150
      __versa_string(const __versa_string& __str)
151
      : __vstring_base(__str) { }
152
 
153
#if __cplusplus >= 201103L
154
      /**
155
       *  @brief  String move constructor.
156
       *  @param  __str  Source string.
157
       *
158
       *  The newly-constructed %string contains the exact contents of
159
       *  @a __str.  The contents of @a __str are a valid, but unspecified
160
       *  string.
161
       */
162
      __versa_string(__versa_string&& __str) noexcept
163
      : __vstring_base(std::move(__str)) { }
164
 
165
      /**
166
       *  @brief  Construct string from an initializer list.
167
       *  @param  __l  std::initializer_list of characters.
168
       *  @param  __a  Allocator to use (default is default allocator).
169
       */
170
      __versa_string(std::initializer_list<_CharT> __l,
171
                     const _Alloc& __a = _Alloc())
172
      : __vstring_base(__l.begin(), __l.end(), __a) { }
173
#endif
174
 
175
      /**
176
       *  @brief  Construct string as copy of a substring.
177
       *  @param  __str  Source string.
178
       *  @param  __pos  Index of first character to copy from.
179
       *  @param  __n  Number of characters to copy (default remainder).
180
       */
181
      __versa_string(const __versa_string& __str, size_type __pos,
182
                     size_type __n = npos)
183
      : __vstring_base(__str._M_data()
184
                       + __str._M_check(__pos,
185
                                        "__versa_string::__versa_string"),
186
                       __str._M_data() + __str._M_limit(__pos, __n)
187
                       + __pos, _Alloc()) { }
188
 
189
      /**
190
       *  @brief  Construct string as copy of a substring.
191
       *  @param  __str  Source string.
192
       *  @param  __pos  Index of first character to copy from.
193
       *  @param  __n  Number of characters to copy.
194
       *  @param  __a  Allocator to use.
195
       */
196
      __versa_string(const __versa_string& __str, size_type __pos,
197
                     size_type __n, const _Alloc& __a)
198
      : __vstring_base(__str._M_data()
199
                       + __str._M_check(__pos,
200
                                        "__versa_string::__versa_string"),
201
                       __str._M_data() + __str._M_limit(__pos, __n)
202
                       + __pos, __a) { }
203
 
204
      /**
205
       *  @brief  Construct string initialized by a character array.
206
       *  @param  __s  Source character array.
207
       *  @param  __n  Number of characters to copy.
208
       *  @param  __a  Allocator to use (default is default allocator).
209
       *
210
       *  NB: @a __s must have at least @a __n characters, '\\0' has no special
211
       *  meaning.
212
       */
213
      __versa_string(const _CharT* __s, size_type __n,
214
                     const _Alloc& __a = _Alloc())
215
      : __vstring_base(__s, __s + __n, __a) { }
216
 
217
      /**
218
       *  @brief  Construct string as copy of a C string.
219
       *  @param  __s  Source C string.
220
       *  @param  __a  Allocator to use (default is default allocator).
221
       */
222
      __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
223
      : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
224
                       __s + npos, __a) { }
225
 
226
      /**
227
       *  @brief  Construct string as multiple characters.
228
       *  @param  __n  Number of characters.
229
       *  @param  __c  Character to use.
230
       *  @param  __a  Allocator to use (default is default allocator).
231
       */
232
      __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
233
      : __vstring_base(__n, __c, __a) { }
234
 
235
      /**
236
       *  @brief  Construct string as copy of a range.
237
       *  @param  __beg  Start of range.
238
       *  @param  __end  End of range.
239
       *  @param  __a  Allocator to use (default is default allocator).
240
       */
241
#if __cplusplus >= 201103L
242
      template<class _InputIterator,
243
               typename = std::_RequireInputIter<_InputIterator>>
244
#else
245
      template<class _InputIterator>
246
#endif
247
        __versa_string(_InputIterator __beg, _InputIterator __end,
248
                       const _Alloc& __a = _Alloc())
249
        : __vstring_base(__beg, __end, __a) { }
250
 
251
      /**
252
       *  @brief  Destroy the string instance.
253
       */
254
      ~__versa_string() _GLIBCXX_NOEXCEPT { }
255
 
256
      /**
257
       *  @brief  Assign the value of @a str to this string.
258
       *  @param  __str  Source string.
259
       */
260
      __versa_string&
261
      operator=(const __versa_string& __str)
262
      { return this->assign(__str); }
263
 
264
#if __cplusplus >= 201103L
265
      /**
266
       *  @brief  String move assignment operator.
267
       *  @param  __str  Source string.
268
       *
269
       *  The contents of @a __str are moved into this string (without
270
       *  copying).  @a __str is a valid, but unspecified string.
271
       */
272
      __versa_string&
273
      operator=(__versa_string&& __str)
274
      {
275
        // NB: DR 1204.
276
        this->swap(__str);
277
        return *this;
278
      }
279
 
280
      /**
281
       *  @brief  Set value to string constructed from initializer list.
282
       *  @param  __l  std::initializer_list.
283
       */
284
      __versa_string&
285
      operator=(std::initializer_list<_CharT> __l)
286
      {
287
        this->assign(__l.begin(), __l.end());
288
        return *this;
289
      }
290
#endif
291
 
292
      /**
293
       *  @brief  Copy contents of @a __s into this string.
294
       *  @param  __s  Source null-terminated string.
295
       */
296
      __versa_string&
297
      operator=(const _CharT* __s)
298
      { return this->assign(__s); }
299
 
300
      /**
301
       *  @brief  Set value to string of length 1.
302
       *  @param  __c  Source character.
303
       *
304
       *  Assigning to a character makes this string length 1 and
305
       *  (*this)[0] == @a __c.
306
       */
307
      __versa_string&
308
      operator=(_CharT __c)
309
      {
310
        this->assign(1, __c);
311
        return *this;
312
      }
313
 
314
      // Iterators:
315
      /**
316
       *  Returns a read/write iterator that points to the first character in
317
       *  the %string.  Unshares the string.
318
       */
319
      iterator
320
      begin() _GLIBCXX_NOEXCEPT
321
      {
322
        this->_M_leak();
323
        return iterator(this->_M_data());
324
      }
325
 
326
      /**
327
       *  Returns a read-only (constant) iterator that points to the first
328
       *  character in the %string.
329
       */
330
      const_iterator
331
      begin() const _GLIBCXX_NOEXCEPT
332
      { return const_iterator(this->_M_data()); }
333
 
334
      /**
335
       *  Returns a read/write iterator that points one past the last
336
       *  character in the %string.  Unshares the string.
337
       */
338
      iterator
339
      end() _GLIBCXX_NOEXCEPT
340
      {
341
        this->_M_leak();
342
        return iterator(this->_M_data() + this->size());
343
      }
344
 
345
      /**
346
       *  Returns a read-only (constant) iterator that points one past the
347
       *  last character in the %string.
348
       */
349
      const_iterator
350
      end() const _GLIBCXX_NOEXCEPT
351
      { return const_iterator(this->_M_data() + this->size()); }
352
 
353
      /**
354
       *  Returns a read/write reverse iterator that points to the last
355
       *  character in the %string.  Iteration is done in reverse element
356
       *  order.  Unshares the string.
357
       */
358
      reverse_iterator
359
      rbegin() _GLIBCXX_NOEXCEPT
360
      { return reverse_iterator(this->end()); }
361
 
362
      /**
363
       *  Returns a read-only (constant) reverse iterator that points
364
       *  to the last character in the %string.  Iteration is done in
365
       *  reverse element order.
366
       */
367
      const_reverse_iterator
368
      rbegin() const _GLIBCXX_NOEXCEPT
369
      { return const_reverse_iterator(this->end()); }
370
 
371
      /**
372
       *  Returns a read/write reverse iterator that points to one before the
373
       *  first character in the %string.  Iteration is done in reverse
374
       *  element order.  Unshares the string.
375
       */
376
      reverse_iterator
377
      rend() _GLIBCXX_NOEXCEPT
378
      { return reverse_iterator(this->begin()); }
379
 
380
      /**
381
       *  Returns a read-only (constant) reverse iterator that points
382
       *  to one before the first character in the %string.  Iteration
383
       *  is done in reverse element order.
384
       */
385
      const_reverse_iterator
386
      rend() const _GLIBCXX_NOEXCEPT
387
      { return const_reverse_iterator(this->begin()); }
388
 
389
#if __cplusplus >= 201103L
390
      /**
391
       *  Returns a read-only (constant) iterator that points to the first
392
       *  character in the %string.
393
       */
394
      const_iterator
395
      cbegin() const noexcept
396
      { return const_iterator(this->_M_data()); }
397
 
398
      /**
399
       *  Returns a read-only (constant) iterator that points one past the
400
       *  last character in the %string.
401
       */
402
      const_iterator
403
      cend() const noexcept
404
      { return const_iterator(this->_M_data() + this->size()); }
405
 
406
      /**
407
       *  Returns a read-only (constant) reverse iterator that points
408
       *  to the last character in the %string.  Iteration is done in
409
       *  reverse element order.
410
       */
411
      const_reverse_iterator
412
      crbegin() const noexcept
413
      { return const_reverse_iterator(this->end()); }
414
 
415
      /**
416
       *  Returns a read-only (constant) reverse iterator that points
417
       *  to one before the first character in the %string.  Iteration
418
       *  is done in reverse element order.
419
       */
420
      const_reverse_iterator
421
      crend() const noexcept
422
      { return const_reverse_iterator(this->begin()); }
423
#endif
424
 
425
    public:
426
      // Capacity:
427
      ///  Returns the number of characters in the string, not including any
428
      ///  null-termination.
429
      size_type
430
      size() const _GLIBCXX_NOEXCEPT
431
      { return this->_M_length(); }
432
 
433
      ///  Returns the number of characters in the string, not including any
434
      ///  null-termination.
435
      size_type
436
      length() const _GLIBCXX_NOEXCEPT
437
      { return this->_M_length(); }
438
 
439
      /// Returns the size() of the largest possible %string.
440
      size_type
441
      max_size() const _GLIBCXX_NOEXCEPT
442
      { return this->_M_max_size(); }
443
 
444
      /**
445
       *  @brief  Resizes the %string to the specified number of characters.
446
       *  @param  __n  Number of characters the %string should contain.
447
       *  @param  __c  Character to fill any new elements.
448
       *
449
       *  This function will %resize the %string to the specified
450
       *  number of characters.  If the number is smaller than the
451
       *  %string's current size the %string is truncated, otherwise
452
       *  the %string is extended and new elements are set to @a __c.
453
       */
454
      void
455
      resize(size_type __n, _CharT __c);
456
 
457
      /**
458
       *  @brief  Resizes the %string to the specified number of characters.
459
       *  @param  __n  Number of characters the %string should contain.
460
       *
461
       *  This function will resize the %string to the specified
462
       *  length.  If the new size is smaller than the %string's
463
       *  current size the %string is truncated, otherwise the %string
464
       *  is extended and new characters are default-constructed.  For
465
       *  basic types such as char, this means setting them to 0.
466
       */
467
      void
468
      resize(size_type __n)
469
      { this->resize(__n, _CharT()); }
470
 
471
#if __cplusplus >= 201103L
472
      /// A non-binding request to reduce capacity() to size().
473
      void
474
      shrink_to_fit()
475
      {
476
        if (capacity() > size())
477
          {
478
            __try
479
              { this->reserve(0); }
480
            __catch(...)
481
              { }
482
          }
483
      }
484
#endif
485
 
486
      /**
487
       *  Returns the total number of characters that the %string can
488
       *  hold before needing to allocate more memory.
489
       */
490
      size_type
491
      capacity() const _GLIBCXX_NOEXCEPT
492
      { return this->_M_capacity(); }
493
 
494
      /**
495
       *  @brief  Attempt to preallocate enough memory for specified number of
496
       *          characters.
497
       *  @param  __res_arg  Number of characters required.
498
       *  @throw  std::length_error  If @a __res_arg exceeds @c max_size().
499
       *
500
       *  This function attempts to reserve enough memory for the
501
       *  %string to hold the specified number of characters.  If the
502
       *  number requested is more than max_size(), length_error is
503
       *  thrown.
504
       *
505
       *  The advantage of this function is that if optimal code is a
506
       *  necessity and the user can determine the string length that
507
       *  will be required, the user can reserve the memory in
508
       *  %advance, and thus prevent a possible reallocation of memory
509
       *  and copying of %string data.
510
       */
511
      void
512
      reserve(size_type __res_arg = 0)
513
      { this->_M_reserve(__res_arg); }
514
 
515
      /**
516
       *  Erases the string, making it empty.
517
       */
518
      void
519
      clear() _GLIBCXX_NOEXCEPT
520
      { this->_M_clear(); }
521
 
522
      /**
523
       *  Returns true if the %string is empty.  Equivalent to
524
       *  <code>*this == ""</code>.
525
       */
526
      bool
527
      empty() const _GLIBCXX_NOEXCEPT
528
      { return this->size() == 0; }
529
 
530
      // Element access:
531
      /**
532
       *  @brief  Subscript access to the data contained in the %string.
533
       *  @param  __pos  The index of the character to access.
534
       *  @return  Read-only (constant) reference to the character.
535
       *
536
       *  This operator allows for easy, array-style, data access.
537
       *  Note that data access with this operator is unchecked and
538
       *  out_of_range lookups are not defined. (For checked lookups
539
       *  see at().)
540
       */
541
      const_reference
542
      operator[] (size_type __pos) const
543
      {
544
        _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
545
        return this->_M_data()[__pos];
546
      }
547
 
548
      /**
549
       *  @brief  Subscript access to the data contained in the %string.
550
       *  @param  __pos  The index of the character to access.
551
       *  @return  Read/write reference to the character.
552
       *
553
       *  This operator allows for easy, array-style, data access.
554
       *  Note that data access with this operator is unchecked and
555
       *  out_of_range lookups are not defined. (For checked lookups
556
       *  see at().)  Unshares the string.
557
       */
558
      reference
559
      operator[](size_type __pos)
560
      {
561
        // allow pos == size() as v3 extension:
562
        _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
563
        // but be strict in pedantic mode:
564
        _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
565
        this->_M_leak();
566
        return this->_M_data()[__pos];
567
      }
568
 
569
      /**
570
       *  @brief  Provides access to the data contained in the %string.
571
       *  @param __n The index of the character to access.
572
       *  @return  Read-only (const) reference to the character.
573
       *  @throw  std::out_of_range  If @a __n is an invalid index.
574
       *
575
       *  This function provides for safer data access.  The parameter
576
       *  is first checked that it is in the range of the string.  The
577
       *  function throws out_of_range if the check fails.
578
       */
579
      const_reference
580
      at(size_type __n) const
581
      {
582
        if (__n >= this->size())
583
          std::__throw_out_of_range(__N("__versa_string::at"));
584
        return this->_M_data()[__n];
585
      }
586
 
587
      /**
588
       *  @brief  Provides access to the data contained in the %string.
589
       *  @param __n The index of the character to access.
590
       *  @return  Read/write reference to the character.
591
       *  @throw  std::out_of_range  If @a __n is an invalid index.
592
       *
593
       *  This function provides for safer data access.  The parameter
594
       *  is first checked that it is in the range of the string.  The
595
       *  function throws out_of_range if the check fails.  Success
596
       *  results in unsharing the string.
597
       */
598
      reference
599
      at(size_type __n)
600
      {
601
        if (__n >= this->size())
602
          std::__throw_out_of_range(__N("__versa_string::at"));
603
        this->_M_leak();
604
        return this->_M_data()[__n];
605
      }
606
 
607
#if __cplusplus >= 201103L
608
      /**
609
       *  Returns a read/write reference to the data at the first
610
       *  element of the %string.
611
       */
612
      reference
613
      front()
614
      { return operator[](0); }
615
 
616
      /**
617
       *  Returns a read-only (constant) reference to the data at the first
618
       *  element of the %string.
619
       */
620
      const_reference
621
      front() const
622
      { return operator[](0); }
623
 
624
      /**
625
       *  Returns a read/write reference to the data at the last
626
       *  element of the %string.
627
       */
628
      reference
629
      back()
630
      { return operator[](this->size() - 1); }
631
 
632
      /**
633
       *  Returns a read-only (constant) reference to the data at the
634
       *  last element of the %string.
635
       */
636
      const_reference
637
      back() const
638
      { return operator[](this->size() - 1); }
639
#endif
640
 
641
      // Modifiers:
642
      /**
643
       *  @brief  Append a string to this string.
644
       *  @param __str  The string to append.
645
       *  @return  Reference to this string.
646
       */
647
      __versa_string&
648
      operator+=(const __versa_string& __str)
649
      { return this->append(__str); }
650
 
651
      /**
652
       *  @brief  Append a C string.
653
       *  @param __s  The C string to append.
654
       *  @return  Reference to this string.
655
       */
656
      __versa_string&
657
      operator+=(const _CharT* __s)
658
      { return this->append(__s); }
659
 
660
      /**
661
       *  @brief  Append a character.
662
       *  @param __c  The character to append.
663
       *  @return  Reference to this string.
664
       */
665
      __versa_string&
666
      operator+=(_CharT __c)
667
      {
668
        this->push_back(__c);
669
        return *this;
670
      }
671
 
672
#if __cplusplus >= 201103L
673
      /**
674
       *  @brief  Append an initializer_list of characters.
675
       *  @param __l  The initializer_list of characters to be appended.
676
       *  @return  Reference to this string.
677
       */
678
      __versa_string&
679
      operator+=(std::initializer_list<_CharT> __l)
680
      { return this->append(__l.begin(), __l.end()); }
681
#endif // C++11
682
 
683
      /**
684
       *  @brief  Append a string to this string.
685
       *  @param __str  The string to append.
686
       *  @return  Reference to this string.
687
       */
688
      __versa_string&
689
      append(const __versa_string& __str)
690
      { return _M_append(__str._M_data(), __str.size()); }
691
 
692
      /**
693
       *  @brief  Append a substring.
694
       *  @param __str  The string to append.
695
       *  @param __pos  Index of the first character of str to append.
696
       *  @param __n  The number of characters to append.
697
       *  @return  Reference to this string.
698
       *  @throw  std::out_of_range if @a pos is not a valid index.
699
       *
700
       *  This function appends @a __n characters from @a __str
701
       *  starting at @a __pos to this string.  If @a __n is is larger
702
       *  than the number of available characters in @a __str, the
703
       *  remainder of @a __str is appended.
704
       */
705
      __versa_string&
706
      append(const __versa_string& __str, size_type __pos, size_type __n)
707
      { return _M_append(__str._M_data()
708
                         + __str._M_check(__pos, "__versa_string::append"),
709
                         __str._M_limit(__pos, __n)); }
710
 
711
      /**
712
       *  @brief  Append a C substring.
713
       *  @param __s  The C string to append.
714
       *  @param __n  The number of characters to append.
715
       *  @return  Reference to this string.
716
       */
717
      __versa_string&
718
      append(const _CharT* __s, size_type __n)
719
      {
720
        __glibcxx_requires_string_len(__s, __n);
721
        _M_check_length(size_type(0), __n, "__versa_string::append");
722
        return _M_append(__s, __n);
723
      }
724
 
725
      /**
726
       *  @brief  Append a C string.
727
       *  @param __s  The C string to append.
728
       *  @return  Reference to this string.
729
       */
730
      __versa_string&
731
      append(const _CharT* __s)
732
      {
733
        __glibcxx_requires_string(__s);
734
        const size_type __n = traits_type::length(__s);
735
        _M_check_length(size_type(0), __n, "__versa_string::append");
736
        return _M_append(__s, __n);
737
      }
738
 
739
      /**
740
       *  @brief  Append multiple characters.
741
       *  @param __n  The number of characters to append.
742
       *  @param __c  The character to use.
743
       *  @return  Reference to this string.
744
       *
745
       *  Appends n copies of c to this string.
746
       */
747
      __versa_string&
748
      append(size_type __n, _CharT __c)
749
      { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
750
 
751
#if __cplusplus >= 201103L
752
      /**
753
       *  @brief  Append an initializer_list of characters.
754
       *  @param __l  The initializer_list of characters to append.
755
       *  @return  Reference to this string.
756
       */
757
      __versa_string&
758
      append(std::initializer_list<_CharT> __l)
759
      { return this->append(__l.begin(), __l.end()); }
760
#endif // C++11
761
 
762
      /**
763
       *  @brief  Append a range of characters.
764
       *  @param __first  Iterator referencing the first character to append.
765
       *  @param __last  Iterator marking the end of the range.
766
       *  @return  Reference to this string.
767
       *
768
       *  Appends characters in the range [first,last) to this string.
769
       */
770
#if __cplusplus >= 201103L
771
      template<class _InputIterator,
772
               typename = std::_RequireInputIter<_InputIterator>>
773
#else
774
      template<class _InputIterator>
775
#endif
776
        __versa_string&
777
        append(_InputIterator __first, _InputIterator __last)
778
        { return this->replace(_M_iend(), _M_iend(), __first, __last); }
779
 
780
      /**
781
       *  @brief  Append a single character.
782
       *  @param __c  Character to append.
783
       */
784
      void
785
      push_back(_CharT __c)
786
      {
787
        const size_type __size = this->size();
788
        if (__size + 1 > this->capacity() || this->_M_is_shared())
789
          this->_M_mutate(__size, size_type(0), 0, size_type(1));
790
        traits_type::assign(this->_M_data()[__size], __c);
791
        this->_M_set_length(__size + 1);
792
      }
793
 
794
      /**
795
       *  @brief  Set value to contents of another string.
796
       *  @param  __str  Source string to use.
797
       *  @return  Reference to this string.
798
       */
799
      __versa_string&
800
      assign(const __versa_string& __str)
801
      {
802
        this->_M_assign(__str);
803
        return *this;
804
      }
805
 
806
#if __cplusplus >= 201103L
807
      /**
808
       *  @brief  Set value to contents of another string.
809
       *  @param  __str  Source string to use.
810
       *  @return  Reference to this string.
811
       *
812
       *  This function sets this string to the exact contents of @a __str.
813
       *  @a __str is a valid, but unspecified string.
814
       */
815
      __versa_string&
816
      assign(__versa_string&& __str)
817
      {
818
        this->swap(__str);
819
        return *this;
820
      }
821
#endif // C++11
822
 
823
      /**
824
       *  @brief  Set value to a substring of a string.
825
       *  @param __str  The string to use.
826
       *  @param __pos  Index of the first character of str.
827
       *  @param __n  Number of characters to use.
828
       *  @return  Reference to this string.
829
       *  @throw  std::out_of_range if @a __pos is not a valid index.
830
       *
831
       *  This function sets this string to the substring of @a __str
832
       *  consisting of @a __n characters at @a __pos.  If @a __n is
833
       *  is larger than the number of available characters in @a
834
       *  __str, the remainder of @a __str is used.
835
       */
836
      __versa_string&
837
      assign(const __versa_string& __str, size_type __pos, size_type __n)
838
      { return _M_replace(size_type(0), this->size(), __str._M_data()
839
                          + __str._M_check(__pos, "__versa_string::assign"),
840
                          __str._M_limit(__pos, __n)); }
841
 
842
      /**
843
       *  @brief  Set value to a C substring.
844
       *  @param __s  The C string to use.
845
       *  @param __n  Number of characters to use.
846
       *  @return  Reference to this string.
847
       *
848
       *  This function sets the value of this string to the first @a
849
       *  __n characters of @a __s.  If @a __n is is larger than the
850
       *  number of available characters in @a __s, the remainder of
851
       *  @a __s is used.
852
       */
853
      __versa_string&
854
      assign(const _CharT* __s, size_type __n)
855
      {
856
        __glibcxx_requires_string_len(__s, __n);
857
        return _M_replace(size_type(0), this->size(), __s, __n);
858
      }
859
 
860
      /**
861
       *  @brief  Set value to contents of a C string.
862
       *  @param __s  The C string to use.
863
       *  @return  Reference to this string.
864
       *
865
       *  This function sets the value of this string to the value of
866
       *  @a __s.  The data is copied, so there is no dependence on @a
867
       *  __s once the function returns.
868
       */
869
      __versa_string&
870
      assign(const _CharT* __s)
871
      {
872
        __glibcxx_requires_string(__s);
873
        return _M_replace(size_type(0), this->size(), __s,
874
                          traits_type::length(__s));
875
      }
876
 
877
      /**
878
       *  @brief  Set value to multiple characters.
879
       *  @param __n  Length of the resulting string.
880
       *  @param __c  The character to use.
881
       *  @return  Reference to this string.
882
       *
883
       *  This function sets the value of this string to @a __n copies of
884
       *  character @a __c.
885
       */
886
      __versa_string&
887
      assign(size_type __n, _CharT __c)
888
      { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
889
 
890
      /**
891
       *  @brief  Set value to a range of characters.
892
       *  @param __first  Iterator referencing the first character to append.
893
       *  @param __last  Iterator marking the end of the range.
894
       *  @return  Reference to this string.
895
       *
896
       *  Sets value of string to characters in the range
897
       *  [first,last).
898
      */
899
#if __cplusplus >= 201103L
900
      template<class _InputIterator,
901
               typename = std::_RequireInputIter<_InputIterator>>
902
#else
903
      template<class _InputIterator>
904
#endif
905
        __versa_string&
906
        assign(_InputIterator __first, _InputIterator __last)
907
        { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
908
 
909
#if __cplusplus >= 201103L
910
      /**
911
       *  @brief  Set value to an initializer_list of characters.
912
       *  @param __l  The initializer_list of characters to assign.
913
       *  @return  Reference to this string.
914
       */
915
      __versa_string&
916
      assign(std::initializer_list<_CharT> __l)
917
      { return this->assign(__l.begin(), __l.end()); }
918
#endif // C++11
919
 
920
      /**
921
       *  @brief  Insert multiple characters.
922
       *  @param __p  Iterator referencing location in string to insert at.
923
       *  @param __n  Number of characters to insert
924
       *  @param __c  The character to insert.
925
       *  @throw  std::length_error  If new length exceeds @c max_size().
926
       *
927
       *  Inserts @a __n copies of character @a __c starting at the
928
       *  position referenced by iterator @a __p.  If adding
929
       *  characters causes the length to exceed max_size(),
930
       *  length_error is thrown.  The value of the string doesn't
931
       *  change if an error is thrown.
932
      */
933
      void
934
      insert(iterator __p, size_type __n, _CharT __c)
935
      { this->replace(__p, __p, __n, __c);  }
936
 
937
      /**
938
       *  @brief  Insert a range of characters.
939
       *  @param __p  Iterator referencing location in string to insert at.
940
       *  @param __beg  Start of range.
941
       *  @param __end  End of range.
942
       *  @throw  std::length_error  If new length exceeds @c max_size().
943
       *
944
       *  Inserts characters in range [beg,end).  If adding characters
945
       *  causes the length to exceed max_size(), length_error is
946
       *  thrown.  The value of the string doesn't change if an error
947
       *  is thrown.
948
      */
949
#if __cplusplus >= 201103L
950
      template<class _InputIterator,
951
               typename = std::_RequireInputIter<_InputIterator>>
952
#else
953
      template<class _InputIterator>
954
#endif
955
        void
956
        insert(iterator __p, _InputIterator __beg, _InputIterator __end)
957
        { this->replace(__p, __p, __beg, __end); }
958
 
959
#if __cplusplus >= 201103L
960
      /**
961
       *  @brief  Insert an initializer_list of characters.
962
       *  @param __p  Iterator referencing location in string to insert at.
963
       *  @param __l  The initializer_list of characters to insert.
964
       *  @throw  std::length_error  If new length exceeds @c max_size().
965
       */
966
      void
967
      insert(iterator __p, std::initializer_list<_CharT> __l)
968
      { this->insert(__p, __l.begin(), __l.end()); }
969
#endif // C++11
970
 
971
      /**
972
       *  @brief  Insert value of a string.
973
       *  @param __pos1  Iterator referencing location in string to insert at.
974
       *  @param __str  The string to insert.
975
       *  @return  Reference to this string.
976
       *  @throw  std::length_error  If new length exceeds @c max_size().
977
       *
978
       *  Inserts value of @a __str starting at @a __pos1.  If adding
979
       *  characters causes the length to exceed max_size(),
980
       *  length_error is thrown.  The value of the string doesn't
981
       *  change if an error is thrown.
982
      */
983
      __versa_string&
984
      insert(size_type __pos1, const __versa_string& __str)
985
      { return this->replace(__pos1, size_type(0),
986
                             __str._M_data(), __str.size()); }
987
 
988
      /**
989
       *  @brief  Insert a substring.
990
       *  @param __pos1  Iterator referencing location in string to insert at.
991
       *  @param __str  The string to insert.
992
       *  @param __pos2  Start of characters in str to insert.
993
       *  @param __n  Number of characters to insert.
994
       *  @return  Reference to this string.
995
       *  @throw  std::length_error  If new length exceeds @c max_size().
996
       *  @throw  std::out_of_range  If @a __pos1 > size() or
997
       *  @a __pos2 > @a __str.size().
998
       *
999
       *  Starting at @a __pos1, insert @a __n character of @a __str
1000
       *  beginning with @a __pos2.  If adding characters causes the
1001
       *  length to exceed max_size(), length_error is thrown.  If @a
1002
       *  __pos1 is beyond the end of this string or @a __pos2 is
1003
       *  beyond the end of @a __str, out_of_range is thrown.  The
1004
       *  value of the string doesn't change if an error is thrown.
1005
      */
1006
      __versa_string&
1007
      insert(size_type __pos1, const __versa_string& __str,
1008
             size_type __pos2, size_type __n)
1009
      { return this->replace(__pos1, size_type(0), __str._M_data()
1010
                             + __str._M_check(__pos2, "__versa_string::insert"),
1011
                             __str._M_limit(__pos2, __n)); }
1012
 
1013
      /**
1014
       *  @brief  Insert a C substring.
1015
       *  @param __pos  Iterator referencing location in string to insert at.
1016
       *  @param __s  The C string to insert.
1017
       *  @param __n  The number of characters to insert.
1018
       *  @return  Reference to this string.
1019
       *  @throw  std::length_error  If new length exceeds @c max_size().
1020
       *  @throw  std::out_of_range  If @a __pos is beyond the end of this
1021
       *  string.
1022
       *
1023
       *  Inserts the first @a __n characters of @a __s starting at @a
1024
       *  __pos.  If adding characters causes the length to exceed
1025
       *  max_size(), length_error is thrown.  If @a __pos is beyond
1026
       *  end(), out_of_range is thrown.  The value of the string
1027
       *  doesn't change if an error is thrown.
1028
      */
1029
      __versa_string&
1030
      insert(size_type __pos, const _CharT* __s, size_type __n)
1031
      { return this->replace(__pos, size_type(0), __s, __n); }
1032
 
1033
      /**
1034
       *  @brief  Insert a C string.
1035
       *  @param __pos  Iterator referencing location in string to insert at.
1036
       *  @param __s  The C string to insert.
1037
       *  @return  Reference to this string.
1038
       *  @throw  std::length_error  If new length exceeds @c max_size().
1039
       *  @throw  std::out_of_range  If @a __pos is beyond the end of this
1040
       *  string.
1041
       *
1042
       *  Inserts the first @a __n characters of @a __s starting at @a
1043
       *  __pos.  If adding characters causes the length to exceed
1044
       *  max_size(), length_error is thrown.  If @a __pos is beyond
1045
       *  end(), out_of_range is thrown.  The value of the string
1046
       *  doesn't change if an error is thrown.
1047
      */
1048
      __versa_string&
1049
      insert(size_type __pos, const _CharT* __s)
1050
      {
1051
        __glibcxx_requires_string(__s);
1052
        return this->replace(__pos, size_type(0), __s,
1053
                             traits_type::length(__s));
1054
      }
1055
 
1056
      /**
1057
       *  @brief  Insert multiple characters.
1058
       *  @param __pos  Index in string to insert at.
1059
       *  @param __n  Number of characters to insert
1060
       *  @param __c  The character to insert.
1061
       *  @return  Reference to this string.
1062
       *  @throw  std::length_error  If new length exceeds @c max_size().
1063
       *  @throw  std::out_of_range  If @a __pos is beyond the end of this
1064
       *  string.
1065
       *
1066
       *  Inserts @a __n copies of character @a __c starting at index
1067
       *  @a __pos.  If adding characters causes the length to exceed
1068
       *  max_size(), length_error is thrown.  If @a __pos > length(),
1069
       *  out_of_range is thrown.  The value of the string doesn't
1070
       *  change if an error is thrown.
1071
      */
1072
      __versa_string&
1073
      insert(size_type __pos, size_type __n, _CharT __c)
1074
      { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
1075
                              size_type(0), __n, __c); }
1076
 
1077
      /**
1078
       *  @brief  Insert one character.
1079
       *  @param __p  Iterator referencing position in string to insert at.
1080
       *  @param __c  The character to insert.
1081
       *  @return  Iterator referencing newly inserted char.
1082
       *  @throw  std::length_error  If new length exceeds @c max_size().
1083
       *
1084
       *  Inserts character @a __c at position referenced by @a __p.
1085
       *  If adding character causes the length to exceed max_size(),
1086
       *  length_error is thrown.  If @a __p is beyond end of string,
1087
       *  out_of_range is thrown.  The value of the string doesn't
1088
       *  change if an error is thrown.
1089
      */
1090
      iterator
1091
      insert(iterator __p, _CharT __c)
1092
      {
1093
        _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1094
        const size_type __pos = __p - _M_ibegin();
1095
        _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1096
        this->_M_set_leaked();
1097
        return iterator(this->_M_data() + __pos);
1098
      }
1099
 
1100
      /**
1101
       *  @brief  Remove characters.
1102
       *  @param __pos  Index of first character to remove (default 0).
1103
       *  @param __n  Number of characters to remove (default remainder).
1104
       *  @return  Reference to this string.
1105
       *  @throw  std::out_of_range  If @a __pos is beyond the end of this
1106
       *  string.
1107
       *
1108
       *  Removes @a __n characters from this string starting at @a
1109
       *  __pos.  The length of the string is reduced by @a __n.  If
1110
       *  there are < @a __n characters to remove, the remainder of
1111
       *  the string is truncated.  If @a __p is beyond end of string,
1112
       *  out_of_range is thrown.  The value of the string doesn't
1113
       *  change if an error is thrown.
1114
      */
1115
      __versa_string&
1116
      erase(size_type __pos = 0, size_type __n = npos)
1117
      {
1118
        this->_M_erase(_M_check(__pos, "__versa_string::erase"),
1119
                       _M_limit(__pos, __n));
1120
        return *this;
1121
      }
1122
 
1123
      /**
1124
       *  @brief  Remove one character.
1125
       *  @param __position  Iterator referencing the character to remove.
1126
       *  @return  iterator referencing same location after removal.
1127
       *
1128
       *  Removes the character at @a __position from this string. The
1129
       *  value of the string doesn't change if an error is thrown.
1130
      */
1131
      iterator
1132
      erase(iterator __position)
1133
      {
1134
        _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1135
                                 && __position < _M_iend());
1136
        const size_type __pos = __position - _M_ibegin();
1137
        this->_M_erase(__pos, size_type(1));
1138
        this->_M_set_leaked();
1139
        return iterator(this->_M_data() + __pos);
1140
      }
1141
 
1142
      /**
1143
       *  @brief  Remove a range of characters.
1144
       *  @param __first  Iterator referencing the first character to remove.
1145
       *  @param __last  Iterator referencing the end of the range.
1146
       *  @return  Iterator referencing location of first after removal.
1147
       *
1148
       *  Removes the characters in the range [first,last) from this
1149
       *  string.  The value of the string doesn't change if an error
1150
       *  is thrown.
1151
      */
1152
      iterator
1153
      erase(iterator __first, iterator __last)
1154
      {
1155
        _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1156
                                 && __last <= _M_iend());
1157
        const size_type __pos = __first - _M_ibegin();
1158
        this->_M_erase(__pos, __last - __first);
1159
        this->_M_set_leaked();
1160
        return iterator(this->_M_data() + __pos);
1161
      }
1162
 
1163
#if __cplusplus >= 201103L
1164
      /**
1165
       *  @brief  Remove the last character.
1166
       *
1167
       *  The string must be non-empty.
1168
       */
1169
      void
1170
      pop_back()
1171
      { this->_M_erase(size()-1, 1); }
1172
#endif // C++11
1173
 
1174
      /**
1175
       *  @brief  Replace characters with value from another string.
1176
       *  @param __pos  Index of first character to replace.
1177
       *  @param __n  Number of characters to be replaced.
1178
       *  @param __str  String to insert.
1179
       *  @return  Reference to this string.
1180
       *  @throw  std::out_of_range  If @a __pos is beyond the end of this
1181
       *  string.
1182
       *  @throw  std::length_error  If new length exceeds @c max_size().
1183
       *
1184
       *  Removes the characters in the range [pos,pos+n) from this
1185
       *  string.  In place, the value of @a __str is inserted.  If @a
1186
       *  __pos is beyond end of string, out_of_range is thrown.  If
1187
       *  the length of the result exceeds max_size(), length_error is
1188
       *  thrown.  The value of the string doesn't change if an error
1189
       *  is thrown.
1190
      */
1191
      __versa_string&
1192
      replace(size_type __pos, size_type __n, const __versa_string& __str)
1193
      { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1194
 
1195
      /**
1196
       *  @brief  Replace characters with value from another string.
1197
       *  @param __pos1  Index of first character to replace.
1198
       *  @param __n1  Number of characters to be replaced.
1199
       *  @param __str  String to insert.
1200
       *  @param __pos2  Index of first character of str to use.
1201
       *  @param __n2  Number of characters from str to use.
1202
       *  @return  Reference to this string.
1203
       *  @throw  std::out_of_range  If @a __pos1 > size() or @a __pos2 >
1204
       *  str.size().
1205
       *  @throw  std::length_error  If new length exceeds @c max_size().
1206
       *
1207
       *  Removes the characters in the range [pos1,pos1 + n) from
1208
       *  this string.  In place, the value of @a __str is inserted.
1209
       *  If @a __pos is beyond end of string, out_of_range is thrown.
1210
       *  If the length of the result exceeds max_size(), length_error
1211
       *  is thrown.  The value of the string doesn't change if an
1212
       *  error is thrown.
1213
      */
1214
      __versa_string&
1215
      replace(size_type __pos1, size_type __n1, const __versa_string& __str,
1216
              size_type __pos2, size_type __n2)
1217
      {
1218
        return this->replace(__pos1, __n1, __str._M_data()
1219
                             + __str._M_check(__pos2,
1220
                                              "__versa_string::replace"),
1221
                             __str._M_limit(__pos2, __n2));
1222
      }
1223
 
1224
      /**
1225
       *  @brief  Replace characters with value of a C substring.
1226
       *  @param __pos  Index of first character to replace.
1227
       *  @param __n1  Number of characters to be replaced.
1228
       *  @param __s  C string to insert.
1229
       *  @param __n2  Number of characters from @a __s to use.
1230
       *  @return  Reference to this string.
1231
       *  @throw  std::out_of_range  If @a __pos1 > size().
1232
       *  @throw  std::length_error  If new length exceeds @c max_size().
1233
       *
1234
       *  Removes the characters in the range [pos,pos + n1) from this
1235
       *  string.  In place, the first @a __n2 characters of @a __s
1236
       *  are inserted, or all of @a __s if @a __n2 is too large.  If
1237
       *  @a __pos is beyond end of string, out_of_range is thrown.
1238
       *  If the length of result exceeds max_size(), length_error is
1239
       *  thrown.  The value of the string doesn't change if an error
1240
       *  is thrown.
1241
      */
1242
      __versa_string&
1243
      replace(size_type __pos, size_type __n1, const _CharT* __s,
1244
              size_type __n2)
1245
      {
1246
        __glibcxx_requires_string_len(__s, __n2);
1247
        return _M_replace(_M_check(__pos, "__versa_string::replace"),
1248
                          _M_limit(__pos, __n1), __s, __n2);
1249
      }
1250
 
1251
      /**
1252
       *  @brief  Replace characters with value of a C string.
1253
       *  @param __pos  Index of first character to replace.
1254
       *  @param __n1  Number of characters to be replaced.
1255
       *  @param __s  C string to insert.
1256
       *  @return  Reference to this string.
1257
       *  @throw  std::out_of_range  If @a __pos > size().
1258
       *  @throw  std::length_error  If new length exceeds @c max_size().
1259
       *
1260
       *  Removes the characters in the range [pos,pos + n1) from this
1261
       *  string.  In place, the characters of @a __s are inserted.  If
1262
       *  @a pos is beyond end of string, out_of_range is thrown.  If
1263
       *  the length of result exceeds max_size(), length_error is thrown.
1264
       *  The value of the string doesn't change if an error is thrown.
1265
      */
1266
      __versa_string&
1267
      replace(size_type __pos, size_type __n1, const _CharT* __s)
1268
      {
1269
        __glibcxx_requires_string(__s);
1270
        return this->replace(__pos, __n1, __s, traits_type::length(__s));
1271
      }
1272
 
1273
      /**
1274
       *  @brief  Replace characters with multiple characters.
1275
       *  @param __pos  Index of first character to replace.
1276
       *  @param __n1  Number of characters to be replaced.
1277
       *  @param __n2  Number of characters to insert.
1278
       *  @param __c  Character to insert.
1279
       *  @return  Reference to this string.
1280
       *  @throw  std::out_of_range  If @a __pos > size().
1281
       *  @throw  std::length_error  If new length exceeds @c max_size().
1282
       *
1283
       *  Removes the characters in the range [pos,pos + n1) from this
1284
       *  string.  In place, @a __n2 copies of @a __c are inserted.
1285
       *  If @a __pos is beyond end of string, out_of_range is thrown.
1286
       *  If the length of result exceeds max_size(), length_error is
1287
       *  thrown.  The value of the string doesn't change if an error
1288
       *  is thrown.
1289
      */
1290
      __versa_string&
1291
      replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1292
      { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1293
                              _M_limit(__pos, __n1), __n2, __c); }
1294
 
1295
      /**
1296
       *  @brief  Replace range of characters with string.
1297
       *  @param __i1  Iterator referencing start of range to replace.
1298
       *  @param __i2  Iterator referencing end of range to replace.
1299
       *  @param __str  String value to insert.
1300
       *  @return  Reference to this string.
1301
       *  @throw  std::length_error  If new length exceeds @c max_size().
1302
       *
1303
       *  Removes the characters in the range [i1,i2).  In place, the
1304
       *  value of @a __str is inserted.  If the length of result
1305
       *  exceeds max_size(), length_error is thrown.  The value of
1306
       *  the string doesn't change if an error is thrown.
1307
      */
1308
      __versa_string&
1309
      replace(iterator __i1, iterator __i2, const __versa_string& __str)
1310
      { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1311
 
1312
      /**
1313
       *  @brief  Replace range of characters with C substring.
1314
       *  @param __i1  Iterator referencing start of range to replace.
1315
       *  @param __i2  Iterator referencing end of range to replace.
1316
       *  @param __s  C string value to insert.
1317
       *  @param __n  Number of characters from s to insert.
1318
       *  @return  Reference to this string.
1319
       *  @throw  std::length_error  If new length exceeds @c max_size().
1320
       *
1321
       *  Removes the characters in the range [i1,i2).  In place, the
1322
       *  first @a n characters of @a __s are inserted.  If the length
1323
       *  of result exceeds max_size(), length_error is thrown.  The
1324
       *  value of the string doesn't change if an error is thrown.
1325
      */
1326
      __versa_string&
1327
      replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1328
      {
1329
        _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1330
                                 && __i2 <= _M_iend());
1331
        return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1332
      }
1333
 
1334
      /**
1335
       *  @brief  Replace range of characters with C string.
1336
       *  @param __i1  Iterator referencing start of range to replace.
1337
       *  @param __i2  Iterator referencing end of range to replace.
1338
       *  @param __s  C string value to insert.
1339
       *  @return  Reference to this string.
1340
       *  @throw  std::length_error  If new length exceeds @c max_size().
1341
       *
1342
       *  Removes the characters in the range [i1,i2).  In place, the
1343
       *  characters of @a __s are inserted.  If the length of result
1344
       *  exceeds max_size(), length_error is thrown.  The value of
1345
       *  the string doesn't change if an error is thrown.
1346
      */
1347
      __versa_string&
1348
      replace(iterator __i1, iterator __i2, const _CharT* __s)
1349
      {
1350
        __glibcxx_requires_string(__s);
1351
        return this->replace(__i1, __i2, __s, traits_type::length(__s));
1352
      }
1353
 
1354
      /**
1355
       *  @brief  Replace range of characters with multiple characters
1356
       *  @param __i1  Iterator referencing start of range to replace.
1357
       *  @param __i2  Iterator referencing end of range to replace.
1358
       *  @param __n  Number of characters to insert.
1359
       *  @param __c  Character to insert.
1360
       *  @return  Reference to this string.
1361
       *  @throw  std::length_error  If new length exceeds @c max_size().
1362
       *
1363
       *  Removes the characters in the range [i1,i2).  In place, @a
1364
       *  __n copies of @a __c are inserted.  If the length of result
1365
       *  exceeds max_size(), length_error is thrown.  The value of
1366
       *  the string doesn't change if an error is thrown.
1367
      */
1368
      __versa_string&
1369
      replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1370
      {
1371
        _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1372
                                 && __i2 <= _M_iend());
1373
        return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1374
      }
1375
 
1376
      /**
1377
       *  @brief  Replace range of characters with range.
1378
       *  @param __i1  Iterator referencing start of range to replace.
1379
       *  @param __i2  Iterator referencing end of range to replace.
1380
       *  @param __k1  Iterator referencing start of range to insert.
1381
       *  @param __k2  Iterator referencing end of range to insert.
1382
       *  @return  Reference to this string.
1383
       *  @throw  std::length_error  If new length exceeds @c max_size().
1384
       *
1385
       *  Removes the characters in the range [i1,i2).  In place,
1386
       *  characters in the range [k1,k2) are inserted.  If the length
1387
       *  of result exceeds max_size(), length_error is thrown.  The
1388
       *  value of the string doesn't change if an error is thrown.
1389
      */
1390
#if __cplusplus >= 201103L
1391
      template<class _InputIterator,
1392
               typename = std::_RequireInputIter<_InputIterator>>
1393
        __versa_string&
1394
        replace(iterator __i1, iterator __i2,
1395
                _InputIterator __k1, _InputIterator __k2)
1396
        {
1397
          _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1398
                                   && __i2 <= _M_iend());
1399
          __glibcxx_requires_valid_range(__k1, __k2);
1400
          return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
1401
                                           std::__false_type());
1402
        }
1403
#else
1404
      template<class _InputIterator>
1405
        __versa_string&
1406
        replace(iterator __i1, iterator __i2,
1407
                _InputIterator __k1, _InputIterator __k2)
1408
        {
1409
          _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1410
                                   && __i2 <= _M_iend());
1411
          __glibcxx_requires_valid_range(__k1, __k2);
1412
          typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1413
          return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1414
        }
1415
#endif
1416
 
1417
      // Specializations for the common case of pointer and iterator:
1418
      // useful to avoid the overhead of temporary buffering in _M_replace.
1419
      __versa_string&
1420
      replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1421
      {
1422
        _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1423
                                 && __i2 <= _M_iend());
1424
        __glibcxx_requires_valid_range(__k1, __k2);
1425
        return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1426
                             __k1, __k2 - __k1);
1427
      }
1428
 
1429
      __versa_string&
1430
      replace(iterator __i1, iterator __i2,
1431
              const _CharT* __k1, const _CharT* __k2)
1432
      {
1433
        _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1434
                                 && __i2 <= _M_iend());
1435
        __glibcxx_requires_valid_range(__k1, __k2);
1436
        return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1437
                             __k1, __k2 - __k1);
1438
      }
1439
 
1440
      __versa_string&
1441
      replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1442
      {
1443
        _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1444
                                 && __i2 <= _M_iend());
1445
        __glibcxx_requires_valid_range(__k1, __k2);
1446
        return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1447
                             __k1.base(), __k2 - __k1);
1448
      }
1449
 
1450
      __versa_string&
1451
      replace(iterator __i1, iterator __i2,
1452
              const_iterator __k1, const_iterator __k2)
1453
      {
1454
        _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1455
                                 && __i2 <= _M_iend());
1456
        __glibcxx_requires_valid_range(__k1, __k2);
1457
        return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1458
                             __k1.base(), __k2 - __k1);
1459
      }
1460
 
1461
#if __cplusplus >= 201103L
1462
      /**
1463
       *  @brief  Replace range of characters with initializer_list.
1464
       *  @param __i1  Iterator referencing start of range to replace.
1465
       *  @param __i2  Iterator referencing end of range to replace.
1466
       *  @param __l  The initializer_list of characters to insert.
1467
       *  @return  Reference to this string.
1468
       *  @throw  std::length_error  If new length exceeds @c max_size().
1469
       *
1470
       *  Removes the characters in the range [i1,i2).  In place,
1471
       *  characters in the range [k1,k2) are inserted.  If the length
1472
       *  of result exceeds max_size(), length_error is thrown.  The
1473
       *  value of the string doesn't change if an error is thrown.
1474
      */
1475
      __versa_string& replace(iterator __i1, iterator __i2,
1476
                              std::initializer_list<_CharT> __l)
1477
      { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
1478
#endif // C++11
1479
 
1480
    private:
1481
      template<class _Integer>
1482
        __versa_string&
1483
        _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1484
                            _Integer __val, std::__true_type)
1485
        { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1486
 
1487
      template<class _InputIterator>
1488
        __versa_string&
1489
        _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1490
                            _InputIterator __k2, std::__false_type);
1491
 
1492
      __versa_string&
1493
      _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1494
                     _CharT __c);
1495
 
1496
      __versa_string&
1497
      _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1498
                 const size_type __len2);
1499
 
1500
      __versa_string&
1501
      _M_append(const _CharT* __s, size_type __n);
1502
 
1503
    public:
1504
 
1505
      /**
1506
       *  @brief  Copy substring into C string.
1507
       *  @param __s  C string to copy value into.
1508
       *  @param __n  Number of characters to copy.
1509
       *  @param __pos  Index of first character to copy.
1510
       *  @return  Number of characters actually copied
1511
       *  @throw  std::out_of_range  If pos > size().
1512
       *
1513
       *  Copies up to @a __n characters starting at @a __pos into the
1514
       *  C string @a s.  If @a __pos is greater than size(),
1515
       *  out_of_range is thrown.
1516
      */
1517
      size_type
1518
      copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1519
 
1520
      /**
1521
       *  @brief  Swap contents with another string.
1522
       *  @param __s  String to swap with.
1523
       *
1524
       *  Exchanges the contents of this string with that of @a __s in
1525
       *  constant time.
1526
      */
1527
      void
1528
      swap(__versa_string& __s)
1529
      { this->_M_swap(__s); }
1530
 
1531
      // String operations:
1532
      /**
1533
       *  @brief  Return const pointer to null-terminated contents.
1534
       *
1535
       *  This is a handle to internal data.  Do not modify or dire things may
1536
       *  happen.
1537
      */
1538
      const _CharT*
1539
      c_str() const _GLIBCXX_NOEXCEPT
1540
      { return this->_M_data(); }
1541
 
1542
      /**
1543
       *  @brief  Return const pointer to contents.
1544
       *
1545
       *  This is a handle to internal data.  Do not modify or dire things may
1546
       *  happen.
1547
      */
1548
      const _CharT*
1549
      data() const _GLIBCXX_NOEXCEPT
1550
      { return this->_M_data(); }
1551
 
1552
      /**
1553
       *  @brief  Return copy of allocator used to construct this string.
1554
      */
1555
      allocator_type
1556
      get_allocator() const _GLIBCXX_NOEXCEPT
1557
      { return allocator_type(this->_M_get_allocator()); }
1558
 
1559
      /**
1560
       *  @brief  Find position of a C substring.
1561
       *  @param __s  C string to locate.
1562
       *  @param __pos  Index of character to search from.
1563
       *  @param __n  Number of characters from @a __s to search for.
1564
       *  @return  Index of start of first occurrence.
1565
       *
1566
       *  Starting from @a __pos, searches forward for the first @a
1567
       *  __n characters in @a __s within this string.  If found,
1568
       *  returns the index where it begins.  If not found, returns
1569
       *  npos.
1570
      */
1571
      size_type
1572
      find(const _CharT* __s, size_type __pos, size_type __n) const;
1573
 
1574
      /**
1575
       *  @brief  Find position of a string.
1576
       *  @param __str  String to locate.
1577
       *  @param __pos  Index of character to search from (default 0).
1578
       *  @return  Index of start of first occurrence.
1579
       *
1580
       *  Starting from @a __pos, searches forward for value of @a
1581
       *  __str within this string.  If found, returns the index where
1582
       *  it begins.  If not found, returns npos.
1583
      */
1584
      size_type
1585
      find(const __versa_string& __str, size_type __pos = 0) const
1586
        _GLIBCXX_NOEXCEPT
1587
      { return this->find(__str.data(), __pos, __str.size()); }
1588
 
1589
      /**
1590
       *  @brief  Find position of a C string.
1591
       *  @param __s  C string to locate.
1592
       *  @param __pos  Index of character to search from (default 0).
1593
       *  @return  Index of start of first occurrence.
1594
       *
1595
       *  Starting from @a __pos, searches forward for the value of @a
1596
       *  __s within this string.  If found, returns the index where
1597
       *  it begins.  If not found, returns npos.
1598
      */
1599
      size_type
1600
      find(const _CharT* __s, size_type __pos = 0) const
1601
      {
1602
        __glibcxx_requires_string(__s);
1603
        return this->find(__s, __pos, traits_type::length(__s));
1604
      }
1605
 
1606
      /**
1607
       *  @brief  Find position of a character.
1608
       *  @param __c  Character to locate.
1609
       *  @param __pos  Index of character to search from (default 0).
1610
       *  @return  Index of first occurrence.
1611
       *
1612
       *  Starting from @a __pos, searches forward for @a __c within
1613
       *  this string.  If found, returns the index where it was
1614
       *  found.  If not found, returns npos.
1615
      */
1616
      size_type
1617
      find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
1618
 
1619
      /**
1620
       *  @brief  Find last position of a string.
1621
       *  @param __str  String to locate.
1622
       *  @param __pos  Index of character to search back from (default end).
1623
       *  @return  Index of start of last occurrence.
1624
       *
1625
       *  Starting from @a __pos, searches backward for value of @a
1626
       *  __str within this string.  If found, returns the index where
1627
       *  it begins.  If not found, returns npos.
1628
      */
1629
      size_type
1630
      rfind(const __versa_string& __str, size_type __pos = npos) const
1631
        _GLIBCXX_NOEXCEPT
1632
      { return this->rfind(__str.data(), __pos, __str.size()); }
1633
 
1634
      /**
1635
       *  @brief  Find last position of a C substring.
1636
       *  @param __s  C string to locate.
1637
       *  @param __pos  Index of character to search back from.
1638
       *  @param __n  Number of characters from s to search for.
1639
       *  @return  Index of start of last occurrence.
1640
       *
1641
       *  Starting from @a __pos, searches backward for the first @a
1642
       *  __n characters in @a __s within this string.  If found,
1643
       *  returns the index where it begins.  If not found, returns
1644
       *  npos.
1645
      */
1646
      size_type
1647
      rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1648
 
1649
      /**
1650
       *  @brief  Find last position of a C string.
1651
       *  @param __s  C string to locate.
1652
       *  @param __pos  Index of character to start search at (default end).
1653
       *  @return  Index of start of  last occurrence.
1654
       *
1655
       *  Starting from @a __pos, searches backward for the value of
1656
       *  @a __s within this string.  If found, returns the index
1657
       *  where it begins.  If not found, returns npos.
1658
      */
1659
      size_type
1660
      rfind(const _CharT* __s, size_type __pos = npos) const
1661
      {
1662
        __glibcxx_requires_string(__s);
1663
        return this->rfind(__s, __pos, traits_type::length(__s));
1664
      }
1665
 
1666
      /**
1667
       *  @brief  Find last position of a character.
1668
       *  @param __c  Character to locate.
1669
       *  @param __pos  Index of character to search back from (default end).
1670
       *  @return  Index of last occurrence.
1671
       *
1672
       *  Starting from @a __pos, searches backward for @a __c within
1673
       *  this string.  If found, returns the index where it was
1674
       *  found.  If not found, returns npos.
1675
      */
1676
      size_type
1677
      rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
1678
 
1679
      /**
1680
       *  @brief  Find position of a character of string.
1681
       *  @param __str  String containing characters to locate.
1682
       *  @param __pos  Index of character to search from (default 0).
1683
       *  @return  Index of first occurrence.
1684
       *
1685
       *  Starting from @a __pos, searches forward for one of the characters of
1686
       *  @a __str within this string.  If found, returns the index where it was
1687
       *  found.  If not found, returns npos.
1688
      */
1689
      size_type
1690
      find_first_of(const __versa_string& __str, size_type __pos = 0) const
1691
        _GLIBCXX_NOEXCEPT
1692
      { return this->find_first_of(__str.data(), __pos, __str.size()); }
1693
 
1694
      /**
1695
       *  @brief  Find position of a character of C substring.
1696
       *  @param __s  String containing characters to locate.
1697
       *  @param __pos  Index of character to search from.
1698
       *  @param __n  Number of characters from s to search for.
1699
       *  @return  Index of first occurrence.
1700
       *
1701
       *  Starting from @a __pos, searches forward for one of the
1702
       *  first @a __n characters of @a __s within this string.  If
1703
       *  found, returns the index where it was found.  If not found,
1704
       *  returns npos.
1705
      */
1706
      size_type
1707
      find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1708
 
1709
      /**
1710
       *  @brief  Find position of a character of C string.
1711
       *  @param __s  String containing characters to locate.
1712
       *  @param __pos  Index of character to search from (default 0).
1713
       *  @return  Index of first occurrence.
1714
       *
1715
       *  Starting from @a __pos, searches forward for one of the
1716
       *  characters of @a __s within this string.  If found, returns
1717
       *  the index where it was found.  If not found, returns npos.
1718
      */
1719
      size_type
1720
      find_first_of(const _CharT* __s, size_type __pos = 0) const
1721
      {
1722
        __glibcxx_requires_string(__s);
1723
        return this->find_first_of(__s, __pos, traits_type::length(__s));
1724
      }
1725
 
1726
      /**
1727
       *  @brief  Find position of a character.
1728
       *  @param __c  Character to locate.
1729
       *  @param __pos  Index of character to search from (default 0).
1730
       *  @return  Index of first occurrence.
1731
       *
1732
       *  Starting from @a __pos, searches forward for the character
1733
       *  @a __c within this string.  If found, returns the index
1734
       *  where it was found.  If not found, returns npos.
1735
       *
1736
       *  Note: equivalent to find(c, pos).
1737
      */
1738
      size_type
1739
      find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
1740
      { return this->find(__c, __pos); }
1741
 
1742
      /**
1743
       *  @brief  Find last position of a character of string.
1744
       *  @param __str  String containing characters to locate.
1745
       *  @param __pos  Index of character to search back from (default end).
1746
       *  @return  Index of last occurrence.
1747
       *
1748
       *  Starting from @a __pos, searches backward for one of the
1749
       *  characters of @a __str within this string.  If found,
1750
       *  returns the index where it was found.  If not found, returns
1751
       *  npos.
1752
      */
1753
      size_type
1754
      find_last_of(const __versa_string& __str, size_type __pos = npos) const
1755
        _GLIBCXX_NOEXCEPT
1756
      { return this->find_last_of(__str.data(), __pos, __str.size()); }
1757
 
1758
      /**
1759
       *  @brief  Find last position of a character of C substring.
1760
       *  @param __s  C string containing characters to locate.
1761
       *  @param __pos  Index of character to search back from.
1762
       *  @param __n  Number of characters from s to search for.
1763
       *  @return  Index of last occurrence.
1764
       *
1765
       *  Starting from @a __pos, searches backward for one of the
1766
       *  first @a __n characters of @a __s within this string.  If
1767
       *  found, returns the index where it was found.  If not found,
1768
       *  returns npos.
1769
      */
1770
      size_type
1771
      find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1772
 
1773
      /**
1774
       *  @brief  Find last position of a character of C string.
1775
       *  @param __s  C string containing characters to locate.
1776
       *  @param __pos  Index of character to search back from (default end).
1777
       *  @return  Index of last occurrence.
1778
       *
1779
       *  Starting from @a __pos, searches backward for one of the
1780
       *  characters of @a __s within this string.  If found, returns
1781
       *  the index where it was found.  If not found, returns npos.
1782
      */
1783
      size_type
1784
      find_last_of(const _CharT* __s, size_type __pos = npos) const
1785
      {
1786
        __glibcxx_requires_string(__s);
1787
        return this->find_last_of(__s, __pos, traits_type::length(__s));
1788
      }
1789
 
1790
      /**
1791
       *  @brief  Find last position of a character.
1792
       *  @param __c  Character to locate.
1793
       *  @param __pos  Index of character to search back from (default end).
1794
       *  @return  Index of last occurrence.
1795
       *
1796
       *  Starting from @a __pos, searches backward for @a __c within
1797
       *  this string.  If found, returns the index where it was
1798
       *  found.  If not found, returns npos.
1799
       *
1800
       *  Note: equivalent to rfind(c, pos).
1801
      */
1802
      size_type
1803
      find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1804
      { return this->rfind(__c, __pos); }
1805
 
1806
      /**
1807
       *  @brief  Find position of a character not in string.
1808
       *  @param __str  String containing characters to avoid.
1809
       *  @param __pos  Index of character to search from (default 0).
1810
       *  @return  Index of first occurrence.
1811
       *
1812
       *  Starting from @a __pos, searches forward for a character not
1813
       *  contained in @a __str within this string.  If found, returns
1814
       *  the index where it was found.  If not found, returns npos.
1815
      */
1816
      size_type
1817
      find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1818
        _GLIBCXX_NOEXCEPT
1819
      { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1820
 
1821
      /**
1822
       *  @brief  Find position of a character not in C substring.
1823
       *  @param __s  C string containing characters to avoid.
1824
       *  @param __pos  Index of character to search from.
1825
       *  @param __n  Number of characters from s to consider.
1826
       *  @return  Index of first occurrence.
1827
       *
1828
       *  Starting from @a __pos, searches forward for a character not
1829
       *  contained in the first @a __n characters of @a __s within
1830
       *  this string.  If found, returns the index where it was
1831
       *  found.  If not found, returns npos.
1832
      */
1833
      size_type
1834
      find_first_not_of(const _CharT* __s, size_type __pos,
1835
                        size_type __n) const;
1836
 
1837
      /**
1838
       *  @brief  Find position of a character not in C string.
1839
       *  @param __s  C string containing characters to avoid.
1840
       *  @param __pos  Index of character to search from (default 0).
1841
       *  @return  Index of first occurrence.
1842
       *
1843
       *  Starting from @a __pos, searches forward for a character not
1844
       *  contained in @a __s within this string.  If found, returns
1845
       *  the index where it was found.  If not found, returns npos.
1846
      */
1847
      size_type
1848
      find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1849
      {
1850
        __glibcxx_requires_string(__s);
1851
        return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1852
      }
1853
 
1854
      /**
1855
       *  @brief  Find position of a different character.
1856
       *  @param __c  Character to avoid.
1857
       *  @param __pos  Index of character to search from (default 0).
1858
       *  @return  Index of first occurrence.
1859
       *
1860
       *  Starting from @a __pos, searches forward for a character
1861
       *  other than @a __c within this string.  If found, returns the
1862
       *  index where it was found.  If not found, returns npos.
1863
      */
1864
      size_type
1865
      find_first_not_of(_CharT __c, size_type __pos = 0) const
1866
        _GLIBCXX_NOEXCEPT;
1867
 
1868
      /**
1869
       *  @brief  Find last position of a character not in string.
1870
       *  @param __str  String containing characters to avoid.
1871
       *  @param __pos  Index of character to search back from (default end).
1872
       *  @return  Index of last occurrence.
1873
       *
1874
       *  Starting from @a __pos, searches backward for a character
1875
       *  not contained in @a __str within this string.  If found,
1876
       *  returns the index where it was found.  If not found, returns
1877
       *  npos.
1878
      */
1879
      size_type
1880
      find_last_not_of(const __versa_string& __str,
1881
                       size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1882
      { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1883
 
1884
      /**
1885
       *  @brief  Find last position of a character not in C substring.
1886
       *  @param __s  C string containing characters to avoid.
1887
       *  @param __pos  Index of character to search back from.
1888
       *  @param __n  Number of characters from s to consider.
1889
       *  @return  Index of last occurrence.
1890
       *
1891
       *  Starting from @a __pos, searches backward for a character
1892
       *  not contained in the first @a __n characters of @a __s
1893
       *  within this string.  If found, returns the index where it
1894
       *  was found.  If not found, returns npos.
1895
      */
1896
      size_type
1897
      find_last_not_of(const _CharT* __s, size_type __pos,
1898
                       size_type __n) const;
1899
      /**
1900
       *  @brief  Find last position of a character not in C string.
1901
       *  @param __s  C string containing characters to avoid.
1902
       *  @param __pos  Index of character to search back from (default end).
1903
       *  @return  Index of last occurrence.
1904
       *
1905
       *  Starting from @a __pos, searches backward for a character
1906
       *  not contained in @a __s within this string.  If found,
1907
       *  returns the index where it was found.  If not found, returns
1908
       *  npos.
1909
      */
1910
      size_type
1911
      find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1912
      {
1913
        __glibcxx_requires_string(__s);
1914
        return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1915
      }
1916
 
1917
      /**
1918
       *  @brief  Find last position of a different character.
1919
       *  @param __c  Character to avoid.
1920
       *  @param __pos  Index of character to search back from (default end).
1921
       *  @return  Index of last occurrence.
1922
       *
1923
       *  Starting from @a __pos, searches backward for a character
1924
       *  other than @a __c within this string.  If found, returns the
1925
       *  index where it was found.  If not found, returns npos.
1926
      */
1927
      size_type
1928
      find_last_not_of(_CharT __c, size_type __pos = npos) const
1929
        _GLIBCXX_NOEXCEPT;
1930
 
1931
      /**
1932
       *  @brief  Get a substring.
1933
       *  @param __pos  Index of first character (default 0).
1934
       *  @param __n  Number of characters in substring (default remainder).
1935
       *  @return  The new string.
1936
       *  @throw  std::out_of_range  If pos > size().
1937
       *
1938
       *  Construct and return a new string using the @a __n
1939
       *  characters starting at @a __pos.  If the string is too
1940
       *  short, use the remainder of the characters.  If @a __pos is
1941
       *  beyond the end of the string, out_of_range is thrown.
1942
      */
1943
      __versa_string
1944
      substr(size_type __pos = 0, size_type __n = npos) const
1945
      {
1946
        return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
1947
                              __n);
1948
      }
1949
 
1950
      /**
1951
       *  @brief  Compare to a string.
1952
       *  @param __str  String to compare against.
1953
       *  @return  Integer < 0, 0, or > 0.
1954
       *
1955
       *  Returns an integer < 0 if this string is ordered before @a
1956
       *  __str, 0 if their values are equivalent, or > 0 if this
1957
       *  string is ordered after @a __str.  Determines the effective
1958
       *  length rlen of the strings to compare as the smallest of
1959
       *  size() and str.size().  The function then compares the two
1960
       *  strings by calling traits::compare(data(), str.data(),rlen).
1961
       *  If the result of the comparison is nonzero returns it,
1962
       *  otherwise the shorter one is ordered first.
1963
      */
1964
      int
1965
      compare(const __versa_string& __str) const
1966
      {
1967
        if (this->_M_compare(__str))
1968
          return 0;
1969
 
1970
        const size_type __size = this->size();
1971
        const size_type __osize = __str.size();
1972
        const size_type __len = std::min(__size, __osize);
1973
 
1974
        int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
1975
        if (!__r)
1976
          __r = this->_S_compare(__size, __osize);
1977
        return __r;
1978
      }
1979
 
1980
      /**
1981
       *  @brief  Compare substring to a string.
1982
       *  @param __pos  Index of first character of substring.
1983
       *  @param __n  Number of characters in substring.
1984
       *  @param __str  String to compare against.
1985
       *  @return  Integer < 0, 0, or > 0.
1986
       *
1987
       *  Form the substring of this string from the @a __n characters
1988
       *  starting at @a __pos.  Returns an integer < 0 if the
1989
       *  substring is ordered before @a __str, 0 if their values are
1990
       *  equivalent, or > 0 if the substring is ordered after @a
1991
       *  __str.  Determines the effective length rlen of the strings
1992
       *  to compare as the smallest of the length of the substring
1993
       *  and @a __str.size().  The function then compares the two
1994
       *  strings by calling
1995
       *  traits::compare(substring.data(),str.data(),rlen).  If the
1996
       *  result of the comparison is nonzero returns it, otherwise
1997
       *  the shorter one is ordered first.
1998
      */
1999
      int
2000
      compare(size_type __pos, size_type __n,
2001
              const __versa_string& __str) const;
2002
 
2003
      /**
2004
       *  @brief  Compare substring to a substring.
2005
       *  @param __pos1  Index of first character of substring.
2006
       *  @param __n1  Number of characters in substring.
2007
       *  @param __str  String to compare against.
2008
       *  @param __pos2  Index of first character of substring of str.
2009
       *  @param __n2  Number of characters in substring of str.
2010
       *  @return  Integer < 0, 0, or > 0.
2011
       *
2012
       *  Form the substring of this string from the @a __n1
2013
       *  characters starting at @a __pos1.  Form the substring of @a
2014
       *  __str from the @a __n2 characters starting at @a __pos2.
2015
       *  Returns an integer < 0 if this substring is ordered before
2016
       *  the substring of @a __str, 0 if their values are equivalent,
2017
       *  or > 0 if this substring is ordered after the substring of
2018
       *  @a __str.  Determines the effective length rlen of the
2019
       *  strings to compare as the smallest of the lengths of the
2020
       *  substrings.  The function then compares the two strings by
2021
       *  calling
2022
       *  traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
2023
       *  If the result of the comparison is nonzero returns it,
2024
       *  otherwise the shorter one is ordered first.
2025
      */
2026
      int
2027
      compare(size_type __pos1, size_type __n1, const __versa_string& __str,
2028
              size_type __pos2, size_type __n2) const;
2029
 
2030
      /**
2031
       *  @brief  Compare to a C string.
2032
       *  @param __s  C string to compare against.
2033
       *  @return  Integer < 0, 0, or > 0.
2034
       *
2035
       *  Returns an integer < 0 if this string is ordered before @a
2036
       *  __s, 0 if their values are equivalent, or > 0 if this string
2037
       *  is ordered after @a __s.  Determines the effective length
2038
       *  rlen of the strings to compare as the smallest of size() and
2039
       *  the length of a string constructed from @a __s.  The
2040
       *  function then compares the two strings by calling
2041
       *  traits::compare(data(),s,rlen).  If the result of the
2042
       *  comparison is nonzero returns it, otherwise the shorter one
2043
       *  is ordered first.
2044
      */
2045
      int
2046
      compare(const _CharT* __s) const;
2047
 
2048
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
2049
      // 5 String::compare specification questionable
2050
      /**
2051
       *  @brief  Compare substring to a C string.
2052
       *  @param __pos  Index of first character of substring.
2053
       *  @param __n1  Number of characters in substring.
2054
       *  @param __s  C string to compare against.
2055
       *  @return  Integer < 0, 0, or > 0.
2056
       *
2057
       *  Form the substring of this string from the @a __n1
2058
       *  characters starting at @a __pos.  Returns an integer < 0 if
2059
       *  the substring is ordered before @a __s, 0 if their values
2060
       *  are equivalent, or > 0 if the substring is ordered after @a
2061
       *  __s.  Determines the effective length rlen of the strings to
2062
       *  compare as the smallest of the length of the substring and
2063
       *  the length of a string constructed from @a __s.  The
2064
       *  function then compares the two string by calling
2065
       *  traits::compare(substring.data(),s,rlen).  If the result of
2066
       *  the comparison is nonzero returns it, otherwise the shorter
2067
       *  one is ordered first.
2068
      */
2069
      int
2070
      compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2071
 
2072
      /**
2073
       *  @brief  Compare substring against a character array.
2074
       *  @param __pos  Index of first character of substring.
2075
       *  @param __n1  Number of characters in substring.
2076
       *  @param __s  character array to compare against.
2077
       *  @param __n2  Number of characters of s.
2078
       *  @return  Integer < 0, 0, or > 0.
2079
       *
2080
       *  Form the substring of this string from the @a __n1
2081
       *  characters starting at @a __pos.  Form a string from the
2082
       *  first @a __n2 characters of @a __s.  Returns an integer < 0
2083
       *  if this substring is ordered before the string from @a __s,
2084
       *  0 if their values are equivalent, or > 0 if this substring
2085
       *  is ordered after the string from @a __s.  Determines the
2086
       *  effective length rlen of the strings to compare as the
2087
       *  smallest of the length of the substring and @a __n2.  The
2088
       *  function then compares the two strings by calling
2089
       *  traits::compare(substring.data(),__s,rlen).  If the result of
2090
       *  the comparison is nonzero returns it, otherwise the shorter
2091
       *  one is ordered first.
2092
       *
2093
       *  NB: __s must have at least n2 characters, <em>\\0</em> has no special
2094
       *  meaning.
2095
      */
2096
      int
2097
      compare(size_type __pos, size_type __n1, const _CharT* __s,
2098
              size_type __n2) const;
2099
    };
2100
 
2101
  // operator+
2102
  /**
2103
   *  @brief  Concatenate two strings.
2104
   *  @param __lhs  First string.
2105
   *  @param __rhs  Last string.
2106
   *  @return  New string with value of @a __lhs followed by @a __rhs.
2107
   */
2108
  template<typename _CharT, typename _Traits, typename _Alloc,
2109
           template <typename, typename, typename> class _Base>
2110
    __versa_string<_CharT, _Traits, _Alloc, _Base>
2111
    operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2112
              const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2113
 
2114
  /**
2115
   *  @brief  Concatenate C string and string.
2116
   *  @param __lhs  First string.
2117
   *  @param __rhs  Last string.
2118
   *  @return  New string with value of @a __lhs followed by @a __rhs.
2119
   */
2120
  template<typename _CharT, typename _Traits, typename _Alloc,
2121
           template <typename, typename, typename> class _Base>
2122
    __versa_string<_CharT, _Traits, _Alloc, _Base>
2123
    operator+(const _CharT* __lhs,
2124
              const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2125
 
2126
  /**
2127
   *  @brief  Concatenate character and string.
2128
   *  @param __lhs  First string.
2129
   *  @param __rhs  Last string.
2130
   *  @return  New string with @a __lhs followed by @a __rhs.
2131
   */
2132
  template<typename _CharT, typename _Traits, typename _Alloc,
2133
           template <typename, typename, typename> class _Base>
2134
    __versa_string<_CharT, _Traits, _Alloc, _Base>
2135
    operator+(_CharT __lhs,
2136
              const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2137
 
2138
  /**
2139
   *  @brief  Concatenate string and C string.
2140
   *  @param __lhs  First string.
2141
   *  @param __rhs  Last string.
2142
   *  @return  New string with @a __lhs followed by @a __rhs.
2143
   */
2144
  template<typename _CharT, typename _Traits, typename _Alloc,
2145
           template <typename, typename, typename> class _Base>
2146
    __versa_string<_CharT, _Traits, _Alloc, _Base>
2147
    operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2148
              const _CharT* __rhs);
2149
 
2150
  /**
2151
   *  @brief  Concatenate string and character.
2152
   *  @param __lhs  First string.
2153
   *  @param __rhs  Last string.
2154
   *  @return  New string with @a __lhs followed by @a __rhs.
2155
   */
2156
  template<typename _CharT, typename _Traits, typename _Alloc,
2157
           template <typename, typename, typename> class _Base>
2158
    __versa_string<_CharT, _Traits, _Alloc, _Base>
2159
    operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2160
              _CharT __rhs);
2161
 
2162
#if __cplusplus >= 201103L
2163
  template<typename _CharT, typename _Traits, typename _Alloc,
2164
           template <typename, typename, typename> class _Base>
2165
    inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2166
    operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2167
              const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2168
    { return std::move(__lhs.append(__rhs)); }
2169
 
2170
  template<typename _CharT, typename _Traits, typename _Alloc,
2171
           template <typename, typename, typename> class _Base>
2172
    inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2173
    operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2174
              __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2175
    { return std::move(__rhs.insert(0, __lhs)); }
2176
 
2177
  template<typename _CharT, typename _Traits, typename _Alloc,
2178
           template <typename, typename, typename> class _Base>
2179
    inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2180
    operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2181
              __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2182
    {
2183
      const auto __size = __lhs.size() + __rhs.size();
2184
      const bool __cond = (__size > __lhs.capacity()
2185
                           && __size <= __rhs.capacity());
2186
      return __cond ? std::move(__rhs.insert(0, __lhs))
2187
                    : std::move(__lhs.append(__rhs));
2188
    }
2189
 
2190
  template<typename _CharT, typename _Traits, typename _Alloc,
2191
           template <typename, typename, typename> class _Base>
2192
    inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2193
    operator+(const _CharT* __lhs,
2194
              __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2195
    { return std::move(__rhs.insert(0, __lhs)); }
2196
 
2197
  template<typename _CharT, typename _Traits, typename _Alloc,
2198
           template <typename, typename, typename> class _Base>
2199
    inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2200
    operator+(_CharT __lhs,
2201
              __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2202
    { return std::move(__rhs.insert(0, 1, __lhs)); }
2203
 
2204
  template<typename _CharT, typename _Traits, typename _Alloc,
2205
           template <typename, typename, typename> class _Base>
2206
    inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2207
    operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2208
              const _CharT* __rhs)
2209
    { return std::move(__lhs.append(__rhs)); }
2210
 
2211
  template<typename _CharT, typename _Traits, typename _Alloc,
2212
           template <typename, typename, typename> class _Base>
2213
    inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2214
    operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2215
              _CharT __rhs)
2216
    { return std::move(__lhs.append(1, __rhs)); }
2217
#endif
2218
 
2219
  // operator ==
2220
  /**
2221
   *  @brief  Test equivalence of two strings.
2222
   *  @param __lhs  First string.
2223
   *  @param __rhs  Second string.
2224
   *  @return  True if @a __lhs.compare(@a __rhs) == 0.  False otherwise.
2225
   */
2226
  template<typename _CharT, typename _Traits, typename _Alloc,
2227
           template <typename, typename, typename> class _Base>
2228
    inline bool
2229
    operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2230
               const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2231
    { return __lhs.compare(__rhs) == 0; }
2232
 
2233
  template<typename _CharT,
2234
           template <typename, typename, typename> class _Base>
2235
    inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
2236
    operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
2237
               std::allocator<_CharT>, _Base>& __lhs,
2238
               const __versa_string<_CharT, std::char_traits<_CharT>,
2239
               std::allocator<_CharT>, _Base>& __rhs)
2240
    { return (__lhs.size() == __rhs.size()
2241
              && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
2242
                                                    __lhs.size())); }
2243
 
2244
  /**
2245
   *  @brief  Test equivalence of C string and string.
2246
   *  @param __lhs  C string.
2247
   *  @param __rhs  String.
2248
   *  @return  True if @a __rhs.compare(@a __lhs) == 0.  False otherwise.
2249
   */
2250
  template<typename _CharT, typename _Traits, typename _Alloc,
2251
           template <typename, typename, typename> class _Base>
2252
    inline bool
2253
    operator==(const _CharT* __lhs,
2254
               const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2255
    { return __rhs.compare(__lhs) == 0; }
2256
 
2257
  /**
2258
   *  @brief  Test equivalence of string and C string.
2259
   *  @param __lhs  String.
2260
   *  @param __rhs  C string.
2261
   *  @return  True if @a __lhs.compare(@a __rhs) == 0.  False otherwise.
2262
   */
2263
  template<typename _CharT, typename _Traits, typename _Alloc,
2264
           template <typename, typename, typename> class _Base>
2265
    inline bool
2266
    operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2267
               const _CharT* __rhs)
2268
    { return __lhs.compare(__rhs) == 0; }
2269
 
2270
  // operator !=
2271
  /**
2272
   *  @brief  Test difference of two strings.
2273
   *  @param __lhs  First string.
2274
   *  @param __rhs  Second string.
2275
   *  @return  True if @a __lhs.compare(@a __rhs) != 0.  False otherwise.
2276
   */
2277
  template<typename _CharT, typename _Traits, typename _Alloc,
2278
           template <typename, typename, typename> class _Base>
2279
    inline bool
2280
    operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2281
               const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2282
    { return !(__lhs == __rhs); }
2283
 
2284
  /**
2285
   *  @brief  Test difference of C string and string.
2286
   *  @param __lhs  C string.
2287
   *  @param __rhs  String.
2288
   *  @return  True if @a __rhs.compare(@a __lhs) != 0.  False otherwise.
2289
   */
2290
  template<typename _CharT, typename _Traits, typename _Alloc,
2291
           template <typename, typename, typename> class _Base>
2292
    inline bool
2293
    operator!=(const _CharT* __lhs,
2294
               const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2295
    { return !(__lhs == __rhs); }
2296
 
2297
  /**
2298
   *  @brief  Test difference of string and C string.
2299
   *  @param __lhs  String.
2300
   *  @param __rhs  C string.
2301
   *  @return  True if @a __lhs.compare(@a __rhs) != 0.  False otherwise.
2302
   */
2303
  template<typename _CharT, typename _Traits, typename _Alloc,
2304
           template <typename, typename, typename> class _Base>
2305
    inline bool
2306
    operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2307
               const _CharT* __rhs)
2308
    { return !(__lhs == __rhs); }
2309
 
2310
  // operator <
2311
  /**
2312
   *  @brief  Test if string precedes string.
2313
   *  @param __lhs  First string.
2314
   *  @param __rhs  Second string.
2315
   *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
2316
   */
2317
  template<typename _CharT, typename _Traits, typename _Alloc,
2318
           template <typename, typename, typename> class _Base>
2319
    inline bool
2320
    operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2321
              const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2322
    { return __lhs.compare(__rhs) < 0; }
2323
 
2324
  /**
2325
   *  @brief  Test if string precedes C string.
2326
   *  @param __lhs  String.
2327
   *  @param __rhs  C string.
2328
   *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
2329
   */
2330
  template<typename _CharT, typename _Traits, typename _Alloc,
2331
           template <typename, typename, typename> class _Base>
2332
    inline bool
2333
    operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2334
              const _CharT* __rhs)
2335
    { return __lhs.compare(__rhs) < 0; }
2336
 
2337
  /**
2338
   *  @brief  Test if C string precedes string.
2339
   *  @param __lhs  C string.
2340
   *  @param __rhs  String.
2341
   *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
2342
   */
2343
  template<typename _CharT, typename _Traits, typename _Alloc,
2344
           template <typename, typename, typename> class _Base>
2345
    inline bool
2346
    operator<(const _CharT* __lhs,
2347
              const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2348
    { return __rhs.compare(__lhs) > 0; }
2349
 
2350
  // operator >
2351
  /**
2352
   *  @brief  Test if string follows string.
2353
   *  @param __lhs  First string.
2354
   *  @param __rhs  Second string.
2355
   *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
2356
   */
2357
  template<typename _CharT, typename _Traits, typename _Alloc,
2358
           template <typename, typename, typename> class _Base>
2359
    inline bool
2360
    operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2361
              const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2362
    { return __lhs.compare(__rhs) > 0; }
2363
 
2364
  /**
2365
   *  @brief  Test if string follows C string.
2366
   *  @param __lhs  String.
2367
   *  @param __rhs  C string.
2368
   *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
2369
   */
2370
  template<typename _CharT, typename _Traits, typename _Alloc,
2371
           template <typename, typename, typename> class _Base>
2372
    inline bool
2373
    operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2374
              const _CharT* __rhs)
2375
    { return __lhs.compare(__rhs) > 0; }
2376
 
2377
  /**
2378
   *  @brief  Test if C string follows string.
2379
   *  @param __lhs  C string.
2380
   *  @param __rhs  String.
2381
   *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
2382
   */
2383
  template<typename _CharT, typename _Traits, typename _Alloc,
2384
           template <typename, typename, typename> class _Base>
2385
    inline bool
2386
    operator>(const _CharT* __lhs,
2387
              const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2388
    { return __rhs.compare(__lhs) < 0; }
2389
 
2390
  // operator <=
2391
  /**
2392
   *  @brief  Test if string doesn't follow string.
2393
   *  @param __lhs  First string.
2394
   *  @param __rhs  Second string.
2395
   *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
2396
   */
2397
  template<typename _CharT, typename _Traits, typename _Alloc,
2398
           template <typename, typename, typename> class _Base>
2399
    inline bool
2400
    operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2401
               const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2402
    { return __lhs.compare(__rhs) <= 0; }
2403
 
2404
  /**
2405
   *  @brief  Test if string doesn't follow C string.
2406
   *  @param __lhs  String.
2407
   *  @param __rhs  C string.
2408
   *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
2409
   */
2410
  template<typename _CharT, typename _Traits, typename _Alloc,
2411
           template <typename, typename, typename> class _Base>
2412
    inline bool
2413
    operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2414
               const _CharT* __rhs)
2415
    { return __lhs.compare(__rhs) <= 0; }
2416
 
2417
  /**
2418
   *  @brief  Test if C string doesn't follow string.
2419
   *  @param __lhs  C string.
2420
   *  @param __rhs  String.
2421
   *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
2422
   */
2423
  template<typename _CharT, typename _Traits, typename _Alloc,
2424
           template <typename, typename, typename> class _Base>
2425
    inline bool
2426
    operator<=(const _CharT* __lhs,
2427
               const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2428
    { return __rhs.compare(__lhs) >= 0; }
2429
 
2430
  // operator >=
2431
  /**
2432
   *  @brief  Test if string doesn't precede string.
2433
   *  @param __lhs  First string.
2434
   *  @param __rhs  Second string.
2435
   *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
2436
   */
2437
  template<typename _CharT, typename _Traits, typename _Alloc,
2438
           template <typename, typename, typename> class _Base>
2439
    inline bool
2440
    operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2441
               const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2442
    { return __lhs.compare(__rhs) >= 0; }
2443
 
2444
  /**
2445
   *  @brief  Test if string doesn't precede C string.
2446
   *  @param __lhs  String.
2447
   *  @param __rhs  C string.
2448
   *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
2449
   */
2450
  template<typename _CharT, typename _Traits, typename _Alloc,
2451
           template <typename, typename, typename> class _Base>
2452
    inline bool
2453
    operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2454
               const _CharT* __rhs)
2455
    { return __lhs.compare(__rhs) >= 0; }
2456
 
2457
  /**
2458
   *  @brief  Test if C string doesn't precede string.
2459
   *  @param __lhs  C string.
2460
   *  @param __rhs  String.
2461
   *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
2462
   */
2463
  template<typename _CharT, typename _Traits, typename _Alloc,
2464
           template <typename, typename, typename> class _Base>
2465
    inline bool
2466
    operator>=(const _CharT* __lhs,
2467
               const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2468
    { return __rhs.compare(__lhs) <= 0; }
2469
 
2470
  /**
2471
   *  @brief  Swap contents of two strings.
2472
   *  @param __lhs  First string.
2473
   *  @param __rhs  Second string.
2474
   *
2475
   *  Exchanges the contents of @a __lhs and @a __rhs in constant time.
2476
   */
2477
  template<typename _CharT, typename _Traits, typename _Alloc,
2478
           template <typename, typename, typename> class _Base>
2479
    inline void
2480
    swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2481
         __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2482
    { __lhs.swap(__rhs); }
2483
 
2484
_GLIBCXX_END_NAMESPACE_VERSION
2485
} // namespace
2486
 
2487
namespace std _GLIBCXX_VISIBILITY(default)
2488
{
2489
_GLIBCXX_BEGIN_NAMESPACE_VERSION
2490
 
2491
  /**
2492
   *  @brief  Read stream into a string.
2493
   *  @param __is  Input stream.
2494
   *  @param __str  Buffer to store into.
2495
   *  @return  Reference to the input stream.
2496
   *
2497
   *  Stores characters from @a __is into @a __str until whitespace is
2498
   *  found, the end of the stream is encountered, or str.max_size()
2499
   *  is reached.  If is.width() is non-zero, that is the limit on the
2500
   *  number of characters stored into @a __str.  Any previous
2501
   *  contents of @a __str are erased.
2502
   */
2503
  template<typename _CharT, typename _Traits, typename _Alloc,
2504
           template <typename, typename, typename> class _Base>
2505
    basic_istream<_CharT, _Traits>&
2506
    operator>>(basic_istream<_CharT, _Traits>& __is,
2507
               __gnu_cxx::__versa_string<_CharT, _Traits,
2508
                                         _Alloc, _Base>& __str);
2509
 
2510
  /**
2511
   *  @brief  Write string to a stream.
2512
   *  @param __os  Output stream.
2513
   *  @param __str  String to write out.
2514
   *  @return  Reference to the output stream.
2515
   *
2516
   *  Output characters of @a __str into os following the same rules as for
2517
   *  writing a C string.
2518
   */
2519
  template<typename _CharT, typename _Traits, typename _Alloc,
2520
           template <typename, typename, typename> class _Base>
2521
    inline basic_ostream<_CharT, _Traits>&
2522
    operator<<(basic_ostream<_CharT, _Traits>& __os,
2523
               const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
2524
               _Base>& __str)
2525
    {
2526
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
2527
      // 586. string inserter not a formatted function
2528
      return __ostream_insert(__os, __str.data(), __str.size());
2529
    }
2530
 
2531
  /**
2532
   *  @brief  Read a line from stream into a string.
2533
   *  @param __is  Input stream.
2534
   *  @param __str  Buffer to store into.
2535
   *  @param __delim  Character marking end of line.
2536
   *  @return  Reference to the input stream.
2537
   *
2538
   *  Stores characters from @a __is into @a __str until @a __delim is
2539
   *  found, the end of the stream is encountered, or str.max_size()
2540
   *  is reached.  If is.width() is non-zero, that is the limit on the
2541
   *  number of characters stored into @a __str.  Any previous
2542
   *  contents of @a __str are erased.  If @a delim was encountered,
2543
   *  it is extracted but not stored into @a __str.
2544
   */
2545
  template<typename _CharT, typename _Traits, typename _Alloc,
2546
           template <typename, typename, typename> class _Base>
2547
    basic_istream<_CharT, _Traits>&
2548
    getline(basic_istream<_CharT, _Traits>& __is,
2549
            __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
2550
            _CharT __delim);
2551
 
2552
  /**
2553
   *  @brief  Read a line from stream into a string.
2554
   *  @param __is  Input stream.
2555
   *  @param __str  Buffer to store into.
2556
   *  @return  Reference to the input stream.
2557
   *
2558
   *  Stores characters from is into @a __str until &apos;\n&apos; is
2559
   *  found, the end of the stream is encountered, or str.max_size()
2560
   *  is reached.  If is.width() is non-zero, that is the limit on the
2561
   *  number of characters stored into @a __str.  Any previous
2562
   *  contents of @a __str are erased.  If end of line was
2563
   *  encountered, it is extracted but not stored into @a __str.
2564
   */
2565
  template<typename _CharT, typename _Traits, typename _Alloc,
2566
           template <typename, typename, typename> class _Base>
2567
    inline basic_istream<_CharT, _Traits>&
2568
    getline(basic_istream<_CharT, _Traits>& __is,
2569
            __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
2570
    { return getline(__is, __str, __is.widen('\n')); }
2571
 
2572
_GLIBCXX_END_NAMESPACE_VERSION
2573
} // namespace
2574
 
2575
#if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99))
2576
 
2577
#include <ext/string_conversions.h>
2578
 
2579
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
2580
{
2581
_GLIBCXX_BEGIN_NAMESPACE_VERSION
2582
 
2583
  // 21.4 Numeric Conversions [string.conversions].
2584
  inline int
2585
  stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2586
  { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
2587
                                        __idx, __base); }
2588
 
2589
  inline long
2590
  stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2591
  { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
2592
                             __idx, __base); }
2593
 
2594
  inline unsigned long
2595
  stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2596
  { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
2597
                             __idx, __base); }
2598
 
2599
  inline long long
2600
  stoll(const __vstring& __str, std::size_t* __idx = 0,  int __base = 10)
2601
  { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
2602
                             __idx, __base); }
2603
 
2604
  inline unsigned long long
2605
  stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
2606
  { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
2607
                             __idx, __base); }
2608
 
2609
  // NB: strtof vs strtod.
2610
  inline float
2611
  stof(const __vstring& __str, std::size_t* __idx = 0)
2612
  { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
2613
 
2614
  inline double
2615
  stod(const __vstring& __str, std::size_t* __idx = 0)
2616
  { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
2617
 
2618
  inline long double
2619
  stold(const __vstring& __str, std::size_t* __idx = 0)
2620
  { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
2621
 
2622
  // NB: (v)snprintf vs sprintf.
2623
 
2624
  // DR 1261.
2625
  inline __vstring
2626
  to_string(int __val)
2627
  { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
2628
                                              "%d", __val); }
2629
 
2630
  inline __vstring
2631
  to_string(unsigned __val)
2632
  { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2633
                                              4 * sizeof(unsigned),
2634
                                              "%u", __val); }
2635
 
2636
  inline __vstring
2637
  to_string(long __val)
2638
  { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2639
                                              4 * sizeof(long),
2640
                                              "%ld", __val); }
2641
 
2642
  inline __vstring
2643
  to_string(unsigned long __val)
2644
  { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2645
                                              4 * sizeof(unsigned long),
2646
                                              "%lu", __val); }
2647
 
2648
 
2649
  inline __vstring
2650
  to_string(long long __val)
2651
  { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2652
                                              4 * sizeof(long long),
2653
                                              "%lld", __val); }
2654
 
2655
  inline __vstring
2656
  to_string(unsigned long long __val)
2657
  { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2658
                                              4 * sizeof(unsigned long long),
2659
                                              "%llu", __val); }
2660
 
2661
  inline __vstring
2662
  to_string(float __val)
2663
  {
2664
    const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2665
    return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2666
                                              "%f", __val);
2667
  }
2668
 
2669
  inline __vstring
2670
  to_string(double __val)
2671
  {
2672
    const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2673
    return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2674
                                              "%f", __val);
2675
  }
2676
 
2677
  inline __vstring
2678
  to_string(long double __val)
2679
  {
2680
    const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2681
    return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2682
                                              "%Lf", __val);
2683
  }
2684
 
2685
#ifdef _GLIBCXX_USE_WCHAR_T
2686
  inline int
2687
  stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2688
  { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
2689
                                        __idx, __base); }
2690
 
2691
  inline long
2692
  stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2693
  { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
2694
                             __idx, __base); }
2695
 
2696
  inline unsigned long
2697
  stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2698
  { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
2699
                             __idx, __base); }
2700
 
2701
  inline long long
2702
  stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2703
  { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
2704
                             __idx, __base); }
2705
 
2706
  inline unsigned long long
2707
  stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2708
  { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
2709
                             __idx, __base); }
2710
 
2711
  // NB: wcstof vs wcstod.
2712
  inline float
2713
  stof(const __wvstring& __str, std::size_t* __idx = 0)
2714
  { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
2715
 
2716
  inline double
2717
  stod(const __wvstring& __str, std::size_t* __idx = 0)
2718
  { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
2719
 
2720
  inline long double
2721
  stold(const __wvstring& __str, std::size_t* __idx = 0)
2722
  { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
2723
 
2724
#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
2725
  // DR 1261.
2726
  inline __wvstring
2727
  to_wstring(int __val)
2728
  { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2729
                                               4 * sizeof(int),
2730
                                               L"%d", __val); }
2731
 
2732
  inline __wvstring
2733
  to_wstring(unsigned __val)
2734
  { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2735
                                               4 * sizeof(unsigned),
2736
                                               L"%u", __val); }
2737
 
2738
  inline __wvstring
2739
  to_wstring(long __val)
2740
  { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2741
                                               4 * sizeof(long),
2742
                                               L"%ld", __val); }
2743
 
2744
  inline __wvstring
2745
  to_wstring(unsigned long __val)
2746
  { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2747
                                               4 * sizeof(unsigned long),
2748
                                               L"%lu", __val); }
2749
 
2750
  inline __wvstring
2751
  to_wstring(long long __val)
2752
  { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2753
                                               4 * sizeof(long long),
2754
                                               L"%lld", __val); }
2755
 
2756
  inline __wvstring
2757
  to_wstring(unsigned long long __val)
2758
  { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2759
                                               4 * sizeof(unsigned long long),
2760
                                               L"%llu", __val); }
2761
 
2762
  inline __wvstring
2763
  to_wstring(float __val)
2764
  {
2765
    const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2766
    return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2767
                                               L"%f", __val);
2768
  }
2769
 
2770
  inline __wvstring
2771
  to_wstring(double __val)
2772
  {
2773
    const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2774
    return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2775
                                               L"%f", __val);
2776
  }
2777
 
2778
  inline __wvstring
2779
  to_wstring(long double __val)
2780
  {
2781
    const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2782
    return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2783
                                               L"%Lf", __val);
2784
  }
2785
#endif
2786
#endif
2787
 
2788
_GLIBCXX_END_NAMESPACE_VERSION
2789
} // namespace
2790
 
2791
#endif
2792
 
2793
#if __cplusplus >= 201103L
2794
 
2795
#include <bits/functional_hash.h>
2796
 
2797
namespace std _GLIBCXX_VISIBILITY(default)
2798
{
2799
_GLIBCXX_BEGIN_NAMESPACE_VERSION
2800
 
2801
  /// std::hash specialization for __vstring.
2802
  template<>
2803
    struct hash<__gnu_cxx::__vstring>
2804
    : public __hash_base<size_t, __gnu_cxx::__vstring>
2805
    {
2806
      size_t
2807
      operator()(const __gnu_cxx::__vstring& __s) const noexcept
2808
      { return std::_Hash_impl::hash(__s.data(), __s.length()); }
2809
    };
2810
 
2811
#ifdef _GLIBCXX_USE_WCHAR_T
2812
  /// std::hash specialization for __wvstring.
2813
  template<>
2814
    struct hash<__gnu_cxx::__wvstring>
2815
    : public __hash_base<size_t, __gnu_cxx::__wvstring>
2816
    {
2817
      size_t
2818
      operator()(const __gnu_cxx::__wvstring& __s) const noexcept
2819
      { return std::_Hash_impl::hash(__s.data(),
2820
                                     __s.length() * sizeof(wchar_t)); }
2821
    };
2822
#endif
2823
 
2824
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
2825
  /// std::hash specialization for __u16vstring.
2826
  template<>
2827
    struct hash<__gnu_cxx::__u16vstring>
2828
    : public __hash_base<size_t, __gnu_cxx::__u16vstring>
2829
    {
2830
      size_t
2831
      operator()(const __gnu_cxx::__u16vstring& __s) const noexcept
2832
      { return std::_Hash_impl::hash(__s.data(),
2833
                                     __s.length() * sizeof(char16_t)); }
2834
    };
2835
 
2836
  /// std::hash specialization for __u32vstring.
2837
  template<>
2838
    struct hash<__gnu_cxx::__u32vstring>
2839
    : public __hash_base<size_t, __gnu_cxx::__u32vstring>
2840
    {
2841
      size_t
2842
      operator()(const __gnu_cxx::__u32vstring& __s) const noexcept
2843
      { return std::_Hash_impl::hash(__s.data(),
2844
                                     __s.length() * sizeof(char32_t)); }
2845
    };
2846
#endif
2847
 
2848
_GLIBCXX_END_NAMESPACE_VERSION
2849
} // namespace
2850
 
2851
#endif // C++11
2852
 
2853
#include "vstring.tcc" 
2854
 
2855
#endif /* _VSTRING_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.