00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
#ifndef _BASIC_STRING_TCC
00042
#define _BASIC_STRING_TCC 1
00043
00044
#pragma GCC system_header
00045
00046
namespace std
00047 {
00048
template<
typename _Type>
00049
inline bool
00050 __is_null_pointer(_Type* __ptr)
00051 {
return __ptr == 0; }
00052
00053
template<
typename _Type>
00054
inline bool
00055 __is_null_pointer(_Type)
00056 {
return false; }
00057
00058
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00059
const typename basic_string<_CharT, _Traits, _Alloc>::size_type
00060 basic_string<_CharT, _Traits, _Alloc>::
00061 _Rep::_S_max_size = (((npos -
sizeof(_Rep_base))/
sizeof(_CharT)) - 1) / 4;
00062
00063
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00064
const _CharT
00065 basic_string<_CharT, _Traits, _Alloc>::
00066 _Rep::_S_terminal = _CharT();
00067
00068
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00069
const typename basic_string<_CharT, _Traits, _Alloc>::size_type
00070 basic_string<_CharT, _Traits, _Alloc>::npos;
00071
00072
00073
00074
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00075
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00076
basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
00077 (
sizeof(_Rep_base) +
sizeof(_CharT) +
sizeof(size_type) - 1) /
00078
sizeof(size_type)];
00079
00080
00081
00082
00083
00084
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00085
template<
typename _InIterator>
00086 _CharT*
00087
basic_string<_CharT, _Traits, _Alloc>::
00088
_S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
00089
input_iterator_tag)
00090 {
00091
if (__beg == __end && __a == _Alloc())
00092
return _S_empty_rep()._M_refdata();
00093
00094 _CharT __buf[128];
00095 size_type __len = 0;
00096
while (__beg != __end && __len <
sizeof(__buf) /
sizeof(_CharT))
00097 {
00098 __buf[__len++] = *__beg;
00099 ++__beg;
00100 }
00101 _Rep* __r = _Rep::_S_create(__len, size_type(0), __a);
00102 traits_type::copy(__r->_M_refdata(), __buf, __len);
00103
try
00104 {
00105
while (__beg != __end)
00106 {
00107
if (__len == __r->_M_capacity)
00108 {
00109
00110 _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
00111 traits_type::copy(__another->_M_refdata(),
00112 __r->_M_refdata(), __len);
00113 __r->_M_destroy(__a);
00114 __r = __another;
00115 }
00116 __r->_M_refdata()[__len++] = *__beg;
00117 ++__beg;
00118 }
00119 }
00120
catch(...)
00121 {
00122 __r->_M_destroy(__a);
00123 __throw_exception_again;
00124 }
00125 __r->_M_length = __len;
00126 __r->_M_refdata()[__len] = _Rep::_S_terminal;
00127
return __r->_M_refdata();
00128 }
00129
00130
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00131
template <
typename _InIterator>
00132 _CharT*
00133
basic_string<_CharT, _Traits, _Alloc>::
00134
_S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
00135
forward_iterator_tag)
00136 {
00137
if (__beg == __end && __a == _Alloc())
00138
return _S_empty_rep()._M_refdata();
00139
00140
00141
if (__builtin_expect(__is_null_pointer(__beg), 0))
00142 __throw_logic_error(__N(
"basic_string::_S_construct NULL not valid"));
00143
00144
const size_type __dnew = static_cast<size_type>(
std::distance(__beg,
00145 __end));
00146
00147 _Rep* __r = _Rep::_S_create(__dnew, size_type(0), __a);
00148
try
00149 { _S_copy_chars(__r->_M_refdata(), __beg, __end); }
00150
catch(...)
00151 {
00152 __r->_M_destroy(__a);
00153 __throw_exception_again;
00154 }
00155 __r->_M_length = __dnew;
00156 __r->_M_refdata()[__dnew] = _Rep::_S_terminal;
00157
return __r->_M_refdata();
00158 }
00159
00160
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00161 _CharT*
00162 basic_string<_CharT, _Traits, _Alloc>::
00163 _S_construct(size_type __n, _CharT __c,
const _Alloc& __a)
00164 {
00165
if (__n == 0 && __a == _Alloc())
00166
return _S_empty_rep()._M_refdata();
00167
00168
00169 _Rep* __r = _Rep::_S_create(__n, size_type(0), __a);
00170
if (__n)
00171 traits_type::assign(__r->_M_refdata(), __n, __c);
00172
00173 __r->_M_length = __n;
00174 __r->_M_refdata()[__n] = _Rep::_S_terminal;
00175
return __r->_M_refdata();
00176 }
00177
00178
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00179 basic_string<_CharT, _Traits, _Alloc>::
00180 basic_string(
const basic_string& __str)
00181 : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.get_allocator()),
00182 __str.get_allocator()),
00183 __str.get_allocator())
00184 { }
00185
00186
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00187
basic_string<_CharT, _Traits, _Alloc>::
00188 basic_string(
const _Alloc& __a)
00189 : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
00190 { }
00191
00192
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00193
basic_string<_CharT, _Traits, _Alloc>::
00194 basic_string(
const basic_string& __str, size_type __pos, size_type __n)
00195 : _M_dataplus(_S_construct(__str._M_data()
00196 + __str._M_check(__pos,
00197 "
basic_string::
basic_string"),
00198 __str._M_data() + __str._M_limit(__pos, __n)
00199 + __pos, _Alloc()), _Alloc())
00200 { }
00201
00202
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00203
basic_string<_CharT, _Traits, _Alloc>::
00204 basic_string(
const basic_string& __str, size_type __pos,
00205 size_type __n,
const _Alloc& __a)
00206 : _M_dataplus(_S_construct(__str._M_data()
00207 + __str._M_check(__pos,
00208 "
basic_string::
basic_string"),
00209 __str._M_data() + __str._M_limit(__pos, __n)
00210 + __pos, __a), __a)
00211 { }
00212
00213
00214
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00215
basic_string<_CharT, _Traits, _Alloc>::
00216 basic_string(
const _CharT* __s, size_type __n,
const _Alloc& __a)
00217 : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
00218 { }
00219
00220
00221
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00222
basic_string<_CharT, _Traits, _Alloc>::
00223 basic_string(
const _CharT* __s,
const _Alloc& __a)
00224 : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) :
00225 __s + npos, __a), __a)
00226 { }
00227
00228
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00229
basic_string<_CharT, _Traits, _Alloc>::
00230 basic_string(size_type __n, _CharT __c,
const _Alloc& __a)
00231 : _M_dataplus(_S_construct(__n, __c, __a), __a)
00232 { }
00233
00234
00235
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00236
template<
typename _InputIterator>
00237
basic_string<_CharT, _Traits, _Alloc>::
00238 basic_string(_InputIterator __beg, _InputIterator __end,
const _Alloc& __a)
00239 : _M_dataplus(_S_construct(__beg, __end, __a), __a)
00240 { }
00241
00242
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00243
basic_string<_CharT, _Traits, _Alloc>&
00244
basic_string<_CharT, _Traits, _Alloc>::
00245 assign(
const basic_string& __str)
00246 {
00247
if (_M_rep() != __str._M_rep())
00248 {
00249
00250
const allocator_type __a = this->
get_allocator();
00251 _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.
get_allocator());
00252 _M_rep()->_M_dispose(__a);
00253 _M_data(__tmp);
00254 }
00255
return *
this;
00256 }
00257
00258
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00259
basic_string<_CharT, _Traits, _Alloc>&
00260
basic_string<_CharT, _Traits, _Alloc>::
00261 assign(
const _CharT* __s, size_type __n)
00262 {
00263 __glibcxx_requires_string_len(__s, __n);
00264
if (__n > this->
max_size())
00265 __throw_length_error(__N(
"basic_string::assign"));
00266
if (_M_rep()->_M_is_shared() ||
less<const _CharT*>()(__s, _M_data())
00267 ||
less<const _CharT*>()(_M_data() + this->
size(), __s))
00268
return _M_replace_safe(size_type(0), this->size(), __s, __n);
00269
else
00270 {
00271
00272
const size_type __pos = __s - _M_data();
00273
if (__pos >= __n)
00274 traits_type::copy(_M_data(), __s, __n);
00275
else if (__pos)
00276 traits_type::move(_M_data(), __s, __n);
00277 _M_rep()->_M_set_sharable();
00278 _M_rep()->_M_length = __n;
00279 _M_data()[__n] = _Rep::_S_terminal;
00280
return *
this;
00281 }
00282 }
00283
00284
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00285
basic_string<_CharT, _Traits, _Alloc>&
00286
basic_string<_CharT, _Traits, _Alloc>::
00287 insert(size_type __pos,
const _CharT* __s, size_type __n)
00288 {
00289 __glibcxx_requires_string_len(__s, __n);
00290 _M_check(__pos,
"basic_string::insert");
00291
if (this->
max_size() - this->
size() < __n)
00292 __throw_length_error(__N(
"basic_string::insert"));
00293
if (_M_rep()->_M_is_shared() ||
less<const _CharT*>()(__s, _M_data())
00294 ||
less<const _CharT*>()(_M_data() + this->
size(), __s))
00295
return _M_replace_safe(__pos, size_type(0), __s, __n);
00296
else
00297 {
00298
00299
00300
00301
const size_type __off = __s - _M_data();
00302 _M_mutate(__pos, 0, __n);
00303 __s = _M_data() + __off;
00304 _CharT* __p = _M_data() + __pos;
00305
if (__s + __n <= __p)
00306 traits_type::copy(__p, __s, __n);
00307
else if (__s >= __p)
00308 traits_type::copy(__p, __s + __n, __n);
00309
else
00310 {
00311
const size_type __nleft = __p - __s;
00312 traits_type::copy(__p, __s, __nleft);
00313 traits_type::copy(__p + __nleft, __p + __n, __n - __nleft);
00314 }
00315
return *
this;
00316 }
00317 }
00318
00319
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00320
basic_string<_CharT, _Traits, _Alloc>&
00321
basic_string<_CharT, _Traits, _Alloc>::
00322 replace(size_type __pos, size_type __n1,
const _CharT* __s,
00323 size_type __n2)
00324 {
00325 __glibcxx_requires_string_len(__s, __n2);
00326 _M_check(__pos,
"basic_string::replace");
00327 __n1 = _M_limit(__pos, __n1);
00328
if (this->
max_size() - (this->
size() - __n1) < __n2)
00329 __throw_length_error(__N(
"basic_string::replace"));
00330
bool __left;
00331
if (_M_rep()->_M_is_shared() ||
less<const _CharT*>()(__s, _M_data())
00332 ||
less<const _CharT*>()(_M_data() + this->
size(), __s))
00333
return _M_replace_safe(__pos, __n1, __s, __n2);
00334
else if ((__left = __s + __n2 <= _M_data() + __pos)
00335 || _M_data() + __pos + __n1 <= __s)
00336 {
00337
00338
const size_type __off = __s - _M_data();
00339 _M_mutate(__pos, __n1, __n2);
00340
if (__left)
00341 traits_type::copy(_M_data() + __pos,
00342 _M_data() + __off, __n2);
00343
else
00344 traits_type::copy(_M_data() + __pos,
00345 _M_data() + __off + __n2 - __n1, __n2);
00346
return *
this;
00347 }
00348
else
00349 {
00350
00351
const basic_string __tmp(__s, __n2);
00352
return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2);
00353 }
00354 }
00355
00356
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00357
void
00358
basic_string<_CharT, _Traits, _Alloc>::_Rep::
00359
_M_destroy(
const _Alloc& __a)
throw ()
00360 {
00361
if (
this == &_S_empty_rep())
00362
return;
00363
const size_type __size =
sizeof(_Rep_base) +
00364 (this->_M_capacity + 1) *
sizeof(_CharT);
00365 _Raw_bytes_alloc(__a).deallocate(reinterpret_cast<char*>(
this), __size);
00366 }
00367
00368
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00369
void
00370 basic_string<_CharT, _Traits, _Alloc>::_M_leak_hard()
00371 {
00372
if (_M_rep() == &_S_empty_rep())
00373
return;
00374
if (_M_rep()->_M_is_shared())
00375 _M_mutate(0, 0, 0);
00376 _M_rep()->_M_set_leaked();
00377 }
00378
00379
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00380
void
00381 basic_string<_CharT, _Traits, _Alloc>::
00382 _M_mutate(size_type __pos, size_type __len1, size_type __len2)
00383 {
00384
const size_type __old_size = this->
size();
00385
const size_type __new_size = __old_size + __len2 - __len1;
00386
const size_type __how_much = __old_size - __pos - __len1;
00387
00388
if (_M_rep() == &_S_empty_rep()
00389 || _M_rep()->_M_is_shared() || __new_size >
capacity())
00390 {
00391
00392
const allocator_type __a =
get_allocator();
00393 _Rep* __r = _Rep::_S_create(__new_size,
capacity(), __a);
00394
00395
if (__pos)
00396 traits_type::copy(__r->_M_refdata(), _M_data(), __pos);
00397
if (__how_much)
00398 traits_type::copy(__r->_M_refdata() + __pos + __len2,
00399 _M_data() + __pos + __len1, __how_much);
00400
00401 _M_rep()->_M_dispose(__a);
00402 _M_data(__r->_M_refdata());
00403 }
00404
else if (__how_much && __len1 != __len2)
00405 {
00406
00407 traits_type::move(_M_data() + __pos + __len2,
00408 _M_data() + __pos + __len1, __how_much);
00409 }
00410 _M_rep()->_M_set_sharable();
00411 _M_rep()->_M_length = __new_size;
00412 _M_data()[__new_size] = _Rep::_S_terminal;
00413
00414 }
00415
00416
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00417
void
00418 basic_string<_CharT, _Traits, _Alloc>::reserve(size_type __res)
00419 {
00420
if (__res != this->
capacity() || _M_rep()->_M_is_shared())
00421 {
00422
if (__res > this->
max_size())
00423 __throw_length_error(__N(
"basic_string::reserve"));
00424
00425
if (__res < this->
size())
00426 __res = this->
size();
00427
const allocator_type __a =
get_allocator();
00428 _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->size());
00429 _M_rep()->_M_dispose(__a);
00430 _M_data(__tmp);
00431 }
00432 }
00433
00434
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00435 void basic_string<_CharT, _Traits, _Alloc>::swap(
basic_string& __s)
00436 {
00437
if (_M_rep()->_M_is_leaked())
00438 _M_rep()->_M_set_sharable();
00439
if (__s._M_rep()->_M_is_leaked())
00440 __s._M_rep()->_M_set_sharable();
00441
if (this->
get_allocator() == __s.
get_allocator())
00442 {
00443 _CharT* __tmp = _M_data();
00444 _M_data(__s._M_data());
00445 __s._M_data(__tmp);
00446 }
00447
00448
else
00449 {
00450
const basic_string __tmp1(_M_ibegin(), _M_iend(),
00451 __s.
get_allocator());
00452
const basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
00453 this->
get_allocator());
00454 *
this = __tmp2;
00455 __s = __tmp1;
00456 }
00457 }
00458
00459
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00460
typename basic_string<_CharT, _Traits, _Alloc>::_Rep*
00461
basic_string<_CharT, _Traits, _Alloc>::_Rep::
00462
_S_create(size_type __capacity, size_type __old_capacity,
00463
const _Alloc& __alloc)
00464 {
00465
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00466
00467
00468
if (__capacity > _S_max_size)
00469 __throw_length_error(__N(
"basic_string::_S_create"));
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
const size_type __pagesize = 4096;
00495
const size_type __subpagesize = 128;
00496
const size_type __malloc_header_size = 4 *
sizeof (
void*);
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
const size_type __page_capacity = ((__pagesize - __malloc_header_size
00507 -
sizeof(_Rep) -
sizeof(_CharT))
00508 /
sizeof(_CharT));
00509
00510
if (__capacity > __old_capacity && __capacity < 2 * __old_capacity
00511 && __capacity > __page_capacity)
00512 __capacity = 2 * __old_capacity;
00513
00514
00515
00516
00517 size_type __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
00518
00519
const size_type __adj_size = __size + __malloc_header_size;
00520
if (__adj_size > __pagesize)
00521 {
00522
const size_type __extra = __pagesize - __adj_size % __pagesize;
00523 __capacity += __extra /
sizeof(_CharT);
00524
00525
if (__capacity > _S_max_size)
00526 __capacity = _S_max_size;
00527 __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
00528 }
00529
else if (__size > __subpagesize)
00530 {
00531
const size_type __extra = __subpagesize - __adj_size % __subpagesize;
00532 __capacity += __extra /
sizeof(_CharT);
00533 __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
00534 }
00535
00536
00537
00538
void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
00539 _Rep *__p =
new (__place) _Rep;
00540 __p->_M_capacity = __capacity;
00541 __p->_M_set_sharable();
00542 __p->_M_length = 0;
00543
return __p;
00544 }
00545
00546
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00547 _CharT*
00548 basic_string<_CharT, _Traits, _Alloc>::_Rep::
00549 _M_clone(
const _Alloc& __alloc, size_type __res)
00550 {
00551
00552
const size_type __requested_cap = this->_M_length + __res;
00553 _Rep* __r = _Rep::_S_create(__requested_cap, this->_M_capacity,
00554 __alloc);
00555
if (this->_M_length)
00556 traits_type::copy(__r->_M_refdata(), _M_refdata(),
00557 this->_M_length);
00558
00559 __r->_M_length = this->_M_length;
00560 __r->_M_refdata()[this->_M_length] = _Rep::_S_terminal;
00561
return __r->_M_refdata();
00562 }
00563
00564
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00565
void
00566 basic_string<_CharT, _Traits, _Alloc>::resize(size_type __n, _CharT __c)
00567 {
00568
if (__n >
max_size())
00569 __throw_length_error(__N(
"basic_string::resize"));
00570
const size_type __size = this->
size();
00571
if (__size < __n)
00572 this->
append(__n - __size, __c);
00573
else if (__n < __size)
00574 this->
erase(__n);
00575
00576 }
00577
00578
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00579
template<
typename _InputIterator>
00580
basic_string<_CharT, _Traits, _Alloc>&
00581
basic_string<_CharT, _Traits, _Alloc>::
00582
_M_replace_dispatch(
iterator __i1,
iterator __i2, _InputIterator __k1,
00583 _InputIterator __k2, __false_type)
00584 {
00585
const basic_string __s(__k1, __k2);
00586
const size_type __n1 = __i2 - __i1;
00587
if (this->
max_size() - (this->
size() - __n1) < __s.
size())
00588 __throw_length_error(__N(
"basic_string::_M_replace_dispatch"));
00589
return _M_replace_safe(__i1 - _M_ibegin(), __n1, __s._M_data(),
00590 __s.
size());
00591 }
00592
00593
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00594 basic_string<_CharT, _Traits, _Alloc>&
00595 basic_string<_CharT, _Traits, _Alloc>::
00596 append(
const basic_string& __str)
00597 {
00598
00599
00600
00601
const size_type __size = __str.
size();
00602
const size_type __len = __size + this->
size();
00603
if (__len > this->
capacity())
00604 this->
reserve(__len);
00605
return _M_replace_safe(this->size(), size_type(0), __str._M_data(),
00606 __str.
size());
00607 }
00608
00609
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00610
basic_string<_CharT, _Traits, _Alloc>&
00611
basic_string<_CharT, _Traits, _Alloc>::
00612 append(
const basic_string& __str, size_type __pos, size_type __n)
00613 {
00614
00615
00616
00617 __str._M_check(__pos,
"basic_string::append");
00618 __n = __str._M_limit(__pos, __n);
00619
const size_type __len = __n + this->
size();
00620
if (__len > this->
capacity())
00621 this->
reserve(__len);
00622
return _M_replace_safe(this->size(), size_type(0), __str._M_data()
00623 + __pos, __n);
00624 }
00625
00626
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00627
basic_string<_CharT, _Traits, _Alloc>&
00628
basic_string<_CharT, _Traits, _Alloc>::
00629 append(
const _CharT* __s, size_type __n)
00630 {
00631 __glibcxx_requires_string_len(__s, __n);
00632
const size_type __len = __n + this->
size();
00633
if (__len > this->
capacity())
00634 this->
reserve(__len);
00635
return _M_replace_safe(this->size(), size_type(0), __s, __n);
00636 }
00637
00638
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00639
basic_string<_CharT, _Traits, _Alloc>
00640 operator+(
const _CharT* __lhs,
00641
const basic_string<_CharT, _Traits, _Alloc>& __rhs)
00642 {
00643 __glibcxx_requires_string(__lhs);
00644
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00645
typedef typename __string_type::size_type __size_type;
00646
const __size_type __len = _Traits::length(__lhs);
00647 __string_type __str;
00648 __str.
reserve(__len + __rhs.
size());
00649 __str.append(__lhs, __len);
00650 __str.append(__rhs);
00651
return __str;
00652 }
00653
00654
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00655 basic_string<_CharT, _Traits, _Alloc>
00656 operator+(_CharT __lhs,
const basic_string<_CharT, _Traits, _Alloc>& __rhs)
00657 {
00658
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00659
typedef typename __string_type::size_type __size_type;
00660 __string_type __str;
00661
const __size_type __len = __rhs.
size();
00662 __str.reserve(__len + 1);
00663 __str.append(__size_type(1), __lhs);
00664 __str.append(__rhs);
00665
return __str;
00666 }
00667
00668
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00669
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00670 basic_string<_CharT, _Traits, _Alloc>::
00671 copy(_CharT* __s, size_type __n, size_type __pos)
const
00672
{
00673 _M_check(__pos,
"basic_string::copy");
00674 __n = _M_limit(__pos, __n);
00675 __glibcxx_requires_string_len(__s, __n);
00676
if (__n)
00677 traits_type::copy(__s, _M_data() + __pos, __n);
00678
00679
return __n;
00680 }
00681
00682
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00683
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00684
basic_string<_CharT, _Traits, _Alloc>::
00685 find(
const _CharT* __s, size_type __pos, size_type __n)
const
00686
{
00687 __glibcxx_requires_string_len(__s, __n);
00688 size_type __ret =
npos;
00689
const size_type __size = this->
size();
00690
if (__pos + __n <= __size)
00691 {
00692
const _CharT* __data = _M_data();
00693
const _CharT* __p =
std::search(__data + __pos, __data + __size,
00694 __s, __s + __n, traits_type::eq);
00695
if (__p != __data + __size || __n == 0)
00696 __ret = __p - __data;
00697 }
00698
return __ret;
00699 }
00700
00701
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00702
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00703
basic_string<_CharT, _Traits, _Alloc>::
00704 find(_CharT __c, size_type __pos)
const
00705
{
00706 size_type __ret =
npos;
00707
const size_type __size = this->
size();
00708
if (__pos < __size)
00709 {
00710
const _CharT* __data = _M_data();
00711
const size_type __n = __size - __pos;
00712
const _CharT* __p = traits_type::find(__data + __pos, __n, __c);
00713
if (__p)
00714 __ret = __p - __data;
00715 }
00716
return __ret;
00717 }
00718
00719
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00720
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00721
basic_string<_CharT, _Traits, _Alloc>::
00722 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
00723
{
00724 __glibcxx_requires_string_len(__s, __n);
00725
const size_type __size = this->
size();
00726
if (__n <= __size)
00727 {
00728 __pos =
std::min(size_type(__size - __n), __pos);
00729
const _CharT* __data = _M_data();
00730
do
00731 {
00732
if (traits_type::compare(__data + __pos, __s, __n) == 0)
00733
return __pos;
00734 }
00735
while (__pos-- > 0);
00736 }
00737
return npos;
00738 }
00739
00740
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00741
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00742
basic_string<_CharT, _Traits, _Alloc>::
00743 rfind(_CharT __c, size_type __pos)
const
00744
{
00745 size_type __size = this->
size();
00746
if (__size)
00747 {
00748
if (--__size > __pos)
00749 __size = __pos;
00750
for (++__size; __size-- > 0; )
00751
if (traits_type::eq(_M_data()[__size], __c))
00752
return __size;
00753 }
00754
return npos;
00755 }
00756
00757
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00758
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00759
basic_string<_CharT, _Traits, _Alloc>::
00760 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
00761
{
00762 __glibcxx_requires_string_len(__s, __n);
00763
for (; __n && __pos < this->
size(); ++__pos)
00764 {
00765
const _CharT* __p = traits_type::find(__s, __n, _M_data()[__pos]);
00766
if (__p)
00767
return __pos;
00768 }
00769
return npos;
00770 }
00771
00772
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00773
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00774
basic_string<_CharT, _Traits, _Alloc>::
00775 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
00776
{
00777 __glibcxx_requires_string_len(__s, __n);
00778 size_type __size = this->
size();
00779
if (__size && __n)
00780 {
00781
if (--__size > __pos)
00782 __size = __pos;
00783
do
00784 {
00785
if (traits_type::find(__s, __n, _M_data()[__size]))
00786
return __size;
00787 }
00788
while (__size-- != 0);
00789 }
00790
return npos;
00791 }
00792
00793
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00794
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00795
basic_string<_CharT, _Traits, _Alloc>::
00796 find_first_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
00797
{
00798 __glibcxx_requires_string_len(__s, __n);
00799
for (; __pos < this->
size(); ++__pos)
00800
if (!traits_type::find(__s, __n, _M_data()[__pos]))
00801
return __pos;
00802
return npos;
00803 }
00804
00805
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00806
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00807
basic_string<_CharT, _Traits, _Alloc>::
00808 find_first_not_of(_CharT __c, size_type __pos)
const
00809
{
00810
for (; __pos < this->
size(); ++__pos)
00811
if (!traits_type::eq(_M_data()[__pos], __c))
00812
return __pos;
00813
return npos;
00814 }
00815
00816
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00817
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00818
basic_string<_CharT, _Traits, _Alloc>::
00819 find_last_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
00820
{
00821 __glibcxx_requires_string_len(__s, __n);
00822 size_type __size = this->
size();
00823
if (__size)
00824 {
00825
if (--__size > __pos)
00826 __size = __pos;
00827
do
00828 {
00829
if (!traits_type::find(__s, __n, _M_data()[__size]))
00830
return __size;
00831 }
00832
while (__size--);
00833 }
00834
return npos;
00835 }
00836
00837
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00838
typename basic_string<_CharT, _Traits, _Alloc>::size_type
00839
basic_string<_CharT, _Traits, _Alloc>::
00840 find_last_not_of(_CharT __c, size_type __pos)
const
00841
{
00842 size_type __size = this->
size();
00843
if (__size)
00844 {
00845
if (--__size > __pos)
00846 __size = __pos;
00847
do
00848 {
00849
if (!traits_type::eq(_M_data()[__size], __c))
00850
return __size;
00851 }
00852
while (__size--);
00853 }
00854
return npos;
00855 }
00856
00857
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00858
int
00859
basic_string<_CharT, _Traits, _Alloc>::
00860 compare(size_type __pos, size_type __n,
const basic_string& __str)
const
00861
{
00862 _M_check(__pos,
"basic_string::compare");
00863 __n = _M_limit(__pos, __n);
00864
const size_type __osize = __str.
size();
00865
const size_type __len =
std::min(__n, __osize);
00866
int __r = traits_type::compare(_M_data() + __pos, __str.
data(), __len);
00867
if (!__r)
00868 __r = __n - __osize;
00869
return __r;
00870 }
00871
00872
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00873
int
00874
basic_string<_CharT, _Traits, _Alloc>::
00875 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
00876 size_type __pos2, size_type __n2)
const
00877
{
00878 _M_check(__pos1,
"basic_string::compare");
00879 __str._M_check(__pos2,
"basic_string::compare");
00880 __n1 = _M_limit(__pos1, __n1);
00881 __n2 = __str._M_limit(__pos2, __n2);
00882
const size_type __len =
std::min(__n1, __n2);
00883
int __r = traits_type::compare(_M_data() + __pos1,
00884 __str.
data() + __pos2, __len);
00885
if (!__r)
00886 __r = __n1 - __n2;
00887
return __r;
00888 }
00889
00890
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00891
int
00892
basic_string<_CharT, _Traits, _Alloc>::
00893 compare(
const _CharT* __s)
const
00894
{
00895 __glibcxx_requires_string(__s);
00896
const size_type __size = this->
size();
00897
const size_type __osize = traits_type::length(__s);
00898
const size_type __len =
std::min(__size, __osize);
00899
int __r = traits_type::compare(_M_data(), __s, __len);
00900
if (!__r)
00901 __r = __size - __osize;
00902
return __r;
00903 }
00904
00905
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00906
int
00907 basic_string <_CharT, _Traits, _Alloc>::
00908 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
00909 {
00910 __glibcxx_requires_string(__s);
00911 _M_check(__pos,
"basic_string::compare");
00912 __n1 = _M_limit(__pos, __n1);
00913
const size_type __osize = traits_type::length(__s);
00914
const size_type __len =
std::min(__n1, __osize);
00915
int __r = traits_type::compare(_M_data() + __pos, __s, __len);
00916
if (!__r)
00917 __r = __n1 - __osize;
00918
return __r;
00919 }
00920
00921
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00922
int
00923 basic_string <_CharT, _Traits, _Alloc>::
00924 compare(size_type __pos, size_type __n1,
const _CharT* __s,
00925 size_type __n2)
const
00926 {
00927 __glibcxx_requires_string_len(__s, __n2);
00928 _M_check(__pos,
"basic_string::compare");
00929 __n1 = _M_limit(__pos, __n1);
00930
const size_type __len =
std::min(__n1, __n2);
00931
int __r = traits_type::compare(_M_data() + __pos, __s, __len);
00932
if (!__r)
00933 __r = __n1 - __n2;
00934
return __r;
00935 }
00936
00937
00938
00939
00940
#if _GLIBCXX_EXTERN_TEMPLATE
00941
extern template class basic_string<char>;
00942
extern template
00943 basic_istream<char>&
00944
operator>>(basic_istream<char>&,
string&);
00945
extern template
00946 basic_ostream<char>&
00947 operator<<(basic_ostream<char>&,
const string&);
00948
extern template
00949 basic_istream<char>&
00950
getline(basic_istream<char>&,
string&,
char);
00951
extern template
00952 basic_istream<char>&
00953
getline(basic_istream<char>&,
string&);
00954
00955
#ifdef _GLIBCXX_USE_WCHAR_T
00956
extern template class basic_string<wchar_t>;
00957
extern template
00958 basic_istream<wchar_t>&
00959
operator>>(basic_istream<wchar_t>&, wstring&);
00960
extern template
00961 basic_ostream<wchar_t>&
00962 operator<<(basic_ostream<wchar_t>&,
const wstring&);
00963
extern template
00964 basic_istream<wchar_t>&
00965
getline(basic_istream<wchar_t>&, wstring&,
wchar_t);
00966
extern template
00967 basic_istream<wchar_t>&
00968
getline(basic_istream<wchar_t>&, wstring&);
00969
#endif
00970
#endif
00971
}
00972
00973
#endif