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