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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc4/] [libstdc++-v3/] [include/] [ext/] [vstring.h] - Blame information for rev 519

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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