home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _string.c < prev    next >
C/C++ Source or Header  |  2002-02-02  |  20KB  |  577 lines

  1. /*
  2.  *
  3.  *
  4.  * Copyright (c) 1994
  5.  * Hewlett-Packard Company
  6.  *
  7.  * Copyright (c) 1996,1997
  8.  * Silicon Graphics Computer Systems, Inc.
  9.  *
  10.  * Copyright (c) 1997
  11.  * Moscow Center for SPARC Technology
  12.  *
  13.  * Copyright (c) 1999 
  14.  * Boris Fomitchev
  15.  *
  16.  * This material is provided "as is", with absolutely no warranty expressed
  17.  * or implied. Any use is at your own risk.
  18.  *
  19.  * Permission to use or copy this software for any purpose is hereby granted 
  20.  * without fee, provided the above notices are retained on all copies.
  21.  * Permission to modify the code and to distribute modified code is granted,
  22.  * provided the above notices are retained, and a notice that the code was
  23.  * modified is included with the above copyright notice.
  24.  *
  25.  */
  26. #ifndef _STLP_STRING_C
  27. #define _STLP_STRING_C
  28.  
  29. #ifndef _STLP_STRING_H
  30. # include <stl/_string.h>
  31. #endif
  32.  
  33. # ifdef _STLP_DEBUG
  34. #  define basic_string _Nondebug_string
  35. # endif
  36.  
  37. # if defined (_STLP_USE_OWN_NAMESPACE) || !defined (_STLP_USE_NATIVE_STRING)
  38.  
  39. # if defined (_STLP_NESTED_TYPE_PARAM_BUG)
  40. #  define __size_type__ size_t
  41. #  define size_type size_t
  42. #  define iterator   _CharT*
  43. # else
  44. #  define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_string<_CharT,_Traits,_Alloc>::size_type
  45. # endif
  46.  
  47. _STLP_BEGIN_NAMESPACE
  48.  
  49. // ------------------------------------------------------------
  50. // Non-inline declarations.
  51.  
  52.  
  53. // Change the string's capacity so that it is large enough to hold
  54. //  at least __res_arg elements, plus the terminating _CharT().  Note that,
  55. //  if __res_arg < capacity(), this member function may actually decrease
  56. //  the string's capacity.
  57. template <class _CharT, class _Traits, class _Alloc> void basic_string<_CharT,_Traits,_Alloc>::reserve(size_type __res_arg) {
  58.   if (__res_arg > max_size())
  59.     this->_M_throw_length_error();
  60.  
  61.   size_type __n = (max)(__res_arg, size()) + 1;
  62.   pointer __new_start = this->_M_end_of_storage.allocate(__n);
  63.   pointer __new_finish = __new_start;
  64.  
  65.   _STLP_TRY {
  66.     __new_finish = uninitialized_copy(this->_M_start, this->_M_finish, __new_start);
  67.     _M_construct_null(__new_finish);
  68.   }
  69.   _STLP_UNWIND((_Destroy(__new_start, __new_finish), 
  70.                 this->_M_end_of_storage.deallocate(__new_start, __n)));
  71.  
  72.   _Destroy(this->_M_start, this->_M_finish + 1);
  73.   this->_M_deallocate_block();
  74.   this->_M_start = __new_start;
  75.   this->_M_finish = __new_finish;
  76.   this->_M_end_of_storage._M_data = __new_start + __n;
  77. }
  78.  
  79. template <class _CharT, class _Traits, class _Alloc> basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc>::append(size_type __n, _CharT __c) {
  80.   if (__n > max_size() || size() > max_size() - __n)
  81.     this->_M_throw_length_error();
  82.   if (size() + __n > capacity())
  83.     reserve(size() + (max)(size(), __n));
  84.   if (__n > 0) {
  85.     uninitialized_fill_n(this->_M_finish + 1, __n - 1, __c);
  86.     _STLP_TRY {
  87.       _M_construct_null(this->_M_finish + __n);
  88.     }
  89.     _STLP_UNWIND(_Destroy(this->_M_finish + 1, this->_M_finish + __n));
  90.     _Traits::assign(*end(), __c);
  91.     this->_M_finish += __n;
  92.   }
  93.   return *this;
  94. }
  95.  
  96. #ifndef _STLP_MEMBER_TEMPLATES
  97.  
  98. template <class _CharT, class _Traits, class _Alloc> basic_string<_CharT, _Traits, _Alloc>& basic_string<_CharT, _Traits, _Alloc>::append(const _CharT* __first,
  99.                           const _CharT* __last)
  100. {
  101.   if (__first != __last) {
  102.     const size_type __old_size = size();
  103.     ptrdiff_t __n = __last - __first;
  104.     if ((size_type)__n > max_size() || __old_size > max_size() - __n)
  105.       this->_M_throw_length_error();
  106.     if (__old_size + __n > capacity()) {
  107.       const size_type __len = __old_size + (max)(__old_size, (size_t) __n) + 1;
  108.       pointer __new_start = this->_M_end_of_storage.allocate(__len);
  109.       pointer __new_finish = __new_start;
  110.       _STLP_TRY {
  111.         __new_finish = uninitialized_copy(this->_M_start, this->_M_finish, __new_start);
  112.         __new_finish = uninitialized_copy(__first, __last, __new_finish);
  113.         _M_construct_null(__new_finish);
  114.       }
  115.       _STLP_UNWIND((_Destroy(__new_start,__new_finish),
  116.                     this->_M_end_of_storage.deallocate(__new_start,__len)));
  117.       _Destroy(this->_M_start, this->_M_finish + 1);
  118.       this->_M_deallocate_block();
  119.       this->_M_start = __new_start;
  120.       this->_M_finish = __new_finish;
  121.       this->_M_end_of_storage._M_data = __new_start + __len; 
  122.     }
  123.     else {
  124.       const _CharT* __f1 = __first;
  125.       ++__f1;
  126.       uninitialized_copy(__f1, __last, this->_M_finish + 1);
  127.       _STLP_TRY {
  128.         _M_construct_null(this->_M_finish + __n);
  129.       }
  130.       _STLP_UNWIND(_Destroy(this->_M_finish + 1, this->_M_finish + __n));
  131.       _Traits::assign(*end(), *__first);
  132.       this->_M_finish += __n;
  133.     }
  134.   }
  135.   return *this;  
  136. }
  137.  
  138. #endif /* _STLP_MEMBER_TEMPLATES */
  139.  
  140. template <class _CharT, class _Traits, class _Alloc> 
  141. basic_string<_CharT,_Traits,_Alloc>& 
  142. basic_string<_CharT,_Traits,_Alloc>::assign(size_type __n, _CharT __c) {
  143.   if (__n <= size()) {
  144.     _Traits::assign(this->_M_start, __n, __c);
  145.     erase(begin() + __n, end());
  146.   }
  147.   else {
  148.     _Traits::assign(this->_M_start, size(), __c);
  149.     append(__n - size(), __c);
  150.   }
  151.   return *this;
  152. }
  153.  
  154. template <class _CharT, class _Traits, class _Alloc> _CharT* 
  155. basic_string<_CharT,_Traits,_Alloc> ::_M_insert_aux(_CharT* __p,
  156.                   _CharT __c)
  157. {
  158.   pointer __new_pos = __p;
  159.   if (this->_M_finish + 1 < this->_M_end_of_storage._M_data) {
  160.     _M_construct_null(this->_M_finish + 1);
  161.     _Traits::move(__p + 1, __p, this->_M_finish - __p);
  162.     _Traits::assign(*__p, __c);
  163.     ++this->_M_finish;
  164.   }
  165.   else {
  166.     const size_type __old_len = size();
  167.     const size_type __len = __old_len +
  168.                             (max)(__old_len, __STATIC_CAST(size_type,1)) + 1;
  169.     pointer __new_start = this->_M_end_of_storage.allocate(__len);
  170.     pointer __new_finish = __new_start;
  171.     _STLP_TRY {
  172.       __new_pos = uninitialized_copy(this->_M_start, __p, __new_start);
  173.       _Construct(__new_pos, __c);
  174.       __new_finish = __new_pos + 1;
  175.       __new_finish = uninitialized_copy(__p, this->_M_finish, __new_finish);
  176.       _M_construct_null(__new_finish);
  177.     }
  178.     _STLP_UNWIND((_Destroy(__new_start,__new_finish), 
  179.                   this->_M_end_of_storage.deallocate(__new_start,__len)));
  180.     _Destroy(this->_M_start, this->_M_finish + 1);
  181.     this->_M_deallocate_block();
  182.     this->_M_start = __new_start;
  183.     this->_M_finish = __new_finish;
  184.     this->_M_end_of_storage._M_data = __new_start + __len;
  185.   }
  186.   return __new_pos;
  187. }
  188.  
  189. template <class _CharT, class _Traits, class _Alloc> void basic_string<_CharT,_Traits,_Alloc>::insert(iterator __position,
  190.            size_t __n, _CharT __c)
  191. {
  192.   if (__n != 0) {
  193.     if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n + 1) {
  194.       const size_type __elems_after = this->_M_finish - __position;
  195.       pointer __old_finish = this->_M_finish;
  196.       if (__elems_after >= __n) {
  197.         uninitialized_copy((this->_M_finish - __n) + 1, this->_M_finish + 1,
  198.                            this->_M_finish + 1);
  199.         this->_M_finish += __n;
  200.         _Traits::move(__position + __n,
  201.                       __position, (__elems_after - __n) + 1);
  202.         _Traits::assign(__position, __n, __c);
  203.       }
  204.       else {
  205.         uninitialized_fill_n(this->_M_finish + 1, __n - __elems_after - 1, __c);
  206.         this->_M_finish += __n - __elems_after;
  207.         _STLP_TRY {
  208.           uninitialized_copy(__position, __old_finish + 1, this->_M_finish);
  209.           this->_M_finish += __elems_after;
  210.         }
  211.         _STLP_UNWIND((_Destroy(__old_finish + 1, this->_M_finish), 
  212.                       this->_M_finish = __old_finish));
  213.         _Traits::assign(__position, __elems_after + 1, __c);
  214.       }
  215.     }
  216.     else {
  217.       const size_type __old_size = size();        
  218.       const size_type __len = __old_size + (max)(__old_size, __n) + 1;
  219.       pointer __new_start = this->_M_end_of_storage.allocate(__len);
  220.       pointer __new_finish = __new_start;
  221.       _STLP_TRY {
  222.         __new_finish = uninitialized_copy(this->_M_start, __position, __new_start);
  223.         __new_finish = uninitialized_fill_n(__new_finish, __n, __c);
  224.         __new_finish = uninitialized_copy(__position, this->_M_finish,
  225.                                           __new_finish);
  226.         _M_construct_null(__new_finish);
  227.       }
  228.       _STLP_UNWIND((_Destroy(__new_start,__new_finish),
  229.                     this->_M_end_of_storage.deallocate(__new_start,__len)));
  230.       _Destroy(this->_M_start, this->_M_finish + 1);
  231.       this->_M_deallocate_block();
  232.       this->_M_start = __new_start;
  233.       this->_M_finish = __new_finish;
  234.       this->_M_end_of_storage._M_data = __new_start + __len;    
  235.     }
  236.   }
  237. }
  238.  
  239. #ifndef _STLP_MEMBER_TEMPLATES
  240.  
  241. template <class _CharT, class _Traits, class _Alloc> void 
  242. basic_string<_CharT,_Traits,_Alloc>::insert(iterator __position,
  243.                                             const _CharT* __first, 
  244.                                             const _CharT* __last)
  245. {
  246.   if (__first != __last) {
  247.     const ptrdiff_t __n = __last - __first;
  248.     if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {
  249.       const ptrdiff_t __elems_after = this->_M_finish - __position;
  250.       pointer __old_finish = this->_M_finish;
  251.       if (__elems_after >= __n) {
  252.         uninitialized_copy((this->_M_finish - __n) + 1, this->_M_finish + 1,
  253.                            this->_M_finish + 1);
  254.         this->_M_finish += __n;
  255.         _Traits::move(__position + __n,
  256.                       __position, (__elems_after - __n) + 1);
  257.         _M_copy(__first, __last, __position);
  258.       }
  259.       else {
  260.         const _CharT* __mid = __first;
  261.         advance(__mid, __elems_after + 1);
  262.         uninitialized_copy(__mid, __last, this->_M_finish + 1);
  263.         this->_M_finish += __n - __elems_after;
  264.         _STLP_TRY {
  265.           uninitialized_copy(__position, __old_finish + 1, this->_M_finish);
  266.           this->_M_finish += __elems_after;
  267.         }
  268.         _STLP_UNWIND((_Destroy(__old_finish + 1, this->_M_finish), 
  269.                       this->_M_finish = __old_finish));
  270.         _M_copy(__first, __mid, __position);
  271.       }
  272.     }
  273.     else {
  274.       size_type __old_size = size();        
  275.       size_type __len
  276.         = __old_size + (max)(__old_size, __STATIC_CAST(const size_type,__n)) + 1;
  277.       pointer __new_start = this->_M_end_of_storage.allocate(__len);
  278.       pointer __new_finish = __new_start;
  279.       _STLP_TRY {
  280.         __new_finish = uninitialized_copy(this->_M_start, __position, __new_start);
  281.         __new_finish = uninitialized_copy(__first, __last, __new_finish);
  282.         __new_finish
  283.           = uninitialized_copy(__position, this->_M_finish, __new_finish);
  284.         _M_construct_null(__new_finish);
  285.       }
  286.       _STLP_UNWIND((_Destroy(__new_start,__new_finish),
  287.                     this->_M_end_of_storage.deallocate(__new_start,__len)));
  288.       _Destroy(this->_M_start, this->_M_finish + 1);
  289.       this->_M_deallocate_block();
  290.       this->_M_start = __new_start;
  291.       this->_M_finish = __new_finish;
  292.       this->_M_end_of_storage._M_data = __new_start + __len; 
  293.     }
  294.   }
  295. }
  296.  
  297. #endif /* _STLP_MEMBER_TEMPLATES */
  298.  
  299. template <class _CharT, class _Traits, class _Alloc> basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc> ::replace(iterator __first, iterator __last, size_type __n, _CharT __c)
  300. {
  301.   size_type __len = (size_type)(__last - __first);
  302.   
  303.   if (__len >= __n) {
  304.     _Traits::assign(__first, __n, __c);
  305.     erase(__first + __n, __last);
  306.   }
  307.   else {
  308.     _Traits::assign(__first, __len, __c);
  309.     insert(__last, __n - __len, __c);
  310.   }
  311.   return *this;
  312. }
  313.  
  314. #ifndef _STLP_MEMBER_TEMPLATES
  315.  
  316.  
  317. template <class _CharT, class _Traits, class _Alloc> basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc> ::replace(iterator __first, iterator __last,
  318.             const _CharT* __f, const _CharT* __l)
  319. {
  320.   const ptrdiff_t         __n = __l - __f;
  321.   const difference_type __len = __last - __first;
  322.   if (__len >= __n) {
  323.     _M_copy(__f, __l, __first);
  324.     erase(__first + __n, __last);
  325.   }
  326.   else {
  327.     const _CharT* __m = __f + __len;
  328.     _M_copy(__f, __m, __first);
  329.     insert(__last, __m, __l);
  330.   }
  331.   return *this;
  332. }
  333.  
  334. #endif /* _STLP_MEMBER_TEMPLATES */
  335.  
  336. template <class _CharT, class _Traits, class _Alloc> __size_type__
  337. basic_string<_CharT,_Traits,_Alloc> ::find(const _CharT* __s, size_type __pos, size_type __n) const 
  338. {
  339.   if (__pos + __n > size())
  340.     return npos;
  341.   else {
  342.     const const_pointer __result =
  343.       _STLP_STD::search((const _CharT*)this->_M_start + __pos, (const _CharT*)this->_M_finish, 
  344.             __s, __s + __n, _Eq_traits<_Traits>());
  345.     return __result != this->_M_finish ? __result - this->_M_start : npos;
  346.   }
  347. }
  348.  
  349. template <class _CharT, class _Traits, class _Alloc> __size_type__
  350. basic_string<_CharT,_Traits,_Alloc> ::find(_CharT __c, size_type __pos) const 
  351. {
  352.   if (__pos >= size())
  353.     return npos;
  354.   else {
  355.     const const_pointer __result =
  356.       _STLP_STD::find_if((const _CharT*)this->_M_start + __pos, (const _CharT*)this->_M_finish,
  357.              _Eq_char_bound<_Traits>(__c));
  358.     return __result != this->_M_finish ? __result - this->_M_start : npos;
  359.   }
  360. }    
  361.  
  362. template <class _CharT, class _Traits, class _Alloc> __size_type__
  363. basic_string<_CharT,_Traits,_Alloc> ::rfind(const _CharT* __s, size_type __pos, size_type __n) const 
  364. {
  365.   const size_t __len = size();
  366.  
  367.   if (__n > __len)
  368.     return npos;
  369.   else if (__n == 0)
  370.     return (min) (__len, __pos);
  371.   else {
  372.     const_pointer __last = this->_M_start + (min) (__len - __n, __pos) + __n;
  373.     const_pointer __result = _STLP_STD::find_end((const_pointer)this->_M_start, __last,
  374.                          __s, __s + __n,
  375.                          _Eq_traits<_Traits>());
  376.     return __result != __last ? __result - this->_M_start : npos;
  377.   }
  378. }
  379.  
  380. template <class _CharT, class _Traits, class _Alloc> __size_type__
  381. basic_string<_CharT,_Traits,_Alloc> ::rfind(_CharT __c, size_type __pos) const 
  382. {
  383.   const size_type __len = size();
  384.  
  385.   if (__len < 1)
  386.     return npos;
  387.   else {
  388.     const const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
  389.     const_reverse_iterator __rresult =
  390.       _STLP_STD::find_if(const_reverse_iterator(__last), rend(),
  391.               _Eq_char_bound<_Traits>(__c));
  392.     return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
  393.   }
  394. }
  395.  
  396. template <class _CharT, class _Traits, class _Alloc> __size_type__
  397. basic_string<_CharT,_Traits,_Alloc> ::find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
  398. {
  399.   if (__pos >= size())
  400.     return npos;
  401.   else {
  402.     const_iterator __result = __find_first_of(begin() + __pos, end(),
  403.                                               __s, __s + __n,
  404.                                               _Eq_traits<_Traits>());
  405.     return __result != end() ? __result - begin() : npos;
  406.   }
  407. }
  408.  
  409.  
  410. template <class _CharT, class _Traits, class _Alloc> __size_type__
  411. basic_string<_CharT,_Traits,_Alloc> ::find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
  412. {
  413.   const size_type __len = size();
  414.  
  415.   if (__len < 1)
  416.     return npos;
  417.   else {
  418.     const const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
  419.     const const_reverse_iterator __rresult =
  420.       __find_first_of(const_reverse_iterator(__last), rend(),
  421.                       __s, __s + __n,
  422.                       _Eq_traits<_Traits>());
  423.     return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
  424.   }
  425. }
  426.  
  427.  
  428. template <class _CharT, class _Traits, class _Alloc> __size_type__
  429. basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
  430. {
  431.   typedef typename _Traits::char_type _CharType;
  432.   if (__pos > size())
  433.     return npos;
  434.   else {
  435.     const_pointer __result = _STLP_STD::find_if((const _CharT*)this->_M_start + __pos, 
  436.                       (const _CharT*)this->_M_finish,
  437.                                 _Not_within_traits<_Traits>((const _CharType*)__s, 
  438.                                 (const _CharType*)__s + __n));
  439.     return __result != this->_M_finish ? __result - this->_M_start : npos;
  440.   }
  441. }
  442.  
  443. template <class _CharT, class _Traits, class _Alloc> __size_type__
  444. basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(_CharT __c, size_type __pos) const
  445. {
  446.   if (__pos > size())
  447.     return npos;
  448.   else {
  449.     const_pointer __result = _STLP_STD::find_if((const _CharT*)this->_M_start + __pos, (const _CharT*)this->_M_finish,
  450.                         _Neq_char_bound<_Traits>(__c));
  451.     return __result != this->_M_finish ? __result - this->_M_start : npos;
  452.   }
  453. }    
  454.  
  455. template <class _CharT, class _Traits, class _Alloc> __size_type__
  456. basic_string<_CharT,_Traits,_Alloc> ::find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const 
  457. {
  458.   typedef typename _Traits::char_type _CharType;
  459.   const size_type __len = size();
  460.  
  461.   if (__len < 1)
  462.     return npos;
  463.   else {
  464.     const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
  465.     const_reverse_iterator __rlast = const_reverse_iterator(__last);
  466.     const_reverse_iterator __rresult =
  467.       _STLP_STD::find_if(__rlast, rend(),
  468.              _Not_within_traits<_Traits>((const _CharType*)__s, 
  469.                              (const _CharType*)__s + __n));
  470.     return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
  471.   }
  472. }
  473.  
  474. template <class _CharT, class _Traits, class _Alloc> __size_type__
  475. basic_string<_CharT, _Traits, _Alloc> ::find_last_not_of(_CharT __c, size_type __pos) const 
  476. {
  477.   const size_type __len = size();
  478.  
  479.   if (__len < 1)
  480.     return npos;
  481.   else {
  482.     const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
  483.     const_reverse_iterator __rlast = const_reverse_iterator(__last);
  484.     const_reverse_iterator __rresult =
  485.       _STLP_STD::find_if(__rlast, rend(),
  486.              _Neq_char_bound<_Traits>(__c));
  487.     return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
  488.   }
  489. }
  490.  
  491. template <class _CharT, class _Traits, class _Alloc> void _STLP_CALL _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s,
  492.                     _CharT* __buf,
  493.                     size_t __n)
  494. {
  495.   if (__n > 0) {
  496.     __n = (min) (__n - 1, __s.size());
  497.     _STLP_STD::copy(__s.begin(), __s.begin() + __n, __buf);
  498.     __buf[__n] = _CharT();
  499.   }
  500. }
  501. _STLP_END_NAMESPACE
  502.  
  503. // _string_fwd has to see clean basic_string
  504. # undef basic_string
  505.  
  506. # if !defined (_STLP_LINK_TIME_INSTANTIATION)
  507. #  include <stl/_string_fwd.c> 
  508. # endif
  509.  
  510. # ifdef _STLP_DEBUG
  511. #  define basic_string _Nondebug_string
  512. # endif
  513.  
  514. # include <stl/_range_errors.h>  
  515. _STLP_BEGIN_NAMESPACE
  516.  
  517. // _String_base methods
  518. template <class _Tp, class _Alloc> void _String_base<_Tp,_Alloc>::_M_throw_length_error() const {
  519.     __stl_throw_length_error("basic_string");
  520. }
  521.  
  522. template <class _Tp, class _Alloc> void _String_base<_Tp, _Alloc>::_M_throw_out_of_range() const {
  523.     __stl_throw_out_of_range("basic_string");
  524. }
  525.  
  526. template <class _Tp, class _Alloc> void _String_base<_Tp, _Alloc>::_M_allocate_block(size_t __n) {  
  527.   if ((__n <= (max_size()+1)) && (__n>0)){ 
  528.     _M_start  = _M_end_of_storage.allocate(__n); 
  529.     _M_finish = _M_start; 
  530.     _M_end_of_storage._M_data = _M_start + __n; 
  531.   } 
  532.     else 
  533.       _M_throw_length_error(); 
  534.  
  535. template <class _CharT, class _Traits, class _Alloc> basic_string<_CharT, _Traits, _Alloc>::basic_string()
  536.   : _String_base<_CharT,_Alloc>(allocator_type()) {  
  537.   this->_M_start = this->_M_end_of_storage.allocate(8); 
  538.   this->_M_finish = this->_M_start; 
  539.   this->_M_end_of_storage._M_data = this->_M_start + 8; 
  540.   _M_terminate_string();  
  541.  
  542.  
  543. template <class _CharT, class _Traits, class _Alloc> basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT* __s, 
  544.                             const allocator_type& __a) 
  545.   : _String_base<_CharT,_Alloc>(__a)  
  546.   _STLP_FIX_LITERAL_BUG(__s) 
  547.     _M_range_initialize(__s, __s + traits_type::length(__s));  
  548.  
  549.  
  550. template <class _CharT, class _Traits, class _Alloc> basic_string<_CharT, _Traits, _Alloc>::basic_string(const basic_string<_CharT, _Traits, _Alloc> & __s)  
  551.   : _String_base<_CharT,_Alloc>(__s.get_allocator())  
  552. {  
  553.   _M_range_initialize(__s._M_start, __s._M_finish);  
  554.   
  555. # if defined ( __SUNPRO_CC) && ! defined(_STLP_STATIC_CONST_INIT_BUG)
  556. template <class _CharT, class _Traits, class _Alloc> const size_t basic_string<_CharT, _Traits, _Alloc>::npos;
  557. # endif
  558.  
  559. _STLP_END_NAMESPACE
  560.  
  561. # undef basic_string
  562. # undef __size_type__
  563. # undef size_type
  564. # undef iterator
  565. # endif /* NATIVE */
  566.  
  567. #endif /*  _STLP_STRING_C */
  568.  
  569. // Local Variables:
  570. // mode:C++
  571. // End:
  572.