home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Include / STRING.STL < prev    next >
Encoding:
Text File  |  1999-01-26  |  71.8 KB  |  1,906 lines

  1. #ifndef __STRING_STL
  2. #define __STRING_STL
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. /***************************************************************************
  6.  *
  7.  * string - Declarations for the Standard Library string classes
  8.  *
  9.  ***************************************************************************
  10.  *
  11.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  12.  * ALL RIGHTS RESERVED
  13.  *
  14.  * The software and information contained herein are proprietary to, and
  15.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  16.  * intends to preserve as trade secrets such software and information.
  17.  * This software is furnished pursuant to a written license agreement and
  18.  * may be used, copied, transmitted, and stored only in accordance with
  19.  * the terms of such license and with the inclusion of the above copyright
  20.  * notice.  This software and information or any other copies thereof may
  21.  * not be provided or otherwise made available to any other person.
  22.  *
  23.  * Notwithstanding any other lease or license that may pertain to, or
  24.  * accompany the delivery of, this computer software and information, the
  25.  * rights of the Government regarding its use, reproduction and disclosure
  26.  * are as set forth in Section 52.227-19 of the FARS Computer
  27.  * Software-Restricted Rights clause.
  28.  * 
  29.  * Use, duplication, or disclosure by the Government is subject to
  30.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  31.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  32.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  33.  * P.O. Box 2328, Corvallis, Oregon 97339.
  34.  *
  35.  * This computer software and information is distributed with "restricted
  36.  * rights."  Use, duplication or disclosure is subject to restrictions as
  37.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  38.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  39.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  40.  * then the "Alternate III" clause applies.
  41.  *
  42.  **************************************************************************/
  43.  
  44. #ifndef __STD_STRING
  45. #define __STD_STRING
  46.  
  47. #include <stdcomp.h>
  48. #include <rw/rwstderr.h>
  49.  
  50. #ifndef _RWSTD_NO_NEW_HEADER
  51. #include <cstring>
  52. #include <cctype>
  53. #else
  54. #include <string.h>
  55. #include <ctype.h>
  56. #endif
  57.  
  58. #ifndef _RWSTD_NO_WIDE_CHAR
  59. #ifndef _RWSTD_NO_NEW_HEADER
  60. #include <cwchar>
  61. #include <cwctype>
  62. #else
  63. #ifndef _RWSTD_NO_WCHAR_H
  64. #include <wchar.h>
  65. #endif
  66. #ifndef _RWSTD_NO_WCTYPE_H
  67. # include <wctype.h>
  68. #endif
  69. #endif
  70. #endif
  71.  
  72. #ifndef _RW_STD_IOSTREAM
  73. #include <iostream.h>
  74. #endif
  75.  
  76. #include <rw/string_ref>
  77.  
  78. #ifndef _RWSTD_NO_NAMESPACE
  79. namespace __rwstd {
  80. #endif
  81. //
  82. // Global error message declarations
  83. //
  84. #ifdef _RWSTD_LOCALIZED_ERRORS
  85.   extern const unsigned int _RWSTDExport __rwse_InvalidSizeParam;
  86.   extern const unsigned int _RWSTDExport __rwse_PosBeyondEndOfString;
  87.   extern const unsigned int _RWSTDExport __rwse_ResultLenInvalid;
  88.   extern const unsigned int _RWSTDExport __rwse_StringIndexOutOfRange;
  89.   extern const unsigned int _RWSTDExport __rwse_UnexpectedNullPtr;
  90. #else
  91.   extern const char _RWSTDExportFunc(*) __rwse_InvalidSizeParam;
  92.   extern const char _RWSTDExportFunc(*) __rwse_PosBeyondEndOfString;
  93.   extern const char _RWSTDExportFunc(*) __rwse_ResultLenInvalid;
  94.   extern const char _RWSTDExportFunc(*) __rwse_StringIndexOutOfRange;
  95.   extern const char _RWSTDExportFunc(*) __rwse_UnexpectedNullPtr;
  96. #endif
  97. #ifndef _RWSTD_NO_NAMESPACE
  98. } namespace std {
  99. #endif
  100.  
  101. #ifdef _RWSTD_NO_STATIC_DEF3
  102.   extern unsigned long _RWSTDExport __nullref[];
  103.   extern bool _RWSTDExport __nullref_initialized;
  104. #endif
  105.  
  106.   template <class charT, class traits , class Allocator >
  107.   class _RWSTDExportTemplate basic_string
  108.   {
  109.   public:
  110.  
  111.     //
  112.     //  Implementation types (see rw/string_ref)
  113.     //
  114.     // __string_ref_type is the type of the string reference that 
  115.     // holds the data for a basic_string. Defining _RWSTD_NO_STRING_REF_CONT
  116.     // gets you a basic_string that does not use reference counting
  117.     // at all.
  118.     //
  119. #ifndef _RWSTD_NO_STRING_REF_COUNT
  120.     typedef __RWSTD::__string_ref<charT,traits,Allocator> __string_ref_type;
  121. #else
  122.     typedef __RWSTD::__string_noref<charT,traits,Allocator> __string_ref_type;
  123. #endif
  124.     //
  125.     // __rep_type is the base class of __string_ref_type.  This type 
  126.     // defines the representation of the reference class.
  127.     //
  128.     typedef _TYPENAME __string_ref_type::__string_ref_rep_type __rep_type;
  129.     //
  130.     // __null_ref_type is the type of the null reference.  Every empty 
  131.     // string holds a reference to the same null reference object in order
  132.     // to keep the size of an empty string at sizeof(char*) -- assuming
  133.     // your compiler can handle the empty base optimization.
  134.     //
  135.     typedef __RWSTD::__null_string_ref_rep<charT,traits,Allocator,__rep_type>  __null_ref_type;
  136.  
  137.     //
  138.     // types
  139.     //
  140.     typedef traits                               traits_type;
  141.     typedef _TYPENAME traits::char_type          value_type;
  142.     typedef Allocator                            allocator_type;
  143.  
  144.   private:
  145.  
  146. #ifdef _RWSTD_ALLOCATOR
  147.     typedef Allocator  __value_alloc_type;
  148.     typedef _TYPENAME Allocator::template rebind<__string_ref_type>::other  __ref_alloc_type;
  149. #else
  150.     typedef allocator_interface<Allocator,charT>       __value_alloc_type;
  151.     typedef allocator_interface<Allocator,__string_ref_type>  __ref_alloc_type;
  152. #endif
  153.  
  154.   
  155.   public:
  156.  
  157. #ifndef _RWSTD_NO_COMPLICATED_TYPEDEF
  158.     typedef _TYPENAME _RWSTD_ALLOC_SIZE_TYPE              size_type;
  159.     typedef _TYPENAME _RWSTD_ALLOC_DIFF_TYPE              difference_type;
  160.     typedef _TYPENAME __value_alloc_type::reference       reference;
  161.     typedef _TYPENAME __value_alloc_type::const_reference const_reference;
  162.     typedef _TYPENAME __value_alloc_type::pointer         pointer;
  163.     typedef _TYPENAME __value_alloc_type::const_pointer   const_pointer;
  164.     typedef _TYPENAME __value_alloc_type::pointer         iterator;
  165.     typedef _TYPENAME __value_alloc_type::const_pointer   const_iterator;
  166. #else
  167.     typedef size_t                            size_type;
  168.     typedef ptrdiff_t                         difference_type;
  169.     typedef charT&                            reference;
  170.     typedef const charT&                      const_reference;
  171.     typedef charT*                            pointer;
  172.     typedef const charT*                      const_pointer;
  173.     typedef charT*                            iterator;
  174.     typedef const charT*                      const_iterator;
  175. #endif  //_RWSTD_NO_COMPLICATED_TYPEDEF
  176.  
  177. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC 
  178.     typedef _RW_STD::reverse_iterator<const_iterator> const_reverse_iterator;
  179.     typedef _RW_STD::reverse_iterator<iterator>  reverse_iterator;
  180. #else
  181.     typedef _RW_STD::reverse_iterator<const_iterator, 
  182.       random_access_iterator_tag, value_type, 
  183.       const_reference, const_pointer, difference_type>
  184.       const_reverse_iterator;
  185.     typedef _RW_STD::reverse_iterator<iterator, 
  186.       random_access_iterator_tag, value_type,
  187.       reference, pointer, difference_type>
  188.       reverse_iterator;
  189. #endif
  190.  
  191. #ifdef _RWSTD_MSC22_STATIC_INIT_BUG
  192. #define npos (size_type)-1
  193. #else
  194.     static const size_type npos;
  195. #endif
  196.  
  197.     inline _EXPLICIT basic_string (const Allocator& _RWSTD_DEFAULT_ARG(Allocator()));
  198.  
  199. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS 
  200.     inline basic_string (void);
  201. #endif
  202.  
  203.     inline basic_string (const basic_string<charT, traits, Allocator>&);
  204.     basic_string (const basic_string<charT, traits, Allocator>&, 
  205.                   size_type, size_type _RWSTD_DEFAULT_ARG(npos), 
  206.                   const Allocator&  _RWSTD_DEFAULT_ARG(Allocator()));
  207.     basic_string (const charT*, size_type, 
  208.                   const Allocator& _RWSTD_DEFAULT_ARG(Allocator()));
  209.     basic_string (const charT*, const Allocator& _RWSTD_DEFAULT_ARG(Allocator()));
  210.  
  211. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  212.     basic_string (const charT*, size_type); 
  213.     basic_string (const charT*); 
  214.     basic_string (size_type n, charT c) : __data_((charT*)0,Allocator())
  215.     { __init_n(n,c); }
  216. #endif
  217.  
  218. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  219.     template <class InputIterator>
  220.     basic_string (InputIterator, InputIterator, const Allocator& _RWSTD_DEFAULT_ARG(Allocator()));
  221.     basic_string (int n, charT c, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  222.       : __data_((charT*)0,alloc)
  223.     { __init_n(n,c); }
  224.     basic_string (unsigned int n, charT c, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  225.       : __data_((charT*)0,alloc)
  226.     { __init_n(n,c); }
  227.     basic_string (long n, charT c, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  228.       : __data_((charT*)0,alloc)
  229.     { __init_n(n,c); }
  230.     basic_string (unsigned long n, charT c, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  231.       : __data_((charT*)0,alloc)
  232.     { __init_n(n,c); }
  233.     basic_string (short n, charT c, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  234.       : __data_((charT*)0,alloc)
  235.     { __init_n(n,c); }
  236.     basic_string (unsigned short n, charT c, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  237.       : __data_((charT*)0,alloc)
  238.     { __init_n(n,c); }
  239.     basic_string (char n, charT c, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  240.       : __data_((charT*)0,alloc)
  241.     { __init_n(n,c); }
  242.     basic_string (unsigned char n, charT c, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  243.       : __data_((charT*)0,alloc)
  244.     { __init_n(n,c); }
  245. #ifndef _RWSTD_NO_OVERLOAD_WCHAR
  246.     basic_string (wchar_t n, charT c, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  247.       : __data_((charT*)0,alloc)
  248.     { __init_n(n,c); }
  249. #endif
  250. #ifndef _RWSTD_NO_BOOL
  251.     basic_string (bool n, charT c, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  252.       : __data_((charT*)0,alloc)
  253.     { __init_n(n,c); }
  254. #endif
  255. #else
  256.     basic_string (size_type n, charT c, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  257.       : __data_((charT*)0,alloc)
  258.     { __init_n(n,c); }
  259. #endif // _RWSTD_NO_MEMBER_TEMPLATES
  260.  
  261.     basic_string (const charT*, const charT*, const Allocator& _RWSTD_DEFAULT_ARG(Allocator()));
  262. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  263.     basic_string (const charT*, const charT*);
  264. #endif
  265.  
  266.     ~basic_string ()
  267.     {
  268.       __unLink();
  269.     }
  270.  
  271.     basic_string<charT, traits, Allocator>& operator= (const basic_string<charT, traits, Allocator>&);
  272.     basic_string<charT, traits, Allocator>& operator= (const charT*);
  273.     inline basic_string<charT, traits, Allocator>& operator= (charT);
  274.  
  275.     //
  276.     // iterators
  277.     //
  278.     iterator begin () 
  279.     { __cow(); __pref()->__setRefCount(0); return __data_.data(); }
  280.     const_iterator begin () const  
  281.     { return __data_.data(); }
  282.     iterator end () 
  283.     { __cow(); __pref()->__setRefCount(0); return __data_.data()+length(); }
  284.     const_iterator end   () const  
  285.     { return __data_.data()+length(); }
  286.  
  287.     reverse_iterator rbegin () 
  288.     { reverse_iterator tmp(end()); return tmp; }
  289.     const_reverse_iterator rbegin () const 
  290.     { const_reverse_iterator tmp(end()); return tmp; }
  291.     reverse_iterator rend ()
  292.     { reverse_iterator tmp(begin()); return tmp; }
  293.     const_reverse_iterator rend () const 
  294.     { const_reverse_iterator tmp(begin()); return tmp; }
  295.  
  296.     //
  297.     // capacity
  298.     //
  299.     size_type size () const   { return length(); }
  300.     inline size_type length () const;
  301.     size_type max_size () const
  302.     {
  303.       return npos - sizeof(__rep_type)-2;
  304.     }
  305.     inline void resize (size_type, charT);
  306.     void resize (size_type n)
  307.     {
  308.       resize(n,__eos()); 
  309.     }
  310.     inline size_type capacity () const;
  311.     inline void reserve (size_type=0);
  312.     void clear () { erase(); }
  313.     bool empty () const  { return length() == 0; }
  314.  
  315.     //
  316.     // element access
  317.     //
  318.     inline const_reference operator[] (size_type) const;
  319.     inline reference       operator[] (size_type);
  320.     inline const_reference at (size_type) const;
  321.     inline reference       at (size_type);
  322.  
  323.     //
  324.     // modifiers
  325.     //
  326.     inline basic_string<charT, traits, Allocator>& operator+= (const basic_string<charT, traits, Allocator>&);
  327.     inline basic_string<charT, traits, Allocator>& operator+= (const charT*);
  328.     inline basic_string<charT, traits, Allocator>& operator+= (charT);
  329.  
  330.     basic_string<charT, traits, Allocator>& append (
  331.         const  basic_string<charT, traits, Allocator>&);
  332.     basic_string<charT, traits, Allocator>& append (
  333.         const basic_string<charT, traits, Allocator>&,
  334.         size_type, 
  335.         size_type);
  336.     inline basic_string<charT, traits, Allocator>& append (const charT*, size_type);
  337.     inline basic_string<charT, traits, Allocator>& append (const charT*);
  338.  
  339. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  340.     template<class InputIterator>
  341.     inline basic_string<charT, traits, Allocator>& append (InputIterator,
  342.                                                     InputIterator);
  343.     basic_string<charT, traits, Allocator>& append (int n, charT c)
  344.     { return replace(length(),0,n,c); }
  345.     basic_string<charT, traits, Allocator>& append (unsigned int n, charT c)
  346.     { return replace(length(),0,n,c); }
  347.     basic_string<charT, traits, Allocator>& append (long n, charT c)
  348.     { return replace(length(),0,n,c); }
  349.     basic_string<charT, traits, Allocator>& append (unsigned long n, charT c)
  350.     { return replace(length(),0,n,c); }
  351.     basic_string<charT, traits, Allocator>& append (short n, charT c)
  352.     { return replace(length(),0,n,c); }
  353.     basic_string<charT, traits, Allocator>& append (unsigned short n, charT c)
  354.     { return replace(length(),0,n,c); }
  355.     basic_string<charT, traits, Allocator>& append (char n, charT c)
  356.     { return replace(length(),0,n,c); }
  357.     basic_string<charT, traits, Allocator>& append (unsigned char n, charT c)
  358.     { return replace(length(),0,n,c); }
  359. #ifndef _RWSTD_NO_OVERLOAD_WCHAR
  360.     basic_string<charT, traits, Allocator>& append (wchar_t n, charT c)
  361.     { return replace(length(),0,n,c); }
  362. #endif
  363. #ifndef _RWSTD_NO_BOOL
  364.     basic_string<charT, traits, Allocator>& append (bool n, charT c)
  365.     { return replace(length(),0,n,c); }
  366. #endif
  367. #else
  368.     inline basic_string<charT, traits, Allocator>& append (const charT*,
  369.                                                     const charT*);
  370.     inline basic_string<charT, traits, Allocator>& append (size_type, charT);
  371. #endif // _RWSTD_NO_MEMBER_TEMPLATES
  372.  
  373.     inline void push_back(const charT);
  374.  
  375.     basic_string<charT, traits, Allocator>& assign (
  376.         const basic_string<charT, traits, Allocator>&);
  377.     basic_string<charT, traits, Allocator>& assign (
  378.         const basic_string<charT, traits, Allocator>&,
  379.         size_type, 
  380.         size_type);
  381.     inline basic_string<charT, traits, Allocator>& assign (const charT*, size_type);
  382.     inline basic_string<charT, traits, Allocator>& assign (const charT*);
  383. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  384.     template<class InputIterator>
  385.     inline basic_string<charT, traits, Allocator>& assign (InputIterator,
  386.                                                     InputIterator);
  387.     basic_string<charT, traits, Allocator>& assign (int n, charT c)
  388.     { return replace(0,length(),n,c); }
  389.     basic_string<charT, traits, Allocator>& assign (unsigned int n, charT c)
  390.     { return replace(0,length(),n,c); }
  391.     basic_string<charT, traits, Allocator>& assign (long n, charT c)
  392.     { return replace(0,length(),n,c); }
  393.     basic_string<charT, traits, Allocator>& assign (unsigned long n, charT c)
  394.     { return replace(0,length(),n,c); }
  395.     basic_string<charT, traits, Allocator>& assign (short n, charT c)
  396.     { return replace(0,length(),n,c); }
  397.     basic_string<charT, traits, Allocator>& assign (unsigned short n, charT c)
  398.     { return replace(0,length(),n,c); }
  399.     basic_string<charT, traits, Allocator>& assign (char n, charT c)
  400.     { return replace(0,length(),n,c); }
  401.     basic_string<charT, traits, Allocator>& assign (unsigned char n, charT c)
  402.     { return replace(0,length(),n,c); }
  403. #ifndef _RWSTD_NO_OVERLOAD_WCHAR
  404.     basic_string<charT, traits, Allocator>& assign (wchar_t n, charT c)
  405.     { return replace(0,length(),n,c); }
  406. #endif
  407. #ifndef _RWSTD_NO_BOOL
  408.     basic_string<charT, traits, Allocator>& assign (bool n, charT c)
  409.     { return replace(0,length(),n,c); }
  410. #endif
  411. #else
  412.     inline basic_string<charT, traits, Allocator>& assign (const charT*,
  413.                                                     const charT*);   
  414.     inline basic_string<charT, traits, Allocator>& assign (size_type, charT);
  415. #endif  // _RWSTD_NO_MEMBER_TEMPLATES
  416.   
  417.     basic_string<charT, traits, Allocator>& insert (size_type,
  418.                                                     const basic_string<charT, traits, Allocator>&);
  419.     basic_string<charT, traits, Allocator>& insert (
  420.         size_type,
  421.         const basic_string<charT, traits, Allocator>&,
  422.         size_type, 
  423.         size_type);
  424.     inline basic_string<charT, traits, Allocator>& insert (
  425.         size_type,
  426.         const charT*, 
  427.         size_type);
  428.     inline basic_string<charT, traits, Allocator>& insert (size_type, const charT*);
  429.     iterator insert (iterator pos, charT c)
  430.     { 
  431.       iterator tmp = __replace_aux(pos-begin(), 0, basic_string<charT, traits, Allocator>(1,c)); 
  432.       __pref()->__setRefCount(0);
  433.       return tmp;
  434.     }
  435.  
  436. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  437.     template<class InputIterator>
  438.     inline void insert (iterator, InputIterator, InputIterator);
  439.     void insert (iterator p, int n, charT c)
  440.     { replace(p-begin(),0,n,c); }
  441.     void insert (iterator p, unsigned int n, charT c)
  442.     { replace(p-begin(),0,n,c); }
  443.     void insert (iterator p, long n, charT c)
  444.     { replace(p-begin(),0,n,c); }
  445.     void insert (iterator p, unsigned long n, charT c)
  446.     { replace(p-begin(),0,n,c); }
  447.     void insert (iterator p, short n, charT c)
  448.     { replace(p-begin(),0,n,c); }
  449.     void insert (iterator p, unsigned short n, charT c)
  450.     { replace(p-begin(),0,n,c); }
  451.     void insert (iterator p, char n, charT c)
  452.     { replace(p-begin(),0,n,c); }
  453.     void insert (iterator p, unsigned char n, charT c)
  454.     { replace(p-begin(),0,n,c); }
  455.     basic_string<charT, traits, Allocator>& insert (size_type pos,int n,charT c)
  456.     { return replace(pos,0,n,c); }
  457.     basic_string<charT, traits, Allocator>& insert (size_type pos,unsigned int n,charT c)
  458.     { return replace(pos,0,n,c); }
  459.     basic_string<charT, traits, Allocator>& insert (size_type pos,long n,charT c)
  460.     { return replace(pos,0,n,c); }
  461.     basic_string<charT, traits, Allocator>& insert (size_type pos,unsigned long n,charT c)
  462.     { return replace(pos,0,n,c); }
  463.     basic_string<charT, traits, Allocator>& insert (size_type pos,short n,charT c)
  464.     { return replace(pos,0,n,c); }
  465.     basic_string<charT, traits, Allocator>& insert (size_type pos,unsigned short n,charT c)
  466.     { return replace(pos,0,n,c); }
  467.     basic_string<charT, traits, Allocator>& insert (size_type pos,char n,charT c)
  468.     { return replace(pos,0,n,c); }
  469.     basic_string<charT, traits, Allocator>& insert (size_type pos,unsigned char n,charT c)
  470.     { return replace(pos,0,n,c); }
  471. #ifndef _RWSTD_NO_OVERLOAD_WCHAR
  472.     void insert (iterator p, wchar_t n, charT c)
  473.     { replace(p-begin(),0,n,c); }
  474.     basic_string<charT, traits, Allocator>& insert (size_type pos,wchar_t n,charT c)
  475.     { return replace(pos,0,n,c); }
  476. #endif
  477. #ifndef _RWSTD_NO_BOOL
  478.     void insert (iterator p, bool n, charT c)
  479.     { replace(p-begin(),0,n,c);} 
  480.     basic_string<charT, traits, Allocator>& insert (size_type pos,bool n,charT c)
  481.     { return replace(pos,0,n,c); }
  482. #endif
  483.  
  484. #else
  485.     inline void insert (iterator, const charT*, const charT*);
  486.     inline basic_string<charT, traits, Allocator>& insert (size_type,size_type,charT);
  487.     inline void insert (iterator, size_type, charT);
  488. #endif  // _RWSTD_NO_MEMBER_TEMPLATES
  489.     
  490.     inline basic_string<charT, traits, Allocator>& erase (size_type = 0,
  491.                                                    size_type = npos);
  492.  
  493.     iterator erase (iterator it) 
  494.     { 
  495.       iterator ret = replace(it - begin(),1,NULL,0,0,0);
  496.       __pref()->__setRefCount(0);
  497.       return ret;
  498.     }
  499.     iterator erase (iterator first, iterator last) 
  500.     {  
  501.       iterator ret =  replace(first - begin(),last-first,NULL,0,0,0);
  502.       __pref()->__setRefCount(0);
  503.       return ret;
  504.     }
  505.   private:  
  506.     //
  507.     // Used for effiency
  508.     //
  509.     _TYPENAME 
  510.     basic_string<charT, traits, Allocator>::iterator replace (size_type, 
  511.                                                               size_type, 
  512.                                                               const charT*,
  513.                                                               size_type,
  514.                                                               size_type,
  515.                                                               size_type);
  516.  
  517.     _TYPENAME 
  518.     basic_string<charT, traits, Allocator>::iterator __replace_aux (
  519.         size_type, 
  520.         size_type,
  521.         const basic_string<charT, traits, Allocator>&,
  522.         size_type =0,
  523.         size_type =npos);
  524.  
  525. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  526.     template<class InputIterator>
  527.     basic_string<charT, traits, Allocator>& __replace_aux (
  528.         iterator first1, 
  529.         iterator last1,
  530.         InputIterator first2,
  531.         InputIterator last2);
  532. #endif
  533.  
  534.   public:
  535.     inline basic_string<charT, traits, Allocator>& replace (size_type, 
  536.                                                      size_type,
  537.                                                      const basic_string<charT, traits, Allocator>&);
  538.     inline basic_string<charT, traits, Allocator>& replace (size_type, 
  539.                                                      size_type,
  540.                                                      const basic_string<charT, traits, Allocator>&,
  541.                                                      size_type, 
  542.                                                      size_type);
  543.     inline basic_string<charT, traits, Allocator>& replace (size_type, 
  544.                                                      size_type, 
  545.                                                      const charT*, 
  546.                                                      size_type);
  547.     inline basic_string<charT, traits, Allocator>& replace (size_type,
  548.                                                      size_type, 
  549.                                                      const charT*);
  550.     basic_string<charT, traits, Allocator>& replace (size_type,
  551.                                                      size_type,
  552.                                                      size_type,
  553.                                                      charT);
  554.     inline basic_string<charT, traits, Allocator>& replace (iterator,
  555.                                                      iterator,
  556.                                                      const basic_string<charT, traits, Allocator>&);
  557.     inline basic_string<charT, traits, Allocator>& replace (iterator,
  558.                                                      iterator,
  559.                                                      const charT*,
  560.                                                      size_type);
  561.     inline basic_string<charT, traits, Allocator>& replace (iterator,
  562.                                                      iterator,
  563.                                                      const charT*);
  564.  
  565. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  566.     template<class InputIterator>
  567.     basic_string<charT, traits, Allocator>& replace (iterator, iterator, 
  568.                                                      InputIterator,
  569.                                                      InputIterator);
  570.     basic_string<charT, traits, Allocator>& replace (iterator first,
  571.                                                      iterator last,
  572.                                                      int n,
  573.                                                      charT c)
  574.     { return replace(first-begin(),last-first,n,c); }
  575.     basic_string<charT, traits, Allocator>& replace (iterator first,
  576.                                                      iterator last,
  577.                                                      unsigned int n,
  578.                                                      charT c)
  579.     { return replace(first-begin(),last-first,n,c); }
  580.     basic_string<charT, traits, Allocator>& replace (iterator first,
  581.                                                      iterator last,
  582.                                                      long n,
  583.                                                      charT c)
  584.     { return replace(first-begin(),last-first,n,c); }
  585.     basic_string<charT, traits, Allocator>& replace (iterator first,
  586.                                                      iterator last,
  587.                                                      unsigned long n,
  588.                                                      charT c)
  589.     { return replace(first-begin(),last-first,n,c); }
  590.     basic_string<charT, traits, Allocator>& replace (iterator first,
  591.                                                      iterator last,
  592.                                                      short n,
  593.                                                      charT c)
  594.     { return replace(first-begin(),last-first,n,c); }
  595.     basic_string<charT, traits, Allocator>& replace (iterator first,
  596.                                                      iterator last,
  597.                                                      unsigned short n,
  598.                                                      charT c)
  599.     { return replace(first-begin(),last-first,n,c); }
  600.     basic_string<charT, traits, Allocator>& replace (iterator first,
  601.                                                      iterator last,
  602.                                                      char n,
  603.                                                      charT c)
  604.     { return replace(first-begin(),last-first,n,c); }
  605.     basic_string<charT, traits, Allocator>& replace (iterator first,
  606.                                                      iterator last,
  607.                                                      unsigned char n,
  608.                                                      charT c)
  609.     { return replace(first-begin(),last-first,n,c); }
  610. #ifndef _RWSTD_NO_OVERLOAD_WCHAR
  611.     basic_string<charT, traits, Allocator>& replace (iterator first,
  612.                                                      iterator last,
  613.                                                      wchar_t n,
  614.                                                      charT c)
  615.     { return replace(first-begin(),last-first,n,c); }
  616. #endif
  617. #ifndef _RWSTD_NO_BOOL
  618.     basic_string<charT, traits, Allocator>& replace (iterator first,
  619.                                                      iterator last,
  620.                                                      bool n,
  621.                                                      charT c)
  622.     { return replace(first-begin(),last-first,n,c); }
  623. #endif
  624. #else
  625.     inline basic_string<charT, traits, Allocator>& replace (iterator, iterator, 
  626.                                                      const charT*,
  627.                                                      const charT*);
  628.     inline basic_string<charT, traits, Allocator>& replace (iterator,
  629.                                                      iterator,
  630.                                                      size_type,
  631.                                                      charT);
  632. #endif  // _RWSTD_NO_MEMBER_TEMPLATES
  633.  
  634.     size_type copy (charT*, size_type, size_type = 0) const;
  635.     basic_string<charT, traits, Allocator> copy () const; // Returns deep copy
  636.     void swap(basic_string<charT, traits, Allocator>& s)
  637.     {
  638.       charT * temp = __data_.data(); __data_ = s.__data_.data(); s.__data_ = temp;
  639.     }
  640.  
  641.     //
  642.     // string operations
  643.     //
  644.     inline const charT* c_str () const;
  645.     inline const charT* data  () const;
  646.     allocator_type get_allocator() const
  647.     {
  648.       return (allocator_type)__data_;
  649.     }
  650.  
  651.     inline size_type find (const basic_string<charT, traits, Allocator>&,
  652.                     size_type = 0) const;
  653.     size_type find (const charT*, size_type, size_type) const;
  654.     inline size_type find (const charT*, size_type = 0) const;
  655.     inline size_type find (charT, size_type = 0) const;
  656.  
  657.     inline size_type rfind (const basic_string<charT, traits, Allocator>&,
  658.                      size_type = npos) const;
  659.     size_type rfind (const charT*, size_type, size_type) const;
  660.     inline size_type rfind (const charT*, size_type = npos) const;
  661.     inline size_type rfind (charT, size_type = npos) const;
  662.  
  663.     inline size_type find_first_of (const basic_string<charT, traits, Allocator>&,
  664.                              size_type = 0) const;
  665.     size_type find_first_of (const charT*, size_type, size_type) const;
  666.     inline size_type find_first_of (const charT*, size_type = 0) const;
  667.     inline size_type find_first_of (charT, size_type = 0) const;
  668.     inline size_type find_last_of (const basic_string<charT, traits, Allocator>&,
  669.                             size_type = npos) const;
  670.     size_type find_last_of (const charT*, size_type, size_type) const;
  671.     inline size_type find_last_of (const charT*, size_type = npos) const;
  672.     inline size_type find_last_of (charT, size_type = npos) const;
  673.  
  674.     inline size_type find_first_not_of (const basic_string<charT, traits, Allocator>&,
  675.                                  size_type = 0) const;
  676.     size_type find_first_not_of (const charT*, size_type ,
  677.                                  size_type) const;
  678.     inline size_type find_first_not_of (const charT*, size_type = 0) const;
  679.     inline size_type find_first_not_of (charT, size_type = 0) const;
  680.  
  681.     inline size_type find_last_not_of (const basic_string<charT, traits, Allocator>&,
  682.                                 size_type = npos) const;
  683.     size_type find_last_not_of (const charT*, size_type, size_type) const;
  684.     inline size_type find_last_not_of (const charT*, size_type = npos) const;
  685.     inline size_type find_last_not_of (charT, size_type = npos) const;
  686.   
  687.     basic_string<charT, traits, Allocator> substr (size_type = 0,
  688.                                                    size_type = npos) const;
  689.   
  690.     inline int compare(const basic_string<charT, traits, Allocator>&) const;
  691.     int compare(size_type, size_type,
  692.                 const basic_string<charT, traits, Allocator>&) const;
  693.     int compare(size_type, size_type,
  694.                 const basic_string<charT, traits, Allocator>&,
  695.                 size_type, size_type) const;
  696.     inline int compare (const charT*) const;
  697.     int compare (size_type, size_type, const charT*, size_type) const;
  698.     inline int compare (size_type, size_type, const charT*) const;
  699.  
  700.   protected:
  701.  
  702.     size_type __getCapac () const { return __pref()->__getCapac(); }
  703.  
  704.     void __clobber (size_type); // Remove old contents
  705.     void __cow ()               // Do copy on write as necessary
  706.     { 
  707.       if (__pref()->__references() > 1) 
  708.         __clone(); 
  709.     }
  710.     void __cow (size_type nc)     // Do copy on write w/ new capacity
  711.     { 
  712.       if (__pref()->__references() > 1 || __getCapac() < nc)
  713.         __clone(nc);
  714.     }
  715.  
  716.   private:
  717.  
  718.     void __init_n(size_type, charT);
  719.  
  720.     static charT __eos () { return (charT)0; }
  721.   
  722.     //
  723.     // Make a distinct copy of self
  724.     //
  725.     void __clone (); 
  726.     //
  727.     // Make a distinct copy w/ new capacity nc
  728.     //
  729.     void __clone (size_type nc);
  730.  
  731.     __string_ref_type *  __pref () const
  732.     { 
  733. #ifdef _RWSTD_SUNPRO_ANACHRONISM
  734.       return (__string_ref_type*)__data_.data() - 1;
  735. #else
  736.       return _RWSTD_STATIC_CAST(__string_ref_type*,
  737.                                 ((_RWSTD_REINTERPRET_CAST(__string_ref_type*,__data_.data())) - 1)); 
  738. #endif
  739.     }
  740.  
  741.     //
  742.     // Disconnect from ref, maybe delete it.
  743.     //
  744.     inline void      __unLink          ();   
  745.  
  746. #ifndef _RWSTD_NO_NAMESPACE
  747.     friend class __RWSTD::__string_ref<charT,traits,Allocator>;
  748. #else
  749.     friend class __string_ref<charT,traits,Allocator>;
  750. #endif
  751.  
  752.     //
  753.     // Null string ref
  754.     //
  755. #ifndef _RWSTD_NO_STATIC_DEF3
  756.     static const __null_ref_type __nullref;
  757. #endif
  758.  
  759.     static __string_ref_type * __getNullRep ()
  760.     {
  761. #ifndef _RWSTD_NO_STATIC_DEF3
  762. #  ifdef _RWSTD_NO_STATIC_CAST
  763.       return (__string_ref_type *)&__nullref;
  764. #  else
  765.       return reinterpret_cast<__string_ref_type *>
  766.              (const_cast<__null_ref_type *>(&__nullref));
  767. #  endif // _RWSTD_NO_STATIC_CAST
  768. #else
  769.       if (!__RWSTD::__nullref_initialized)
  770.       {
  771.         new (&__RWSTD::__nullref) __null_ref_type();
  772.         __RWSTD::__nullref_initialized = 1;
  773.       }
  774.       return (__string_ref_type *) &__RWSTD::__nullref[0]; 
  775. #endif // _RWSTD_NO_STATIC_DEF3
  776.     }
  777.     __string_ref_type * __getRep (size_type capac, size_type nchar);
  778.  
  779.     __RWSTD::__rw_basis<charT*,allocator_type>    __data_;                   
  780.   };
  781. //
  782. // Standard Type Definitions
  783. //
  784.   typedef basic_string<char, char_traits<char>, allocator<char> >
  785.   string;
  786.  
  787. #ifndef _RWSTD_NO_WIDE_CHAR
  788.   typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >
  789.   wstring;
  790. #endif
  791.  
  792. //
  793. // The following has to go after the declaration of the string
  794. // classes because of cross references.
  795. //
  796.  
  797. #ifndef _RWSTD_NO_NAMESPACE
  798. }
  799. #endif
  800.  
  801. #ifdef _RW_STD_EXCEPT
  802. #include <stdexcept>
  803. #endif
  804.  
  805. #if defined(_RWSTD_NO_DESTROY_BUILTIN) || defined(_RWSTD_NO_DESTROY_NONBUILTIN)
  806.  
  807. #ifndef _RWSTD_NO_NAMESPACE
  808. namespace __rwstd {
  809. #endif
  810. //
  811. // Specializations for STL destroy
  812. //
  813.   inline void __destroy (string**)    {;}
  814.   inline void __destroy (string***)   {;}
  815.   inline void __destroy (string****)  {;}
  816. #ifndef _RWSTD_NO_WIDE_CHAR
  817.   inline void __destroy (wstring**)   {;}
  818.   inline void __destroy (wstring***)  {;}
  819.   inline void __destroy (wstring****) {;}
  820. #endif
  821.  
  822. #ifndef _RWSTD_NO_NAMESPACE
  823. }
  824. #endif
  825. #endif // _RWSTD_NO_DESTROY_BUILTIN || _RWSTD_NO_DESTROY_NONBUILTIN
  826.  
  827. #ifndef _RWSTD_NO_NAMESPACE
  828. namespace std {
  829. #endif
  830.  
  831. //
  832. // Inline member functions for class basic_string
  833. //
  834.  
  835.   template <class charT, class traits , class Allocator  >
  836.   inline void basic_string<charT, traits, Allocator>::__unLink()
  837.   {
  838.     if (!__data_.data())
  839.       return;
  840.     if (__pref()->__references() == 0 || __pref()->__removeReference() == 0) 
  841.     {
  842.       __ref_alloc_type(__data_).destroy(__pref());
  843.       __value_alloc_type(__data_).
  844.         deallocate(_RWSTD_REINTERPRET_CAST(charT*,__pref()),length());
  845.       __data_ = (charT*)0;
  846.     }
  847.   }
  848.  
  849.   template <class charT, class traits , class Allocator  >
  850.   inline basic_string<charT, traits, Allocator>
  851.   ::basic_string (const Allocator& alloc) : __data_((charT*)0,alloc)
  852.   {
  853.     __data_ = __getNullRep()->data();
  854.     __getNullRep()->__addReference();
  855.   }
  856.  
  857. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  858.   template <class charT, class traits , class Allocator  >
  859.   inline basic_string<charT, traits, Allocator>
  860.   ::basic_string (void) : __data_((charT*)0,Allocator())
  861.   {
  862.     __data_ = __getNullRep()->data();
  863.     __getNullRep()->__addReference();
  864.   }
  865. #endif
  866.  
  867. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  868.   template <class charT, class traits , class Allocator >
  869.   template <class InputIterator>
  870.   basic_string<charT, traits, Allocator>::basic_string (InputIterator first,
  871.                                                         InputIterator last,
  872.                                                         const Allocator &alloc)
  873.   : __data_(0,alloc)
  874.   {
  875.     __data_ = __getRep(1,0)->data();
  876.     replace(__data_.data(),__data_.data(),first,last);
  877.   }
  878. #endif /* _RWSTD_NO_MEMBER_TEMPLATES */
  879.  
  880.   template <class charT, class traits , class Allocator  >
  881.   inline
  882.   basic_string<charT, traits, Allocator>
  883.   ::basic_string (const basic_string<charT, traits, Allocator> & s)
  884.    : __data_((charT*)0,Allocator())
  885.   {                     
  886.     if ( s.__pref()->__references() > 0 )
  887.     {                                    
  888.       __data_ = s.__data_.data();
  889.       __pref()->__addReference();
  890.     }
  891.     else
  892.     {
  893.       size_type n = s.length();
  894.       __data_  = __getRep(n, n)->data();
  895.       traits::copy(__data_.data(), s.c_str(), n);
  896.     }
  897.   }
  898.  
  899. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  900.   // Since we have no way of knowing how much is out there
  901.   // between first2 and last2 we have to allocate some space
  902.   // in chunks as needed and copy over characters in groups
  903.   // until we reach the end of the range.  After that 
  904.   // we can tidy things up.  We avoid this using replace_aux
  905.   // any time we have an InputIterator capable of giving us
  906.   // the distance information we need.  If InputIterator
  907.   // is really a charT* then we should never even get here.
  908.   template<class charT, class traits , class Allocator >
  909.   template<class InputIterator>
  910.   inline basic_string<charT, traits, Allocator>& 
  911.   basic_string<charT, traits, Allocator>::replace (
  912.       iterator first1, 
  913.       iterator last1,
  914.       InputIterator first2,
  915.       InputIterator last2)
  916.   {
  917.      iterator first = first1;
  918.      iterator last = last1;
  919.  
  920.      // Use a (probably)faster algorithm if possible
  921.      if (__is_bidirectional_iterator(__iterator_category(first2)))
  922.        return __replace_aux(first1,last1,first2,last2);
  923.  
  924.      _RWSTD_THROW((first > end() || last > end()),out_of_range,
  925.      __RWSTD::except_msg_string(__RWSTD::__rwse_StringIndexOutOfRange,
  926.           "basic_string::replace(iterator,iterator,InputIterato,InputIterato)"
  927.            ,first > end() ? first : last,end()).msgstr());
  928.  
  929.      while (first2 != last2)
  930.      {
  931.      _RWSTD_THROW(first  - __data_.data() == npos,length_error,
  932.      __RWSTD::except_msg_string(__RWSTD::__rwse_ResultLenInvalid,
  933.           "basic_string::replace(iterator,iterator,InputIterator,InputIterator)"
  934.            ,first-__data_.data(),npos).msgstr());
  935.        if (first == last)
  936.        {
  937.          // Need to allocate a more room.
  938.          // First get the amount to increase buffer size         
  939.          size_type delta =  __RWSTD::__rw_allocation_size((value_type*)0,
  940.                                                         (size_type)0,
  941.                                                         (size_type)0);
  942.          delta = delta > 0 ? delta : 1;
  943.          size_type tot = delta + size();
  944.          // Now get new buffer
  945.          __string_ref_type * temp = __getRep(tot,tot);
  946.          // Now copy data from old to new, leaving a hole for additions
  947.          size_type current = last-begin();
  948.          traits::copy(temp->data(),__data_.data(),current);
  949.          traits::copy(temp->data()+current+delta,last,end()-last);
  950.          __unLink();
  951.          __data_ = temp->data();
  952.          first = __data_.data() + current;
  953.          last = first + delta;
  954.        }
  955.        // Copy data over
  956.        *first++ = *first2++;
  957.      }    
  958.      if (first != last)
  959.        replace(first-__data_.data(),last-first,0,(charT)' ');   // Clean up  
  960.  
  961.      return *this;
  962.   }
  963.  
  964.   // Special function for random access and bi-directional iterators
  965.   // Avoids the possibility of multiple allocations
  966.   // We still have to copy characters over one at a time.
  967.   template<class charT, class traits , class Allocator >
  968.   template<class InputIterator>
  969.   inline basic_string<charT, traits, Allocator>& 
  970.   basic_string<charT, traits, Allocator>::__replace_aux (
  971.       iterator first1, 
  972.       iterator last1,
  973.       InputIterator first2,
  974.       InputIterator last2)
  975.   {
  976.     difference_type n2 = 0;
  977.     distance(first2,last2,n2);
  978.     size_type n = last1-first1;
  979.     size_type pos = first1 - __data_.data();
  980.  
  981.     _RWSTD_THROW(pos > length(),out_of_range,
  982.      __RWSTD::except_msg_string(__RWSTD::__rwse_StringIndexOutOfRange,
  983.           "basic_string::__replace_aux(iterator,iterator,InputIterator,InputIterator)"
  984.            ,pos,length()).msgstr());
  985.  
  986.     size_type slen = length() - pos;
  987.     size_type xlen = n < slen ? n : slen; 
  988.  
  989.    _RWSTD_THROW(length() - xlen >= npos - n2,length_error,
  990.     __RWSTD::except_msg_string(__RWSTD::__rwse_ResultLenInvalid,
  991.          "basic_string::__replace_aux(iterator,iterator,InputIterator,InputIterator)"
  992.            ,length() - xlen, npos - n2).msgstr());
  993.  
  994.     size_type tot = length() - xlen + n2;  // Final string length.
  995.  
  996.     if (!tot)
  997.     {
  998.       // Special case a substitution that leaves the string empty.
  999.       __unLink();
  1000.       __getNullRep()->__addReference();
  1001.       __data_ = __getNullRep()->data();
  1002.     }
  1003.  
  1004.     else
  1005.     {
  1006.       size_type d = 0;
  1007.       size_type rem = length() - xlen - pos; // Length of bit at end of string
  1008.       // Check for shared representation, insufficient capacity, 
  1009.       if ( (__pref()->__references() > 1) || (__getCapac() < tot))
  1010.       {
  1011.         // Need to allocate a new reference.
  1012.         __string_ref_type * temp = __getRep(tot,tot);
  1013.         if (pos) traits::copy(temp->data(), __data_.data(), pos);
  1014.         for (d = 0; d < n2; d++)
  1015.           *(temp->data()+pos+d) = *first2++;
  1016.         if (rem ) 
  1017.           traits::copy(temp->data()+pos+n2, __data_.data()+pos+n, rem);
  1018.         __unLink();
  1019.         __data_ = temp->data();
  1020.       }
  1021.       else
  1022.       {
  1023.         // Current reference has enough room.
  1024.         if (rem)  
  1025.           traits::move(__data_.data()+pos+n2, __data_.data()+pos+n, rem);
  1026.         for (d = 0; d < n2; d++)
  1027.           *(__data_.data()+pos+d) = *first2++;
  1028.         __data_.data()[__pref()->__nchars_ = tot] = __eos();   // Add terminating null
  1029.       }
  1030.     }
  1031.     return *this;
  1032.   }
  1033. #endif // _RWSTD_NO_MEMBER_TEMPLATES
  1034.  
  1035.   template <class charT, class traits , class Allocator  >
  1036.   inline basic_string<charT, traits, Allocator> &
  1037.   basic_string<charT, traits, Allocator>::operator= (charT c)
  1038.   {
  1039.     replace(0,length(),1,c);
  1040.     return *this;
  1041.   }
  1042.  
  1043.   template <class charT, class traits , class Allocator  >
  1044.   inline basic_string<charT, traits, Allocator> &
  1045.   basic_string<charT, traits, Allocator>::operator+= (const basic_string<charT, traits, Allocator>& s)
  1046.   {
  1047.     return append(s);
  1048.   }
  1049.  
  1050.   template <class charT, class traits , class Allocator  >
  1051.   inline basic_string<charT, traits, Allocator> &
  1052.   basic_string<charT, traits, Allocator>::operator+= (const charT* s)
  1053.   {
  1054.     return append(s);
  1055.   }
  1056.  
  1057.   template <class charT, class traits , class Allocator  >
  1058.   inline basic_string<charT, traits, Allocator> &
  1059.   basic_string<charT, traits, Allocator>::operator+= (charT c)
  1060.   {
  1061.     return append((size_type) 1, c);
  1062.   }
  1063.  
  1064.   template <class charT, class traits , class Allocator  >
  1065.   inline basic_string<charT, traits, Allocator> &
  1066.   basic_string<charT, traits, Allocator>::append (const charT* s, size_type n)
  1067.   {
  1068.     replace(size(),0,s,n,0,n);
  1069.     return *this;
  1070.   }
  1071.  
  1072.   template <class charT, class traits , class Allocator  >
  1073.   inline basic_string<charT, traits, Allocator> &
  1074.   basic_string<charT, traits, Allocator>::append (const charT* s)
  1075.   {
  1076.     replace(size(),0,s);
  1077.     return *this;
  1078.   }
  1079.  
  1080. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  1081.   template<class charT, class traits , class Allocator >
  1082.   template<class InputIterator>
  1083.   inline basic_string<charT, traits, Allocator>& 
  1084.   basic_string<charT, traits, Allocator>::append (InputIterator first, 
  1085.                                                   InputIterator last )
  1086.   {
  1087.     replace(end(),end(),first,last);
  1088.     return *this;
  1089.   }
  1090. #else
  1091.   template <class charT, class traits , class Allocator  >
  1092.   inline basic_string<charT, traits, Allocator>& 
  1093.   basic_string<charT, traits, Allocator>::append (const charT* first, 
  1094.                                                   const charT* last)
  1095.   {
  1096.     replace(size(),0,first,last-first,0,last-first);
  1097.     return *this;
  1098.   }
  1099.  
  1100.   template <class charT, class traits , class Allocator  >
  1101.   inline basic_string<charT, traits, Allocator> &
  1102.   basic_string<charT, traits, Allocator>::append (size_type n, charT c)
  1103.   {
  1104.     replace(length(),0,n,c);
  1105.     return *this;
  1106.   }
  1107. #endif // _RWSTD_NO_MEMBER_TEMPLATES
  1108.  
  1109.   template <class charT, class traits , class Allocator  >
  1110.   inline void basic_string<charT, traits, Allocator>::push_back(const charT c) // RW_BUG not marked as inline
  1111.   {
  1112.     replace(size(),0,1,c);
  1113.   }
  1114.  
  1115.   template <class charT, class traits , class Allocator  >
  1116.   inline basic_string<charT, traits, Allocator> &
  1117.   basic_string<charT, traits, Allocator>::assign (const charT* s, size_type n)
  1118.   {
  1119.     replace(0, length(), s, n, 0, n);
  1120.     return *this;
  1121.   }
  1122.  
  1123.   template <class charT, class traits , class Allocator  >
  1124.   inline basic_string<charT, traits, Allocator> &
  1125.   basic_string<charT, traits, Allocator>::assign (const charT* s)
  1126.   {
  1127.     size_type len = traits::length(s);
  1128.     replace(0, length(), s, len, 0, len);
  1129.     return *this;
  1130.   }
  1131.  
  1132. #ifndef _RWSTD_NO_MEMBER_TEMPLATES 
  1133.   template<class charT, class traits , class Allocator >
  1134.   template<class InputIterator>
  1135.   inline basic_string<charT, traits, Allocator>& 
  1136.   basic_string<charT, traits, Allocator>::assign (InputIterator first, 
  1137.                                                   InputIterator last)
  1138.   {
  1139.     replace(begin(),end(),first,last);
  1140.     return *this;
  1141.   }
  1142. #else
  1143.   template <class charT, class traits , class Allocator  >
  1144.   inline basic_string<charT, traits, Allocator>& 
  1145.   basic_string<charT, traits, Allocator>::assign (const charT* first, 
  1146.                                                   const charT* last)
  1147.   {
  1148.     replace(0,length(),first,last-first,0,last-first);
  1149.     return *this;
  1150.   }
  1151.  
  1152.   template <class charT, class traits , class Allocator  >
  1153.   inline basic_string<charT, traits, Allocator> &
  1154.   basic_string<charT, traits, Allocator>::assign (size_type n, charT c)
  1155.   {
  1156.     return replace(0,length(),n,c);
  1157.   }
  1158. #endif // _RWSTD_NO_MEMBER_TEMPLATES 
  1159.  
  1160.   template <class charT, class traits , class Allocator  >
  1161.   inline basic_string<charT, traits, Allocator> &
  1162.   basic_string<charT, traits, Allocator>::insert (size_type pos,
  1163.                                                   const charT* s,
  1164.                                                   size_type n)
  1165.   {
  1166.     replace(pos, 0, s, n, 0, n);
  1167.     return *this;
  1168.   }
  1169.  
  1170.   template <class charT, class traits , class Allocator  >
  1171.   inline basic_string<charT, traits, Allocator> &
  1172.   basic_string<charT, traits, Allocator>::insert (size_type pos, const charT* s)
  1173.   {
  1174.     size_type len = traits::length(s);
  1175.     replace(pos, 0, s, len, 0, len);
  1176.     return *this;
  1177.   }
  1178.  
  1179. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  1180.   template<class charT, class traits , class Allocator >
  1181.   template<class InputIterator>
  1182.   inline void 
  1183.   basic_string<charT, traits, Allocator>::insert (
  1184.       iterator p, 
  1185.       InputIterator first,
  1186.       InputIterator last)
  1187.   {
  1188.     replace(p,p,first,last);
  1189.   }
  1190. #else
  1191.   template <class charT, class traits , class Allocator  >
  1192.   inline void 
  1193.   basic_string<charT, traits, Allocator>::insert (
  1194.       iterator p, 
  1195.       const charT* first,
  1196.       const charT* last)
  1197.   {
  1198.     replace(p-begin(),0,first,last-first,0,last-first);
  1199.   }
  1200.  
  1201.   template <class charT, class traits , class Allocator  >
  1202.   inline void 
  1203.   basic_string<charT, traits, Allocator>::insert (
  1204.       iterator p,
  1205.       size_type n,
  1206.       charT c)
  1207.   {
  1208.       replace(p-begin(),0,n,c);
  1209.   }
  1210.  
  1211.   template <class charT, class traits , class Allocator  >
  1212.   inline basic_string<charT, traits, Allocator> &
  1213.   basic_string<charT, traits, Allocator>::insert(size_type pos,
  1214.                                                  size_type n,
  1215.                                                  charT c)
  1216.   {
  1217.     return replace(pos,0,n,c);
  1218.   }
  1219. #endif // _RWSTD_NO_MEMBER_TEMPLATES
  1220.  
  1221.   template <class charT, class traits , class Allocator  >
  1222.   inline basic_string<charT, traits, Allocator> &
  1223.   basic_string<charT, traits, Allocator>::erase (size_type pos, size_type n)
  1224.   {
  1225.     _RWSTD_THROW(pos > length(), out_of_range,
  1226.      __RWSTD::except_msg_string(__RWSTD::__rwse_StringIndexOutOfRange,
  1227.          "basic_string::erase(size_t,size_t)", pos,length()).msgstr());
  1228.  
  1229.     size_type len = length() - pos;
  1230.     charT tmp[1];
  1231.     *tmp = 0;
  1232.     return replace(pos,n < len ? n : len, tmp,0);
  1233.   }
  1234.  
  1235.   template <class charT, class traits , class Allocator  >
  1236.   inline basic_string<charT, traits, Allocator> &
  1237.   basic_string<charT, traits, Allocator>::replace (size_type pos1,
  1238.                                                    size_type n1,
  1239.                                                    const basic_string<charT, traits, Allocator> & str, 
  1240.                                                    size_type pos2,
  1241.                                                    size_type n2)
  1242.   {
  1243.     replace(pos1, n1, str.data(), str.length(), pos2, n2);
  1244.     return *this;
  1245.   }
  1246.  
  1247.   template <class charT, class traits , class Allocator  >
  1248.   inline basic_string<charT, traits, Allocator> &
  1249.   basic_string<charT, traits, Allocator>::replace (
  1250.       size_type pos1,
  1251.       size_type n1,
  1252.       const basic_string<charT, traits, Allocator> & str)
  1253.   {
  1254.     replace(pos1, n1, str.data(), str.length(),0,str.length());
  1255.     return *this;
  1256.   }
  1257.  
  1258.   template <class charT, class traits , class Allocator  >
  1259.   inline _TYPENAME basic_string<charT, traits, Allocator>::iterator
  1260.   basic_string<charT, traits, Allocator>::__replace_aux (size_type pos1,
  1261.                                                        size_type n1,
  1262.                                                        const basic_string<charT, traits, Allocator> & str, 
  1263.                                                        size_type pos2,
  1264.                                                        size_type n2)
  1265.   {
  1266.     return replace(pos1, n1, str.data(), str.length(), pos2, n2);
  1267.   }
  1268.  
  1269.   template <class charT, class traits , class Allocator  >
  1270.   inline basic_string<charT, traits, Allocator> &
  1271.   basic_string<charT, traits, Allocator>::replace (size_type pos,
  1272.                                                    size_type n1,
  1273.                                                    const charT* s,
  1274.                                                    size_type n2)
  1275.   {
  1276.     replace(pos, n1, s, n2, 0, n2);
  1277.     return *this;
  1278.   }
  1279.  
  1280.   template <class charT, class traits , class Allocator  >
  1281.   inline basic_string<charT, traits, Allocator> &
  1282.   basic_string<charT, traits, Allocator>::replace (size_type pos,
  1283.                                                    size_type n1,
  1284.                                                    const charT* s)
  1285.   {
  1286.     size_type len = traits::length(s);
  1287.     replace(pos, n1, s, len, 0, len);
  1288.     return *this;
  1289.   }
  1290.  
  1291.   template <class charT, class traits , class Allocator  >
  1292.   inline basic_string<charT, traits, Allocator>& 
  1293.   basic_string<charT, traits, Allocator>::replace (
  1294.       iterator first,
  1295.       iterator last,
  1296.       const basic_string<charT, traits, Allocator>& str)
  1297.   {
  1298.     return replace(first - begin(), last - first, str);
  1299.   }
  1300.  
  1301.   template <class charT, class traits , class Allocator  >
  1302.   inline basic_string<charT, traits, Allocator>& 
  1303.   basic_string<charT, traits, Allocator>::replace (
  1304.       iterator first, 
  1305.       iterator last,
  1306.       const charT* s,
  1307.       size_type n)
  1308.   {
  1309.     replace(first-begin(),last-first,s,n,0,n);
  1310.     return *this;
  1311.   }
  1312.  
  1313.   template <class charT, class traits , class Allocator  >
  1314.   inline basic_string<charT, traits, Allocator>& 
  1315.   basic_string<charT, traits, Allocator>::replace (
  1316.       iterator first, 
  1317.       iterator last,
  1318.       const charT* s)
  1319.   {
  1320.     size_type len = traits::length(s);
  1321.     replace(first-begin(),last-first,s,len,0,len);
  1322.     return *this;
  1323.   }
  1324. #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  1325.   template <class charT, class traits , class Allocator  >
  1326.   inline basic_string<charT, traits, Allocator>& 
  1327.   basic_string<charT, traits, Allocator>::replace (
  1328.       iterator first1, 
  1329.       iterator last1,
  1330.       const charT* first2,
  1331.       const charT* last2)
  1332.   {
  1333.     replace(first1-begin(),last1-first1,first2,last2-first2,0,last2-first2);
  1334.     return *this;
  1335.   }
  1336.  
  1337.   template <class charT, class traits , class Allocator  >
  1338.   inline basic_string<charT, traits, Allocator>& 
  1339.   basic_string<charT, traits, Allocator>::replace (
  1340.       iterator first, 
  1341.       iterator last,
  1342.       size_type n,
  1343.       charT c)
  1344.   {
  1345.     return replace(first-begin(),last-first,n,c);
  1346.   }
  1347. #endif
  1348.  
  1349.   template <class charT, class traits , class Allocator  >
  1350.   inline _TYPENAME basic_string<charT, traits,Allocator>::const_reference 
  1351.   basic_string<charT, traits, Allocator>::operator[] (size_type pos) const
  1352.   {
  1353. #ifdef _RWSTD_BOUNDS_CHECKING
  1354.     _RWSTD_THROW(pos > size(), out_of_range,
  1355.      __RWSTD::except_msg_string(__RWSTD::__rwse_PosBeyondEndOfString,
  1356.         "basic_string::operator[](size_t) const", pos,size()).msgstr());
  1357. #endif
  1358.     return __data_.data()[pos];
  1359.   }
  1360.  
  1361.   template <class charT, class traits , class Allocator  >
  1362.   inline _TYPENAME basic_string<charT, traits, Allocator>::reference
  1363.   basic_string<charT, traits, Allocator>::operator[] (size_type pos)
  1364.   {
  1365. #ifdef _RWSTD_BOUNDS_CHECKING
  1366.     _RWSTD_THROW(pos >= size(), out_of_range,
  1367.      __RWSTD::except_msg_string(__RWSTD::__rwse_PosBeyondEndOfString,
  1368.         "basic_string::operator[](size_t)", pos,size()).msgstr());
  1369. #endif
  1370.     __cow();
  1371.     __pref()->__setRefCount(0);
  1372.     return __data_.data()[pos];
  1373.   }
  1374.  
  1375.   template <class charT, class traits , class Allocator  >
  1376.   inline _TYPENAME basic_string<charT, traits, Allocator>::const_reference
  1377.   basic_string<charT, traits, Allocator>::at (size_type pos) const
  1378.   {
  1379.     _RWSTD_THROW(pos >= size(), out_of_range,
  1380.      __RWSTD::except_msg_string(__RWSTD::__rwse_PosBeyondEndOfString,
  1381.         "basic_string::at(size_t) const", pos,size()).msgstr());
  1382.  
  1383.     return __data_.data()[pos];
  1384.   }
  1385.   template <class charT, class traits , class Allocator  >
  1386.   inline _TYPENAME basic_string<charT, traits, Allocator>::reference
  1387.   basic_string<charT, traits, Allocator>::at (size_type pos)
  1388.   {
  1389.     _RWSTD_THROW(pos >= size(), out_of_range,
  1390.      __RWSTD::except_msg_string(__RWSTD::__rwse_PosBeyondEndOfString,
  1391.           "basic_string::at(size_t)", pos,size()).msgstr());
  1392.  
  1393.     __cow();
  1394.     __pref()->__setRefCount(0);
  1395.     return __data_.data()[pos];
  1396.   }
  1397.  
  1398.   template <class charT, class traits , class Allocator  >
  1399.   inline const charT* basic_string<charT, traits, Allocator>::c_str () const
  1400.   {
  1401.     return __data_.data();
  1402.   }
  1403.  
  1404.   template <class charT, class traits , class Allocator  >
  1405.   inline const charT* basic_string<charT, traits, Allocator>::data () const
  1406.   {
  1407.     return __data_.data();
  1408.   }
  1409.  
  1410.   template <class charT, class traits , class Allocator  >
  1411.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1412.   basic_string<charT, traits, Allocator>::length () const
  1413.   {
  1414.     return __pref()->__nchars_;
  1415.   }
  1416.  
  1417.   template <class charT, class traits , class Allocator  >
  1418.   inline void
  1419.   basic_string<charT, traits, Allocator>::resize (size_type n, charT c)
  1420.   {
  1421.     _RWSTD_THROW(n > max_size(), length_error,
  1422.      __RWSTD::except_msg_string(__RWSTD::__rwse_InvalidSizeParam,
  1423.         "basic_string( const charT*,size_type,const Allocator&)",n,npos).msgstr());
  1424.     if (n < length())
  1425.       erase(n,length()-n);
  1426.     else
  1427.       replace(length(),0,n,c);
  1428.     __pref()->__setRefCount(1);
  1429.   }
  1430.  
  1431.   template <class charT, class traits , class Allocator  >
  1432.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1433.   basic_string<charT, traits, Allocator>::capacity () const
  1434.   {
  1435.     return __getCapac();
  1436.   }
  1437.  
  1438.   template <class charT, class traits , class Allocator  >
  1439.   inline void basic_string<charT, traits, Allocator>::reserve(size_type res_arg)
  1440.   {
  1441.      _RWSTD_THROW(res_arg > max_size(), length_error,
  1442.         __RWSTD::except_msg_string(__RWSTD::__rwse_InvalidSizeParam,
  1443.           "basic_string::reserve(size_t)",res_arg,max_size()).msgstr());
  1444.  
  1445.     if (res_arg > __getCapac()) __clone(res_arg);
  1446.   }
  1447.  
  1448.   template <class charT, class traits , class Allocator  >
  1449.   inline basic_string<charT, traits, Allocator>
  1450.   basic_string<charT, traits, Allocator>::copy () const
  1451.   {
  1452.     basic_string<charT, traits, Allocator> temp(*this); // Make referenced copy
  1453.     temp.__clone();   // Make a distinct copy
  1454.     return temp;
  1455.   }
  1456.  
  1457.   template <class charT, class traits, class Allocator >
  1458.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1459.   basic_string<charT, traits, Allocator>::find (
  1460.       const basic_string<charT, traits, Allocator>& str,
  1461.       size_type                                     pos) const
  1462.   {
  1463.     return find(str.c_str(),pos,str.length());
  1464.   }
  1465.  
  1466.   template <class charT, class traits , class Allocator  >
  1467.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1468.   basic_string<charT, traits, Allocator>::find (const charT* s,
  1469.                                                 size_type pos) const
  1470.   {
  1471.     _RWSTD_THROW(s == 0, logic_error,
  1472.      __RWSTD::except_msg_string(__RWSTD::__rwse_UnexpectedNullPtr,
  1473.        "basic_string::find(const char*,size_t) const").msgstr());
  1474.  
  1475.     if (pos > length())
  1476.       return npos;
  1477.     const charT* p = __RWSTD::rw_traits<charT,traits>::find(__data_.data()+pos,s);
  1478.     return p ? p - __data_.data() : npos;
  1479.   }
  1480.  
  1481.   template <class charT, class traits , class Allocator  >
  1482.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1483.   basic_string<charT, traits, Allocator>::find (charT c, size_type pos) const
  1484.   {
  1485.     if (pos > length())
  1486.       return npos;
  1487.     const charT* p =  traits::find(__data_.data()+pos,length()-pos,c);
  1488.     return p ? p - __data_.data() : npos;
  1489.   }
  1490.  
  1491.   template <class charT, class traits, class Allocator >
  1492.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1493.   basic_string<charT, traits, Allocator>::rfind (
  1494.       const basic_string<charT, traits, Allocator>& str,
  1495.       size_type                                     pos) const
  1496.   {
  1497.     return rfind(str.c_str(), pos, str.length());
  1498.   }
  1499.  
  1500.   template <class charT, class traits , class Allocator  >
  1501.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1502.   basic_string<charT, traits, Allocator>::rfind (const charT* s, size_type pos)
  1503.   const
  1504.   {  
  1505.     size_type len = traits::length(s);
  1506.     return rfind(s, pos,len);
  1507.   }
  1508.  
  1509.   template <class charT, class traits , class Allocator  >
  1510.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1511.   basic_string<charT, traits, Allocator>::rfind (charT c, size_type pos) const
  1512.   {
  1513.     if (pos > length())
  1514.       pos = length();
  1515.     const charT* p = __RWSTD::rw_traits<charT,traits>::rfind(__data_.data(),c,pos);
  1516.     return p ? p - __data_.data() : npos;
  1517.   }
  1518.  
  1519.   template <class charT, class traits, class Allocator >
  1520.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1521.   basic_string<charT, traits, Allocator>::find_first_of (
  1522.       const basic_string<charT, traits, Allocator>& str,
  1523.       size_type                                     pos) const
  1524.   {
  1525.     return find_first_of(str.c_str(),pos,str.length());
  1526.   }
  1527.  
  1528.   template <class charT, class traits , class Allocator  >
  1529.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1530.   basic_string<charT, traits, Allocator>::find_first_of (const charT* s,
  1531.                                                          size_type pos) const
  1532.   {
  1533.     _RWSTD_THROW(s == 0, logic_error,
  1534.      __RWSTD::except_msg_string(__RWSTD::__rwse_UnexpectedNullPtr,
  1535.         "basic_string::find_first_of(char*,size_t) const").msgstr());
  1536.  
  1537.     if (pos > length())
  1538.       return npos;
  1539.     size_type i = __RWSTD::rw_traits<charT,traits>::find_first_of(__data_.data()+pos,s) + pos;
  1540.     return i >= length() ? npos : i;
  1541.   }
  1542.  
  1543.   template <class charT, class traits , class Allocator  >
  1544.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1545.   basic_string<charT, traits, Allocator>::find_first_of (charT c, size_type pos) const
  1546.   {
  1547.     return find(c, pos);
  1548.   }
  1549.  
  1550.   template <class charT, class traits, class Allocator >
  1551.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1552.   basic_string<charT, traits, Allocator>::find_last_of (
  1553.       const basic_string<charT, traits, Allocator>& str,
  1554.       size_type                                     pos) const
  1555.   {
  1556.     return find_last_of(str.c_str(), pos,str.length());
  1557.   }
  1558.  
  1559.   template <class charT, class traits , class Allocator  >
  1560.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1561.   basic_string<charT, traits, Allocator>::find_last_of (const charT* s,
  1562.                                                         size_type pos) const
  1563.   {
  1564.     size_type len = traits::length(s);
  1565.     return find_last_of(s, pos,len);
  1566.   }
  1567.  
  1568.   template <class charT, class traits , class Allocator  >
  1569.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1570.   basic_string<charT, traits, Allocator>::find_last_of (charT c, size_type pos)
  1571.   const
  1572.   {
  1573.     return rfind(c,pos);
  1574.   }
  1575.  
  1576.   template <class charT, class traits, class Allocator >
  1577.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1578.   basic_string<charT, traits, Allocator>::find_first_not_of (
  1579.       const basic_string<charT, traits, Allocator>& str,
  1580.       size_type                                     pos) const
  1581.   {
  1582.     return find_first_not_of(str.c_str(), pos, str.length());
  1583.   }
  1584.  
  1585.   template <class charT, class traits , class Allocator  >
  1586.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1587.   basic_string<charT, traits, Allocator>::find_first_not_of (const charT* s,
  1588.                                                              size_type pos) const
  1589.   {
  1590.     _RWSTD_THROW(s == 0, logic_error,
  1591.      __RWSTD::except_msg_string(__RWSTD::__rwse_UnexpectedNullPtr,
  1592.        "basic_string::find_first_not_of(char*,size_t) const").msgstr());
  1593.  
  1594.     if (pos > length())
  1595.       return npos;
  1596.     size_type i = __RWSTD::rw_traits<charT,traits>::find_first_not_of(__data_.data()+pos,s) + pos;
  1597.     return i >= length() ? npos : i;
  1598.   }
  1599.  
  1600.   template <class charT, class traits , class Allocator  >
  1601.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1602.   basic_string<charT, traits, Allocator>::find_first_not_of (charT c,
  1603.                                                              size_type pos) const
  1604.   {
  1605.     charT tmp[2];
  1606.     *tmp = c;
  1607.     tmp[1] = 0;
  1608.     return find_first_not_of(tmp, pos);
  1609.   }
  1610.  
  1611.   template <class charT, class traits, class Allocator >
  1612.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1613.   basic_string<charT, traits, Allocator>::find_last_not_of (
  1614.       const basic_string<charT, traits, Allocator>& str,
  1615.       size_type                                     pos) const
  1616.   {
  1617.     return find_last_not_of(str.c_str(), pos, str.length());
  1618.   }
  1619.  
  1620.   template <class charT, class traits , class Allocator  >
  1621.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1622.   basic_string<charT, traits, Allocator>::find_last_not_of (const charT* s,
  1623.                                                             size_type pos) const
  1624.   {
  1625.     size_type len = traits::length(s);
  1626.     return find_last_not_of(s, pos, len);
  1627.   }
  1628.  
  1629.   template <class charT, class traits , class Allocator  >
  1630.   inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1631.   basic_string<charT, traits, Allocator>::find_last_not_of (charT c,
  1632.                                                             size_type pos) const
  1633.   {
  1634.     charT tmp[2];
  1635.     *tmp = c;
  1636.     tmp[1] = 0;
  1637.     return find_last_not_of(tmp, pos);
  1638.   }
  1639.  
  1640.   template <class charT, class traits, class Allocator >
  1641.   inline int
  1642.   basic_string<charT, traits, Allocator>::compare (
  1643.       const basic_string<charT, traits, Allocator>& str) const
  1644.   {
  1645.     return compare(0,length(),str.c_str(),str.length());
  1646.   }
  1647.  
  1648.   template <class charT, class traits , class Allocator  >
  1649.   inline int
  1650.   basic_string<charT, traits, Allocator>::compare (size_type pos,
  1651.                                                    size_type n1,
  1652.                                                    const charT* s) const
  1653.   {
  1654.     size_type len = traits::length(s);
  1655.     return compare(pos,n1,s,len);
  1656.   }
  1657.  
  1658.   template <class charT, class traits , class Allocator  >
  1659.   inline int
  1660.   basic_string<charT, traits, Allocator>::compare (const charT* s) const
  1661.   {
  1662.     size_type len = traits::length(s);
  1663.     return compare(0,length(),s,len);
  1664.   }
  1665.  
  1666. //
  1667. // Inlined non-member operators
  1668. //
  1669.  
  1670.   template <class charT, class traits , class Allocator  >
  1671.   inline basic_string<charT, traits, Allocator> operator+(
  1672.       const basic_string<charT, traits, Allocator>& lhs,
  1673.       const basic_string<charT, traits, Allocator>& rhs)
  1674.   {
  1675.     return basic_string<charT, traits, Allocator>(lhs).append(rhs);
  1676.   }
  1677.  
  1678.   template <class charT, class traits , class Allocator  >
  1679.   inline basic_string<charT, traits, Allocator> operator+(
  1680.       const charT*                                  lhs,
  1681.       const basic_string<charT, traits, Allocator>& rhs)
  1682.   {
  1683.     return basic_string<charT, traits, Allocator>(lhs).append(rhs);
  1684.   }
  1685.  
  1686.   template <class charT, class traits , class Allocator  >
  1687.   inline basic_string<charT, traits, Allocator> operator+(
  1688.       charT lhs, const basic_string<charT, traits, Allocator>& rhs)
  1689.   {
  1690.     return basic_string<charT, traits, Allocator>(1,lhs).append(rhs);
  1691.   }
  1692.  
  1693.   template <class charT, class traits , class Allocator  >
  1694.   inline basic_string<charT, traits, Allocator> operator+(
  1695.       const basic_string<charT, traits, Allocator>& lhs,
  1696.       const charT*                                  rhs)
  1697.   {
  1698.     return basic_string<charT,traits,Allocator>(lhs).append(basic_string<charT, traits, Allocator>(rhs));
  1699.   }
  1700.  
  1701.   template <class charT, class traits , class Allocator  >
  1702.   inline basic_string<charT, traits, Allocator> operator+(
  1703.       const basic_string<charT, traits, Allocator>& lhs,
  1704.       charT                                         rhs)
  1705.   {
  1706.     return basic_string<charT,traits,Allocator>(lhs).append(basic_string<charT, traits, Allocator>(1,rhs));
  1707.   }
  1708.  
  1709.   template <class charT, class traits , class Allocator  >
  1710.   inline bool operator==(
  1711.       const basic_string<charT, traits, Allocator>& lhs,
  1712.       const basic_string<charT, traits, Allocator>& rhs)
  1713.   {
  1714.     return lhs.compare(rhs) == 0 ? true : false ;
  1715.   }
  1716.  
  1717.   template <class charT, class traits , class Allocator  >
  1718.   inline bool operator==(
  1719.       const charT*                                  lhs,
  1720.       const basic_string<charT, traits, Allocator>& rhs)
  1721.   {
  1722.     return basic_string<charT,traits,Allocator>(lhs).compare(rhs)==0?true:false;
  1723.   }
  1724.  
  1725.   template <class charT, class traits , class Allocator  >
  1726.   inline bool operator==(
  1727.       const basic_string<charT, traits, Allocator>& lhs,
  1728.       const charT*                                  rhs)
  1729.   {
  1730.     return lhs.compare(basic_string<charT,traits,Allocator>(rhs))==0?true:false;
  1731.   }
  1732.  
  1733.   template <class charT, class traits , class Allocator  >
  1734.   inline bool operator<(
  1735.       const basic_string<charT, traits, Allocator>& lhs,
  1736.       const basic_string<charT, traits, Allocator>& rhs)
  1737.   {
  1738.     return lhs.compare(rhs) < 0 ? true:false ;
  1739.   }
  1740.  
  1741.   template <class charT, class traits , class Allocator  >
  1742.   inline bool operator<(
  1743.       const charT*                                  lhs,
  1744.       const basic_string<charT, traits, Allocator>& rhs)
  1745.   {
  1746.     return basic_string<charT,traits,Allocator>(lhs).compare(rhs)<0?true:false;
  1747.   }
  1748.  
  1749.   template <class charT, class traits , class Allocator  >
  1750.   inline bool operator<(
  1751.       const basic_string<charT, traits, Allocator>& lhs,
  1752.       const charT*                                  rhs)
  1753.   {
  1754.     return lhs.compare(basic_string<charT,traits,Allocator>(rhs))<0?true:false;
  1755.   }
  1756.  
  1757. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  1758.   template <class charT, class traits , class Allocator  >
  1759.   inline bool operator!=(
  1760.       const basic_string<charT, traits, Allocator>& lhs,
  1761.       const basic_string<charT, traits, Allocator>& rhs)
  1762.   {
  1763.     return lhs.compare(rhs) != 0 ? true : false;
  1764.   }
  1765. #endif
  1766.  
  1767.   template <class charT, class traits , class Allocator  >
  1768.   inline bool operator!=(
  1769.       const charT*                                  lhs,
  1770.       const basic_string<charT, traits, Allocator>& rhs)
  1771.   {
  1772.     return basic_string<charT,traits,Allocator>(lhs).compare(rhs)!=0?true:false;
  1773.   }
  1774.  
  1775.   template <class charT, class traits , class Allocator  >
  1776.   inline bool operator!=(
  1777.       const basic_string<charT, traits, Allocator>& lhs,
  1778.       const charT*                                  rhs)
  1779.   {
  1780.     return lhs.compare(basic_string<charT,traits,Allocator>(rhs))!=0?true:false;
  1781.   }
  1782.  
  1783. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  1784.   template <class charT, class traits , class Allocator  >
  1785.   inline bool operator>(
  1786.       const basic_string<charT, traits, Allocator>& lhs,
  1787.       const basic_string<charT, traits, Allocator>& rhs)
  1788.   {
  1789.     return lhs.compare(rhs) > 0 ? true : false;
  1790.   }
  1791. #endif
  1792.  
  1793.   template <class charT, class traits , class Allocator  >
  1794.   inline bool operator>(
  1795.       const charT*                                  lhs,
  1796.       const basic_string<charT, traits, Allocator>& rhs)
  1797.   {
  1798.     return basic_string<charT,traits,Allocator>(lhs).compare(rhs)>0?true:false;
  1799.   }
  1800.  
  1801.   template <class charT, class traits , class Allocator  >
  1802.   inline bool operator>(
  1803.       const basic_string<charT, traits, Allocator>& lhs,
  1804.       const charT*                                  rhs)
  1805.   {
  1806.     return lhs.compare(basic_string<charT,traits,Allocator>(rhs))>0?true:false;
  1807.   }
  1808.  
  1809. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  1810.   template <class charT, class traits , class Allocator  >
  1811.   inline bool operator<=(
  1812.       const basic_string<charT, traits, Allocator>& lhs,
  1813.       const basic_string<charT, traits, Allocator>& rhs)
  1814.   {
  1815.     return lhs.compare(rhs) <= 0 ? true : false;
  1816.   }
  1817. #endif
  1818.  
  1819.   template <class charT, class traits , class Allocator  >
  1820.   inline bool operator<=(
  1821.       const charT*                                  lhs,
  1822.       const basic_string<charT, traits, Allocator>& rhs)
  1823.   {
  1824.     return basic_string<charT,traits,Allocator>(lhs).compare(rhs)<=0?true:false;
  1825.   }
  1826.  
  1827.   template <class charT, class traits , class Allocator  >
  1828.   inline bool operator<=(
  1829.       const basic_string<charT, traits, Allocator>& lhs,
  1830.       const charT*                                  rhs)
  1831.   {
  1832.     return lhs.compare(basic_string<charT,traits,Allocator>(rhs))<=0?true:false;
  1833.   }
  1834.  
  1835. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  1836.   template <class charT, class traits , class Allocator  >
  1837.   inline bool operator>=(
  1838.       const basic_string<charT, traits, Allocator>& lhs,
  1839.       const basic_string<charT, traits, Allocator>& rhs)
  1840.   {
  1841.     return lhs.compare(rhs) >= 0 ? true:false;
  1842.   }
  1843. #endif
  1844.  
  1845.   template <class charT, class traits , class Allocator  >
  1846.   inline bool operator>=(
  1847.       const charT*                                  lhs,
  1848.       const basic_string<charT, traits, Allocator>& rhs)
  1849.   {
  1850.     return basic_string<charT,traits,Allocator>(lhs).compare(rhs)>=0?true:false;
  1851.   }
  1852.  
  1853.   template <class charT, class traits , class Allocator  >
  1854.   inline bool operator>=(
  1855.       const basic_string<charT, traits, Allocator>& lhs,
  1856.       const charT*                                  rhs)
  1857.   {
  1858.     return lhs.compare(basic_string<charT,traits,Allocator>(rhs))>=0?true:false;
  1859.   }
  1860.  
  1861. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  1862.   template <class charT, class traits, class Allocator>
  1863.   inline void swap(basic_string<charT,traits,Allocator>& a, 
  1864.                    basic_string<charT,traits,Allocator>& b)
  1865.   {
  1866.     a.swap(b);
  1867.   }
  1868. #endif
  1869.  
  1870. #ifndef _RW_STD_IOSTREAM
  1871.  
  1872.   template<class charT, class traits , class Allocator >
  1873.   istream & _RWSTDExportTemplate operator >> (
  1874.       istream & is, basic_string<charT, traits, Allocator > & str);
  1875.  
  1876.   template<class charT, class traits , class Allocator >
  1877.   ostream& _RWSTDExportTemplate operator << (
  1878.       ostream & os, const basic_string<charT, traits, Allocator > & str);
  1879.  
  1880.   template<class Stream, class charT, class traits , class Allocator >
  1881.   Stream& _RWSTDExportTemplate getline(Stream& is, 
  1882.                                        basic_string<charT, traits,Allocator>& str, charT delim);
  1883.  
  1884.   template<class Stream, class charT, class traits , class Allocator >
  1885.   Stream& _RWSTDExportTemplate getline(Stream& is, 
  1886.                                        basic_string<charT, traits,Allocator>& str)
  1887.   { return getline(is,str,'\n'); }
  1888.  
  1889. #endif /*_RW_STD_IOSTREAM*/
  1890.  
  1891. #ifdef _RWSTD_MSC22_STATIC_INIT_BUG
  1892. #undef npos
  1893. #endif
  1894.  
  1895. #ifndef _RWSTD_NO_NAMESPACE
  1896. }
  1897. #endif
  1898.  
  1899. #ifdef _RWSTD_COMPILE_INSTANTIATE
  1900. #include <string.cc>
  1901. #endif
  1902. #endif /*defined __STD_STRING*/
  1903.  
  1904. #pragma option pop
  1905. #endif /* __STRING_STL */
  1906.