williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
williamr@2
|
3 |
*
|
williamr@2
|
4 |
* Copyright (c) 1997-1999
|
williamr@2
|
5 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
6 |
*
|
williamr@2
|
7 |
* Copyright (c) 1999
|
williamr@2
|
8 |
* Boris Fomitchev
|
williamr@2
|
9 |
*
|
williamr@2
|
10 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
11 |
* or implied. Any use is at your own risk.
|
williamr@2
|
12 |
*
|
williamr@2
|
13 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
14 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
15 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
16 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
17 |
* modified is included with the above copyright notice.
|
williamr@2
|
18 |
*
|
williamr@2
|
19 |
*/
|
williamr@2
|
20 |
|
williamr@2
|
21 |
#ifndef _STLP_STRING_H
|
williamr@2
|
22 |
#define _STLP_STRING_H
|
williamr@2
|
23 |
|
williamr@2
|
24 |
#ifndef _STLP_MEMORY
|
williamr@2
|
25 |
# include <memory>
|
williamr@2
|
26 |
#endif
|
williamr@2
|
27 |
|
williamr@2
|
28 |
# ifndef _STLP_CCTYPE
|
williamr@2
|
29 |
# include <cctype>
|
williamr@2
|
30 |
# endif
|
williamr@2
|
31 |
|
williamr@2
|
32 |
#ifndef _STLP_STRING_FWD_H
|
williamr@2
|
33 |
# include <stl/_string_fwd.h>
|
williamr@2
|
34 |
#endif
|
williamr@2
|
35 |
|
williamr@2
|
36 |
#ifndef _STLP_INTERNAL_FUNCTION_BASE_H
|
williamr@2
|
37 |
# include <stl/_function.h>
|
williamr@2
|
38 |
#endif
|
williamr@2
|
39 |
|
williamr@2
|
40 |
# include <stl/_ctraits_fns.h>
|
williamr@2
|
41 |
#ifndef _STLP_INTERNAL_ALGOBASE_H
|
williamr@2
|
42 |
# include <stl/_algobase.h>
|
williamr@2
|
43 |
#endif
|
williamr@2
|
44 |
|
williamr@2
|
45 |
#ifndef _STLP_INTERNAL_ITERATOR_H
|
williamr@2
|
46 |
# include <stl/_iterator.h>
|
williamr@2
|
47 |
#endif
|
williamr@2
|
48 |
|
williamr@2
|
49 |
#if defined( __MWERKS__ ) && ! defined (_STLP_USE_OWN_NAMESPACE)
|
williamr@2
|
50 |
|
williamr@2
|
51 |
// MSL implementation classes expect to see the definition of streampos
|
williamr@2
|
52 |
// when this header is included. We expect this to be fixed in later MSL
|
williamr@2
|
53 |
// implementations
|
williamr@2
|
54 |
# if !defined( __MSL_CPP__ ) || __MSL_CPP__ < 0x4105
|
williamr@2
|
55 |
# include <stl/msl_string.h>
|
williamr@2
|
56 |
# endif
|
williamr@2
|
57 |
|
williamr@2
|
58 |
#endif // __MWERKS__
|
williamr@2
|
59 |
|
williamr@2
|
60 |
// Standard C++ string class. This class has performance
|
williamr@2
|
61 |
// characteristics very much like vector<>, meaning, for example, that
|
williamr@2
|
62 |
// it does not perform reference-count or copy-on-write, and that
|
williamr@2
|
63 |
// concatenation of two strings is an O(N) operation.
|
williamr@2
|
64 |
|
williamr@2
|
65 |
// There are three reasons why basic_string is not identical to
|
williamr@2
|
66 |
// vector. First, basic_string always stores a null character at the
|
williamr@2
|
67 |
// end; this makes it possible for c_str to be a fast operation.
|
williamr@2
|
68 |
// Second, the C++ standard requires basic_string to copy elements
|
williamr@2
|
69 |
// using char_traits<>::assign, char_traits<>::copy, and
|
williamr@2
|
70 |
// char_traits<>::move. This means that all of vector<>'s low-level
|
williamr@2
|
71 |
// operations must be rewritten. Third, basic_string<> has a lot of
|
williamr@2
|
72 |
// extra functions in its interface that are convenient but, strictly
|
williamr@2
|
73 |
// speaking, redundant.
|
williamr@2
|
74 |
|
williamr@2
|
75 |
// Additionally, the C++ standard imposes a major restriction: according
|
williamr@2
|
76 |
// to the standard, the character type _CharT must be a POD type. This
|
williamr@2
|
77 |
// implementation weakens that restriction, and allows _CharT to be a
|
williamr@2
|
78 |
// a user-defined non-POD type. However, _CharT must still have a
|
williamr@2
|
79 |
// default constructor.
|
williamr@2
|
80 |
|
williamr@2
|
81 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
82 |
|
williamr@2
|
83 |
# ifdef _STLP_DEBUG
|
williamr@2
|
84 |
# define basic_string _Nondebug_string
|
williamr@2
|
85 |
# endif
|
williamr@2
|
86 |
|
williamr@2
|
87 |
// A helper class to use a char_traits as a function object.
|
williamr@2
|
88 |
|
williamr@2
|
89 |
template <class _Traits> struct _Not_within_traits
|
williamr@2
|
90 |
: public unary_function<typename _Traits::char_type, bool> {
|
williamr@2
|
91 |
typedef typename _Traits::char_type _CharT;
|
williamr@2
|
92 |
const _CharT* _M_first;
|
williamr@2
|
93 |
const _CharT* _M_last;
|
williamr@2
|
94 |
|
williamr@2
|
95 |
_Not_within_traits(const typename _Traits::char_type* __f,
|
williamr@2
|
96 |
const typename _Traits::char_type* __l)
|
williamr@2
|
97 |
: _M_first(__f), _M_last(__l) {}
|
williamr@2
|
98 |
|
williamr@2
|
99 |
bool operator()(const typename _Traits::char_type& __x) const {
|
williamr@2
|
100 |
return find_if(_M_first, _M_last,
|
williamr@2
|
101 |
_Eq_char_bound<_Traits>(__x)) == _M_last;
|
williamr@2
|
102 |
}
|
williamr@2
|
103 |
};
|
williamr@2
|
104 |
|
williamr@2
|
105 |
|
williamr@2
|
106 |
// -----------------------------------------------------------------------------
|
williamr@2
|
107 |
// Symbian string-to-descriptor conversion
|
williamr@2
|
108 |
// -----------------------------------------------------------------------------
|
williamr@2
|
109 |
#ifdef _STLP_IMPLICIT_STRING_TO_DESC
|
williamr@2
|
110 |
template< typename TYPE >
|
williamr@2
|
111 |
class _DescConv;
|
williamr@2
|
112 |
|
williamr@2
|
113 |
class _DescConv< wchar_t >
|
williamr@2
|
114 |
{
|
williamr@2
|
115 |
public:
|
williamr@2
|
116 |
|
williamr@2
|
117 |
typedef TPtrC16 DescT;
|
williamr@2
|
118 |
|
williamr@2
|
119 |
static TPtrC16 convert( const wchar_t *ptr, unsigned int len )
|
williamr@2
|
120 |
{
|
williamr@2
|
121 |
return TPtrC16( ptr, len );
|
williamr@2
|
122 |
}
|
williamr@2
|
123 |
};
|
williamr@2
|
124 |
|
williamr@2
|
125 |
class _DescConv< char >
|
williamr@2
|
126 |
{
|
williamr@2
|
127 |
public:
|
williamr@2
|
128 |
typedef TPtrC8 DescT;
|
williamr@2
|
129 |
|
williamr@2
|
130 |
static TPtrC8 convert( const char *ptr, unsigned int len )
|
williamr@2
|
131 |
{
|
williamr@2
|
132 |
return TPtrC8( (const TUint8 *)ptr, len );
|
williamr@2
|
133 |
}
|
williamr@2
|
134 |
};
|
williamr@2
|
135 |
#endif // _STLP_IMPLICIT_STRING_TO_DESC
|
williamr@2
|
136 |
|
williamr@2
|
137 |
|
williamr@2
|
138 |
// ------------------------------------------------------------
|
williamr@2
|
139 |
// Class _String_base.
|
williamr@2
|
140 |
|
williamr@2
|
141 |
// _String_base is a helper class that makes it it easier to write an
|
williamr@2
|
142 |
// exception-safe version of basic_string. The constructor allocates,
|
williamr@2
|
143 |
// but does not initialize, a block of memory. The destructor
|
williamr@2
|
144 |
// deallocates, but does not destroy elements within, a block of
|
williamr@2
|
145 |
// memory. The destructor assumes that _M_start either is null, or else
|
williamr@2
|
146 |
// points to a block of memory that was allocated using _String_base's
|
williamr@2
|
147 |
// allocator and whose size is _M_end_of_storage._M_data - _M_start.
|
williamr@2
|
148 |
|
williamr@2
|
149 |
template <class _Tp, class _Alloc> class _String_base
|
williamr@2
|
150 |
{
|
williamr@2
|
151 |
public:
|
williamr@2
|
152 |
_STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
|
williamr@2
|
153 |
typedef typename _Alloc_traits<_Tp, _Alloc>::allocator_type allocator_type;
|
williamr@2
|
154 |
typedef _String_base<_Tp,_Alloc> _Base;
|
williamr@2
|
155 |
_Tp* _M_start;
|
williamr@2
|
156 |
_Tp* _M_finish;
|
williamr@2
|
157 |
_STLP_alloc_proxy<_Tp*, _Tp, allocator_type> _M_end_of_storage;
|
williamr@2
|
158 |
size_t _M_stream_pos;
|
williamr@2
|
159 |
// Precondition: 0 < __n <= max_size().
|
williamr@2
|
160 |
void _M_allocate_block(size_t);
|
williamr@2
|
161 |
void _M_deallocate_block()
|
williamr@2
|
162 |
{ _M_end_of_storage.deallocate(_M_start, _M_end_of_storage._M_data - _M_start); }
|
williamr@2
|
163 |
|
williamr@2
|
164 |
size_t max_size() const { return (size_t(-1) / sizeof(_Tp)) - 1; }
|
williamr@2
|
165 |
|
williamr@2
|
166 |
_String_base(const allocator_type& __a)
|
williamr@2
|
167 |
: _M_start(0), _M_finish(0), _M_end_of_storage(__a, (_Tp*)0), _M_stream_pos(0) {
|
williamr@2
|
168 |
_STLP_PUSH_CLEANUP_ITEM(_Base, this)
|
williamr@2
|
169 |
}
|
williamr@2
|
170 |
|
williamr@2
|
171 |
_String_base(const allocator_type& __a, size_t __n)
|
williamr@2
|
172 |
: _M_start(0), _M_finish(0), _M_end_of_storage(__a, (_Tp*)0), _M_stream_pos(0)
|
williamr@2
|
173 |
{
|
williamr@2
|
174 |
_STLP_PUSH_CLEANUP_ITEM(_Base, this)
|
williamr@2
|
175 |
_M_allocate_block(__n);
|
williamr@2
|
176 |
}
|
williamr@2
|
177 |
|
williamr@2
|
178 |
~_String_base() { _M_deallocate_block(); }
|
williamr@2
|
179 |
|
williamr@2
|
180 |
void _M_throw_length_error() const;
|
williamr@2
|
181 |
void _M_throw_out_of_range() const;
|
williamr@2
|
182 |
};
|
williamr@2
|
183 |
|
williamr@2
|
184 |
# if defined (_STLP_USE_TEMPLATE_EXPORT)
|
williamr@2
|
185 |
_STLP_EXPORT_TEMPLATE_CLASS _String_base<char, allocator<char> >;
|
williamr@2
|
186 |
# if defined (_STLP_HAS_WCHAR_T)
|
williamr@2
|
187 |
_STLP_EXPORT_TEMPLATE_CLASS _String_base<wchar_t, allocator<wchar_t> >;
|
williamr@2
|
188 |
# endif
|
williamr@2
|
189 |
# endif /* _STLP_USE_TEMPLATE_EXPORT */
|
williamr@2
|
190 |
|
williamr@2
|
191 |
// ------------------------------------------------------------
|
williamr@2
|
192 |
// Class basic_string.
|
williamr@2
|
193 |
|
williamr@2
|
194 |
// Class invariants:
|
williamr@2
|
195 |
// (1) [start, finish) is a valid range.
|
williamr@2
|
196 |
// (2) Each iterator in [start, finish) points to a valid object
|
williamr@2
|
197 |
// of type value_type.
|
williamr@2
|
198 |
// (3) *finish is a valid object of type value_type; in particular,
|
williamr@2
|
199 |
// it is value_type().
|
williamr@2
|
200 |
// (4) [finish + 1, end_of_storage) is a valid range.
|
williamr@2
|
201 |
// (5) Each iterator in [finish + 1, end_of_storage) points to
|
williamr@2
|
202 |
// unininitialized memory.
|
williamr@2
|
203 |
|
williamr@2
|
204 |
// Note one important consequence: a string of length n must manage
|
williamr@2
|
205 |
// a block of memory whose size is at least n + 1.
|
williamr@2
|
206 |
|
williamr@2
|
207 |
struct _String_reserve_t {};
|
williamr@2
|
208 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
209 |
#ifdef __SYMBIAN32__
|
williamr@2
|
210 |
NONSHARABLE_CLASS ( basic_string ) : public _String_base<_CharT,_Alloc> {
|
williamr@2
|
211 |
#else
|
williamr@2
|
212 |
class basic_string : public _String_base<_CharT,_Alloc> {
|
williamr@2
|
213 |
#endif
|
williamr@2
|
214 |
private: // Protected members inherited from base.
|
williamr@2
|
215 |
typedef _String_base<_CharT,_Alloc> _Base;
|
williamr@2
|
216 |
typedef basic_string<_CharT, _Traits, _Alloc> _Self;
|
williamr@2
|
217 |
// fbp : used to optimize char/wchar_t cases, and to simplify
|
williamr@2
|
218 |
// _STLP_DEFAULT_CONSTRUCTOR_BUG problem workaround
|
williamr@2
|
219 |
typedef typename _Is_integer<_CharT>::_Integral _Char_Is_Integral;
|
williamr@2
|
220 |
public:
|
williamr@2
|
221 |
typedef _CharT value_type;
|
williamr@2
|
222 |
typedef _Traits traits_type;
|
williamr@2
|
223 |
|
williamr@2
|
224 |
typedef value_type* pointer;
|
williamr@2
|
225 |
typedef const value_type* const_pointer;
|
williamr@2
|
226 |
typedef value_type& reference;
|
williamr@2
|
227 |
typedef const value_type& const_reference;
|
williamr@2
|
228 |
typedef size_t size_type;
|
williamr@2
|
229 |
typedef ptrdiff_t difference_type;
|
williamr@2
|
230 |
typedef random_access_iterator_tag _Iterator_category;
|
williamr@2
|
231 |
|
williamr@2
|
232 |
typedef const value_type* const_iterator;
|
williamr@2
|
233 |
typedef value_type* iterator;
|
williamr@2
|
234 |
|
williamr@2
|
235 |
_STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
|
williamr@2
|
236 |
|
williamr@2
|
237 |
# if defined(_STLP_STATIC_CONST_INIT_BUG) && ! defined (__SYMBIAN32__)
|
williamr@2
|
238 |
enum { npos = -1 };
|
williamr@2
|
239 |
# elif __GNUC__ == 2 && __GNUC_MINOR__ == 96
|
williamr@2
|
240 |
// inline initializer conflicts with 'extern template'
|
williamr@2
|
241 |
static const size_t npos ;
|
williamr@2
|
242 |
# else
|
williamr@2
|
243 |
static const size_t npos = ~(size_t)0;
|
williamr@2
|
244 |
# endif
|
williamr@2
|
245 |
|
williamr@2
|
246 |
typedef _String_reserve_t _Reserve_t;
|
williamr@2
|
247 |
# if defined (_STLP_USE_NATIVE_STRING) && ! defined (_STLP_DEBUG)
|
williamr@2
|
248 |
# if (defined(__IBMCPP__) && (500 <= __IBMCPP__) && (__IBMCPP__ < 600) )
|
williamr@2
|
249 |
// this typedef is being used for conversions
|
williamr@2
|
250 |
typedef typename _STLP_VENDOR_STD::basic_string<_CharT,_Traits,
|
williamr@2
|
251 |
typename _STLP_VENDOR_STD::allocator<_CharT> > __std_string;
|
williamr@2
|
252 |
# else
|
williamr@2
|
253 |
// this typedef is being used for conversions
|
williamr@2
|
254 |
typedef _STLP_VENDOR_STD::basic_string<_CharT,_Traits,
|
williamr@2
|
255 |
_STLP_VENDOR_STD::allocator<_CharT> > __std_string;
|
williamr@2
|
256 |
# endif
|
williamr@2
|
257 |
# endif
|
williamr@2
|
258 |
|
williamr@2
|
259 |
public: // Constructor, destructor, assignment.
|
williamr@2
|
260 |
typedef typename _String_base<_CharT,_Alloc>::allocator_type allocator_type;
|
williamr@2
|
261 |
|
williamr@2
|
262 |
allocator_type get_allocator() const {
|
williamr@2
|
263 |
return _STLP_CONVERT_ALLOCATOR((const allocator_type&)this->_M_end_of_storage, _CharT);
|
williamr@2
|
264 |
}
|
williamr@2
|
265 |
|
williamr@2
|
266 |
_STLP_DECLSPEC basic_string();
|
williamr@2
|
267 |
|
williamr@2
|
268 |
explicit basic_string(const allocator_type& __a)
|
williamr@2
|
269 |
: _String_base<_CharT,_Alloc>(__a, 8) {
|
williamr@2
|
270 |
_M_terminate_string();
|
williamr@2
|
271 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
272 |
}
|
williamr@2
|
273 |
|
williamr@2
|
274 |
basic_string(_Reserve_t, size_t __n,
|
williamr@2
|
275 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
276 |
: _String_base<_CharT,_Alloc>(__a, __n + 1) {
|
williamr@2
|
277 |
_M_terminate_string();
|
williamr@2
|
278 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
279 |
}
|
williamr@2
|
280 |
|
williamr@2
|
281 |
_STLP_DECLSPEC basic_string(const basic_string<_CharT, _Traits, _Alloc>&);
|
williamr@2
|
282 |
|
williamr@2
|
283 |
basic_string(const _Self& __s, size_type __pos, size_type __n = npos,
|
williamr@2
|
284 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
285 |
: _String_base<_CharT,_Alloc>(__a) {
|
williamr@2
|
286 |
if (__pos > __s.size())
|
williamr@2
|
287 |
this->_M_throw_out_of_range();
|
williamr@2
|
288 |
else
|
williamr@2
|
289 |
_M_range_initialize(__s._M_start + __pos,
|
williamr@2
|
290 |
__s._M_start + __pos + (min) (__n, __s.size() - __pos));
|
williamr@2
|
291 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
292 |
}
|
williamr@2
|
293 |
|
williamr@2
|
294 |
basic_string(const _CharT* __s, size_type __n,
|
williamr@2
|
295 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
296 |
: _String_base<_CharT,_Alloc>(__a)
|
williamr@2
|
297 |
{
|
williamr@2
|
298 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
299 |
_M_range_initialize(__s, __s + __n);
|
williamr@2
|
300 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
301 |
}
|
williamr@2
|
302 |
|
williamr@2
|
303 |
_STLP_DECLSPEC basic_string(const _CharT* __s,
|
williamr@2
|
304 |
const allocator_type& __a = allocator_type());
|
williamr@2
|
305 |
|
williamr@2
|
306 |
basic_string(size_type __n, _CharT __c,
|
williamr@2
|
307 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
308 |
: _String_base<_CharT,_Alloc>(__a, __n + 1)
|
williamr@2
|
309 |
{
|
williamr@2
|
310 |
this->_M_finish = uninitialized_fill_n(this->_M_start, __n, __c);
|
williamr@2
|
311 |
_M_terminate_string();
|
williamr@2
|
312 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
313 |
}
|
williamr@2
|
314 |
|
williamr@2
|
315 |
// Check to see if _InputIterator is an integer type. If so, then
|
williamr@2
|
316 |
// it can't be an iterator.
|
williamr@2
|
317 |
#if defined (_STLP_MEMBER_TEMPLATES) && !(defined(__MRC__)||(defined(__SC__) && !defined(__DMC__))) //*ty 04/30/2001 - mpw compilers choke on this ctor
|
williamr@2
|
318 |
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
|
williamr@2
|
319 |
template <class _InputIterator> basic_string(_InputIterator __f, _InputIterator __l)
|
williamr@2
|
320 |
: _String_base<_CharT,_Alloc>(allocator_type())
|
williamr@2
|
321 |
{
|
williamr@2
|
322 |
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
|
williamr@2
|
323 |
_M_initialize_dispatch(__f, __l, _Integral());
|
williamr@2
|
324 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
325 |
}
|
williamr@2
|
326 |
# endif
|
williamr@2
|
327 |
template <class _InputIterator> basic_string(_InputIterator __f, _InputIterator __l,
|
williamr@2
|
328 |
const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)
|
williamr@2
|
329 |
: _String_base<_CharT,_Alloc>(__a)
|
williamr@2
|
330 |
{
|
williamr@2
|
331 |
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
|
williamr@2
|
332 |
_M_initialize_dispatch(__f, __l, _Integral());
|
williamr@2
|
333 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
334 |
}
|
williamr@2
|
335 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
336 |
|
williamr@2
|
337 |
basic_string(const _CharT* __f, const _CharT* __l,
|
williamr@2
|
338 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
339 |
: _String_base<_CharT,_Alloc>(__a)
|
williamr@2
|
340 |
{
|
williamr@2
|
341 |
_STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
|
williamr@2
|
342 |
_M_range_initialize(__f, __l);
|
williamr@2
|
343 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
344 |
}
|
williamr@2
|
345 |
|
williamr@2
|
346 |
#endif
|
williamr@2
|
347 |
|
williamr@2
|
348 |
# if defined (_STLP_USE_NATIVE_STRING) && ! defined (_STLP_DEBUG)
|
williamr@2
|
349 |
// these conversion operations still needed for
|
williamr@2
|
350 |
// strstream, etc.
|
williamr@2
|
351 |
basic_string (const __std_string& __x): _String_base<_CharT,_Alloc>(allocator_type())
|
williamr@2
|
352 |
{
|
williamr@2
|
353 |
const _CharT* __s = __x.data();
|
williamr@2
|
354 |
_M_range_initialize(__s, __s + __x.size());
|
williamr@2
|
355 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
356 |
}
|
williamr@2
|
357 |
|
williamr@2
|
358 |
operator __std_string() const { return __std_string(this->data(), this->size()); }
|
williamr@2
|
359 |
# endif
|
williamr@2
|
360 |
|
williamr@2
|
361 |
~basic_string() { _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1); }
|
williamr@2
|
362 |
|
williamr@2
|
363 |
_Self& operator=(const _Self& __s) {
|
williamr@2
|
364 |
if (&__s != this)
|
williamr@2
|
365 |
{
|
williamr@2
|
366 |
assign(__s._M_start, __s._M_finish);
|
williamr@2
|
367 |
this->_M_stream_pos = __s.size();
|
williamr@2
|
368 |
}
|
williamr@2
|
369 |
return *this;
|
williamr@2
|
370 |
}
|
williamr@2
|
371 |
|
williamr@2
|
372 |
_Self& operator=(const _CharT* __s) {
|
williamr@2
|
373 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
374 |
return assign(__s, __s + traits_type::length(__s));
|
williamr@2
|
375 |
}
|
williamr@2
|
376 |
|
williamr@2
|
377 |
_Self& operator=(_CharT __c)
|
williamr@2
|
378 |
{ return assign(__STATIC_CAST(size_type,1), __c); }
|
williamr@2
|
379 |
|
williamr@2
|
380 |
static _CharT _STLP_CALL _M_null() {
|
williamr@2
|
381 |
return _STLP_DEFAULT_CONSTRUCTED(_CharT);
|
williamr@2
|
382 |
}
|
williamr@2
|
383 |
|
williamr@2
|
384 |
private: // Helper functions used by constructors
|
williamr@2
|
385 |
// and elsewhere.
|
williamr@2
|
386 |
// fbp : simplify integer types (char, wchar)
|
williamr@2
|
387 |
void _M_construct_null_aux(_CharT* __p, const __false_type&) {
|
williamr@2
|
388 |
_Construct(__p);
|
williamr@2
|
389 |
}
|
williamr@2
|
390 |
void _M_construct_null_aux(_CharT* __p, const __true_type&) {
|
williamr@2
|
391 |
*__p = 0;
|
williamr@2
|
392 |
}
|
williamr@2
|
393 |
|
williamr@2
|
394 |
void _M_construct_null(_CharT* __p) {
|
williamr@2
|
395 |
_M_construct_null_aux(__p, _Char_Is_Integral());
|
williamr@2
|
396 |
}
|
williamr@2
|
397 |
|
williamr@2
|
398 |
private:
|
williamr@2
|
399 |
// Helper functions used by constructors. It is a severe error for
|
williamr@2
|
400 |
// any of them to be called anywhere except from within constructors.
|
williamr@2
|
401 |
|
williamr@2
|
402 |
void _M_terminate_string_aux(const __false_type&) {
|
williamr@2
|
403 |
_STLP_TRY {
|
williamr@2
|
404 |
_M_construct_null(this->_M_finish);
|
williamr@2
|
405 |
}
|
williamr@2
|
406 |
_STLP_UNWIND(_STLP_STD::_Destroy(this->_M_start, this->_M_finish));
|
williamr@2
|
407 |
}
|
williamr@2
|
408 |
|
williamr@2
|
409 |
void _M_terminate_string_aux(const __true_type&) {
|
williamr@2
|
410 |
*(this->_M_finish)=0;
|
williamr@2
|
411 |
}
|
williamr@2
|
412 |
|
williamr@2
|
413 |
void _M_terminate_string() {
|
williamr@2
|
414 |
_M_terminate_string_aux(_Char_Is_Integral());
|
williamr@2
|
415 |
}
|
williamr@2
|
416 |
|
williamr@2
|
417 |
#ifndef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
418 |
bool _M_inside(const _CharT* __s ) const {
|
williamr@2
|
419 |
return (__s >= this->_M_start) && (__s < this->_M_finish);
|
williamr@2
|
420 |
}
|
williamr@2
|
421 |
#else
|
williamr@2
|
422 |
template <class _InputIter>
|
williamr@2
|
423 |
bool _M_inside(_InputIter __i) const {
|
williamr@2
|
424 |
const _CharT* __s = __STATIC_CAST(const _CharT*, &(*__i));
|
williamr@2
|
425 |
return (__s >= this->_M_start) && (__s < this->_M_finish);
|
williamr@2
|
426 |
}
|
williamr@2
|
427 |
#endif /*_STLP_MEMBER_TEMPLATES*/
|
williamr@2
|
428 |
|
williamr@2
|
429 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
430 |
|
williamr@2
|
431 |
template <class _InputIter> void _M_range_initialize(_InputIter __f, _InputIter __l,
|
williamr@2
|
432 |
const input_iterator_tag &) {
|
williamr@2
|
433 |
this->_M_allocate_block(8);
|
williamr@2
|
434 |
_M_construct_null(this->_M_finish);
|
williamr@2
|
435 |
_STLP_TRY {
|
williamr@2
|
436 |
append(__f, __l);
|
williamr@2
|
437 |
}
|
williamr@2
|
438 |
_STLP_UNWIND(_STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1));
|
williamr@2
|
439 |
}
|
williamr@2
|
440 |
|
williamr@2
|
441 |
template <class _ForwardIter> void _M_range_initialize(_ForwardIter __f, _ForwardIter __l,
|
williamr@2
|
442 |
const forward_iterator_tag &) {
|
williamr@2
|
443 |
difference_type __n = distance(__f, __l);
|
williamr@2
|
444 |
this->_M_allocate_block(__n + 1);
|
williamr@2
|
445 |
this->_M_finish = uninitialized_copy(__f, __l, this->_M_start);
|
williamr@2
|
446 |
_M_terminate_string();
|
williamr@2
|
447 |
|
williamr@2
|
448 |
}
|
williamr@2
|
449 |
|
williamr@2
|
450 |
template <class _InputIter> void _M_range_initialize(_InputIter __f, _InputIter __l) {
|
williamr@2
|
451 |
_M_range_initialize(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
|
williamr@2
|
452 |
}
|
williamr@2
|
453 |
|
williamr@2
|
454 |
template <class _Integer> void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type&) {
|
williamr@2
|
455 |
this->_M_allocate_block(__n + 1);
|
williamr@2
|
456 |
this->_M_finish = uninitialized_fill_n(this->_M_start, __n, __x);
|
williamr@2
|
457 |
_M_terminate_string();
|
williamr@2
|
458 |
}
|
williamr@2
|
459 |
|
williamr@2
|
460 |
template <class _InputIter> void _M_initialize_dispatch(_InputIter __f, _InputIter __l, const __false_type&) {
|
williamr@2
|
461 |
_M_range_initialize(__f, __l);
|
williamr@2
|
462 |
}
|
williamr@2
|
463 |
|
williamr@2
|
464 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
465 |
|
williamr@2
|
466 |
void _M_range_initialize(const _CharT* __f, const _CharT* __l) {
|
williamr@2
|
467 |
ptrdiff_t __n = __l - __f;
|
williamr@2
|
468 |
this->_M_allocate_block(__n + 1);
|
williamr@2
|
469 |
this->_M_finish = uninitialized_copy(__f, __l, this->_M_start);
|
williamr@2
|
470 |
_M_terminate_string();
|
williamr@2
|
471 |
}
|
williamr@2
|
472 |
|
williamr@2
|
473 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
474 |
|
williamr@2
|
475 |
#ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
476 |
public:
|
williamr@2
|
477 |
static void* operator new (size_t __n, TLeave) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
478 |
static void* operator new (size_t __n) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
479 |
#endif
|
williamr@2
|
480 |
|
williamr@2
|
481 |
public: // Iterators.
|
williamr@2
|
482 |
iterator begin() { return this->_M_start; }
|
williamr@2
|
483 |
iterator end() { return this->_M_finish; }
|
williamr@2
|
484 |
const_iterator begin() const { return this->_M_start; }
|
williamr@2
|
485 |
const_iterator end() const { return this->_M_finish; }
|
williamr@2
|
486 |
|
williamr@2
|
487 |
reverse_iterator rbegin()
|
williamr@2
|
488 |
{ return reverse_iterator(this->_M_finish); }
|
williamr@2
|
489 |
reverse_iterator rend()
|
williamr@2
|
490 |
{ return reverse_iterator(this->_M_start); }
|
williamr@2
|
491 |
const_reverse_iterator rbegin() const
|
williamr@2
|
492 |
{ return const_reverse_iterator(this->_M_finish); }
|
williamr@2
|
493 |
const_reverse_iterator rend() const
|
williamr@2
|
494 |
{ return const_reverse_iterator(this->_M_start); }
|
williamr@2
|
495 |
|
williamr@2
|
496 |
public: // Size, capacity, etc.
|
williamr@2
|
497 |
size_type size() const { return this->_M_finish - this->_M_start; }
|
williamr@2
|
498 |
size_type length() const { return size(); }
|
williamr@2
|
499 |
|
williamr@2
|
500 |
size_t max_size() const { return _Base::max_size(); }
|
williamr@2
|
501 |
|
williamr@2
|
502 |
|
williamr@2
|
503 |
void resize(size_type __n, _CharT __c) {
|
williamr@2
|
504 |
if (__n <= size())
|
williamr@2
|
505 |
erase(begin() + __n, end());
|
williamr@2
|
506 |
else
|
williamr@2
|
507 |
append(__n - size(), __c);
|
williamr@2
|
508 |
}
|
williamr@2
|
509 |
void resize(size_type __n) { resize(__n, _M_null()); }
|
williamr@2
|
510 |
|
williamr@2
|
511 |
_STLP_DECLSPEC void reserve(size_type = 0);
|
williamr@2
|
512 |
|
williamr@2
|
513 |
size_type capacity() const { return (this->_M_end_of_storage._M_data - this->_M_start) - 1; }
|
williamr@2
|
514 |
|
williamr@2
|
515 |
void clear() {
|
williamr@2
|
516 |
if (!empty()) {
|
williamr@2
|
517 |
_Traits::assign(*(this->_M_start), _M_null());
|
williamr@2
|
518 |
_STLP_STD::_Destroy(this->_M_start+1, this->_M_finish+1);
|
williamr@2
|
519 |
this->_M_finish = this->_M_start;
|
williamr@2
|
520 |
}
|
williamr@2
|
521 |
}
|
williamr@2
|
522 |
|
williamr@2
|
523 |
bool empty() const { return this->_M_start == this->_M_finish; }
|
williamr@2
|
524 |
|
williamr@2
|
525 |
public: // Element access.
|
williamr@2
|
526 |
|
williamr@2
|
527 |
const_reference operator[](size_type __n) const
|
williamr@2
|
528 |
{ return *(this->_M_start + __n); }
|
williamr@2
|
529 |
reference operator[](size_type __n)
|
williamr@2
|
530 |
{ return *(this->_M_start + __n); }
|
williamr@2
|
531 |
|
williamr@2
|
532 |
const_reference at(size_type __n) const {
|
williamr@2
|
533 |
if (__n >= size())
|
williamr@2
|
534 |
this->_M_throw_out_of_range();
|
williamr@2
|
535 |
return *(this->_M_start + __n);
|
williamr@2
|
536 |
}
|
williamr@2
|
537 |
|
williamr@2
|
538 |
reference at(size_type __n) {
|
williamr@2
|
539 |
if (__n >= size())
|
williamr@2
|
540 |
this->_M_throw_out_of_range();
|
williamr@2
|
541 |
return *(this->_M_start + __n);
|
williamr@2
|
542 |
}
|
williamr@2
|
543 |
|
williamr@2
|
544 |
public: // Append, operator+=, push_back.
|
williamr@2
|
545 |
|
williamr@2
|
546 |
_Self& operator+=(const _Self& __s) { return append(__s); }
|
williamr@2
|
547 |
_Self& operator+=(const _CharT* __s) { _STLP_FIX_LITERAL_BUG(__s) return append(__s); }
|
williamr@2
|
548 |
_Self& operator+=(_CharT __c) { push_back(__c); return *this; }
|
williamr@2
|
549 |
|
williamr@2
|
550 |
_Self& append(const _Self& __s)
|
williamr@2
|
551 |
{ return append(__s._M_start, __s._M_finish); }
|
williamr@2
|
552 |
|
williamr@2
|
553 |
_Self& append(const _Self& __s,
|
williamr@2
|
554 |
size_type __pos, size_type __n)
|
williamr@2
|
555 |
{
|
williamr@2
|
556 |
if (__pos > __s.size())
|
williamr@2
|
557 |
this->_M_throw_out_of_range();
|
williamr@2
|
558 |
return append(__s._M_start + __pos,
|
williamr@2
|
559 |
__s._M_start + __pos + (min) (__n, __s.size() - __pos));
|
williamr@2
|
560 |
}
|
williamr@2
|
561 |
|
williamr@2
|
562 |
_Self& append(const _CharT* __s, size_type __n)
|
williamr@2
|
563 |
{ _STLP_FIX_LITERAL_BUG(__s) return append(__s, __s+__n); }
|
williamr@2
|
564 |
_Self& append(const _CharT* __s)
|
williamr@2
|
565 |
{ _STLP_FIX_LITERAL_BUG(__s) return append(__s, __s + traits_type::length(__s)); }
|
williamr@2
|
566 |
_Self& append(size_type __n, _CharT __c);
|
williamr@2
|
567 |
|
williamr@2
|
568 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
569 |
|
williamr@2
|
570 |
// Check to see if _InputIterator is an integer type. If so, then
|
williamr@2
|
571 |
// it can't be an iterator.
|
williamr@2
|
572 |
template <class _InputIter> _Self& append(_InputIter __first, _InputIter __last) {
|
williamr@2
|
573 |
typedef typename _Is_integer<_InputIter>::_Integral _Integral;
|
williamr@2
|
574 |
return _M_append_dispatch(__first, __last, _Integral());
|
williamr@2
|
575 |
}
|
williamr@2
|
576 |
|
williamr@2
|
577 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
578 |
|
williamr@2
|
579 |
_Self& append(const _CharT* __first, const _CharT* __last);
|
williamr@2
|
580 |
|
williamr@2
|
581 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
582 |
|
williamr@2
|
583 |
void push_back(_CharT __c) {
|
williamr@2
|
584 |
if (this->_M_finish + 1 == this->_M_end_of_storage._M_data)
|
williamr@2
|
585 |
reserve(size() + (max)(size(), __STATIC_CAST(size_type,1)));
|
williamr@2
|
586 |
_M_construct_null(this->_M_finish + 1);
|
williamr@2
|
587 |
_Traits::assign(*(this->_M_finish), __c);
|
williamr@2
|
588 |
++this->_M_finish;
|
williamr@2
|
589 |
}
|
williamr@2
|
590 |
|
williamr@2
|
591 |
void pop_back() {
|
williamr@2
|
592 |
_Traits::assign(*(this->_M_finish - 1), _M_null());
|
williamr@2
|
593 |
_STLP_STD::_Destroy(this->_M_finish);
|
williamr@2
|
594 |
--this->_M_finish;
|
williamr@2
|
595 |
}
|
williamr@2
|
596 |
|
williamr@2
|
597 |
private: // Helper functions for append.
|
williamr@2
|
598 |
|
williamr@2
|
599 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
600 |
|
williamr@2
|
601 |
template <class _InputIter> _Self& append(_InputIter __first, _InputIter __last, const input_iterator_tag &)
|
williamr@2
|
602 |
{
|
williamr@2
|
603 |
for ( ; __first != __last ; ++__first)
|
williamr@2
|
604 |
push_back(*__first);
|
williamr@2
|
605 |
return *this;
|
williamr@2
|
606 |
}
|
williamr@2
|
607 |
|
williamr@2
|
608 |
template <class _ForwardIter> _Self& append(_ForwardIter __first, _ForwardIter __last,
|
williamr@2
|
609 |
const forward_iterator_tag &) {
|
williamr@2
|
610 |
if (__first != __last) {
|
williamr@2
|
611 |
const size_type __old_size = size();
|
williamr@2
|
612 |
difference_type __n = distance(__first, __last);
|
williamr@2
|
613 |
if (__STATIC_CAST(size_type,__n) > max_size() || __old_size > max_size() - __STATIC_CAST(size_type,__n))
|
williamr@2
|
614 |
this->_M_throw_length_error();
|
williamr@2
|
615 |
if (__old_size + __n > capacity()) {
|
williamr@2
|
616 |
const size_type __len = __old_size +
|
williamr@2
|
617 |
(max)(__old_size, __STATIC_CAST(size_type,__n)) + 1;
|
williamr@2
|
618 |
_STLP_LEAVE_VOLATILE pointer __new_start = this->_M_end_of_storage.allocate(__len);
|
williamr@2
|
619 |
_STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
|
williamr@2
|
620 |
_STLP_TRY {
|
williamr@2
|
621 |
__new_finish = uninitialized_copy(this->_M_start, this->_M_finish, __new_start);
|
williamr@2
|
622 |
__new_finish = uninitialized_copy(__first, __last, __new_finish);
|
williamr@2
|
623 |
_M_construct_null(__new_finish);
|
williamr@2
|
624 |
}
|
williamr@2
|
625 |
_STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),
|
williamr@2
|
626 |
this->_M_end_of_storage.deallocate(__new_start,__len)));
|
williamr@2
|
627 |
_STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
|
williamr@2
|
628 |
this->_M_deallocate_block();
|
williamr@2
|
629 |
this->_M_start = __new_start;
|
williamr@2
|
630 |
this->_M_finish = __new_finish;
|
williamr@2
|
631 |
this->_M_end_of_storage._M_data = __new_start + __len;
|
williamr@2
|
632 |
}
|
williamr@2
|
633 |
else {
|
williamr@2
|
634 |
_ForwardIter __f1 = __first;
|
williamr@2
|
635 |
++__f1;
|
williamr@2
|
636 |
uninitialized_copy(__f1, __last, this->_M_finish + 1);
|
williamr@2
|
637 |
_STLP_TRY {
|
williamr@2
|
638 |
_M_construct_null(this->_M_finish + __n);
|
williamr@2
|
639 |
}
|
williamr@2
|
640 |
_STLP_UNWIND(_STLP_STD::_Destroy(this->_M_finish + 1, this->_M_finish + __n));
|
williamr@2
|
641 |
_Traits::assign(*end(), *__first);
|
williamr@2
|
642 |
this->_M_finish += __n;
|
williamr@2
|
643 |
}
|
williamr@2
|
644 |
}
|
williamr@2
|
645 |
return *this;
|
williamr@2
|
646 |
}
|
williamr@2
|
647 |
|
williamr@2
|
648 |
template <class _Integer> _Self& _M_append_dispatch(_Integer __n, _Integer __x, const __true_type&) {
|
williamr@2
|
649 |
return append((size_type) __n, (_CharT) __x);
|
williamr@2
|
650 |
}
|
williamr@2
|
651 |
|
williamr@2
|
652 |
template <class _InputIter> _Self& _M_append_dispatch(_InputIter __f, _InputIter __l,
|
williamr@2
|
653 |
const __false_type&) {
|
williamr@2
|
654 |
return append(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
|
williamr@2
|
655 |
}
|
williamr@2
|
656 |
|
williamr@2
|
657 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
658 |
|
williamr@2
|
659 |
public: // Assign
|
williamr@2
|
660 |
|
williamr@2
|
661 |
_Self& assign(const _Self& __s)
|
williamr@2
|
662 |
{ return assign(__s._M_start, __s._M_finish); }
|
williamr@2
|
663 |
|
williamr@2
|
664 |
_Self& assign(const _Self& __s,
|
williamr@2
|
665 |
size_type __pos, size_type __n) {
|
williamr@2
|
666 |
if (__pos > __s.size())
|
williamr@2
|
667 |
this->_M_throw_out_of_range();
|
williamr@2
|
668 |
return assign(__s._M_start + __pos,
|
williamr@2
|
669 |
__s._M_start + __pos + (min) (__n, __s.size() - __pos));
|
williamr@2
|
670 |
}
|
williamr@2
|
671 |
|
williamr@2
|
672 |
_Self& assign(const _CharT* __s, size_type __n)
|
williamr@2
|
673 |
{ _STLP_FIX_LITERAL_BUG(__s) return assign(__s, __s + __n); }
|
williamr@2
|
674 |
|
williamr@2
|
675 |
_Self& assign(const _CharT* __s)
|
williamr@2
|
676 |
{ _STLP_FIX_LITERAL_BUG(__s) return assign(__s, __s + _Traits::length(__s)); }
|
williamr@2
|
677 |
|
williamr@2
|
678 |
_STLP_DECLSPEC _Self& assign(size_type __n, _CharT __c);
|
williamr@2
|
679 |
|
williamr@2
|
680 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
681 |
|
williamr@2
|
682 |
private: // Helper functions for assign.
|
williamr@2
|
683 |
|
williamr@2
|
684 |
template <class _Integer>
|
williamr@2
|
685 |
_Self& _M_assign_dispatch(_Integer __n, _Integer __x, const __true_type&) {
|
williamr@2
|
686 |
return assign((size_type) __n, (_CharT) __x);
|
williamr@2
|
687 |
}
|
williamr@2
|
688 |
|
williamr@2
|
689 |
template <class _InputIter>
|
williamr@2
|
690 |
_Self& _M_assign_dispatch(_InputIter __f, _InputIter __l,
|
williamr@2
|
691 |
const __false_type&) {
|
williamr@2
|
692 |
pointer __cur = this->_M_start;
|
williamr@2
|
693 |
while (__f != __l && __cur != this->_M_finish) {
|
williamr@2
|
694 |
_Traits::assign(*__cur, *__f);
|
williamr@2
|
695 |
++__f;
|
williamr@2
|
696 |
++__cur;
|
williamr@2
|
697 |
}
|
williamr@2
|
698 |
if (__f == __l)
|
williamr@2
|
699 |
erase(__cur, end());
|
williamr@2
|
700 |
else
|
williamr@2
|
701 |
append(__f, __l);
|
williamr@2
|
702 |
return *this;
|
williamr@2
|
703 |
}
|
williamr@2
|
704 |
|
williamr@2
|
705 |
public:
|
williamr@2
|
706 |
// Check to see if _InputIterator is an integer type. If so, then
|
williamr@2
|
707 |
// it can't be an iterator.
|
williamr@2
|
708 |
template <class _InputIter> _Self& assign(_InputIter __first, _InputIter __last) {
|
williamr@2
|
709 |
typedef typename _Is_integer<_InputIter>::_Integral _Integral;
|
williamr@2
|
710 |
return _M_assign_dispatch(__first, __last, _Integral());
|
williamr@2
|
711 |
}
|
williamr@2
|
712 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
713 |
|
williamr@2
|
714 |
// if member templates are on, this works as specialization
|
williamr@2
|
715 |
_Self& assign(const _CharT* __f, const _CharT* __l)
|
williamr@2
|
716 |
{
|
williamr@2
|
717 |
ptrdiff_t __n = __l - __f;
|
williamr@2
|
718 |
if (__STATIC_CAST(size_type,__n) <= size()) {
|
williamr@2
|
719 |
_Traits::copy(this->_M_start, __f, __n);
|
williamr@2
|
720 |
erase(begin() + __n, end());
|
williamr@2
|
721 |
}
|
williamr@2
|
722 |
else {
|
williamr@2
|
723 |
_Traits::copy(this->_M_start, __f, size());
|
williamr@2
|
724 |
append(__f + size(), __l);
|
williamr@2
|
725 |
}
|
williamr@2
|
726 |
return *this;
|
williamr@2
|
727 |
}
|
williamr@2
|
728 |
|
williamr@2
|
729 |
public: // Insert
|
williamr@2
|
730 |
|
williamr@2
|
731 |
_Self& insert(size_type __pos, const _Self& __s) {
|
williamr@2
|
732 |
if (__pos > size())
|
williamr@2
|
733 |
this->_M_throw_out_of_range();
|
williamr@2
|
734 |
if (size() > max_size() - __s.size())
|
williamr@2
|
735 |
this->_M_throw_length_error();
|
williamr@2
|
736 |
insert(begin() + __pos, __s._M_start, __s._M_finish);
|
williamr@2
|
737 |
return *this;
|
williamr@2
|
738 |
}
|
williamr@2
|
739 |
|
williamr@2
|
740 |
_Self& insert(size_type __pos, const _Self& __s,
|
williamr@2
|
741 |
size_type __beg, size_type __n) {
|
williamr@2
|
742 |
if (__pos > size() || __beg > __s.size())
|
williamr@2
|
743 |
this->_M_throw_out_of_range();
|
williamr@2
|
744 |
size_type __len = (min) (__n, __s.size() - __beg);
|
williamr@2
|
745 |
if (size() > max_size() - __len)
|
williamr@2
|
746 |
this->_M_throw_length_error();
|
williamr@2
|
747 |
insert(begin() + __pos,
|
williamr@2
|
748 |
__s._M_start + __beg, __s._M_start + __beg + __len);
|
williamr@2
|
749 |
return *this;
|
williamr@2
|
750 |
}
|
williamr@2
|
751 |
|
williamr@2
|
752 |
_Self& insert(size_type __pos, const _CharT* __s, size_type __n) {
|
williamr@2
|
753 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
754 |
if (__pos > size())
|
williamr@2
|
755 |
this->_M_throw_out_of_range();
|
williamr@2
|
756 |
if (size() > max_size() - __n)
|
williamr@2
|
757 |
this->_M_throw_length_error();
|
williamr@2
|
758 |
insert(begin() + __pos, __s, __s + __n);
|
williamr@2
|
759 |
return *this;
|
williamr@2
|
760 |
}
|
williamr@2
|
761 |
|
williamr@2
|
762 |
_Self& insert(size_type __pos, const _CharT* __s) {
|
williamr@2
|
763 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
764 |
if (__pos > size())
|
williamr@2
|
765 |
this->_M_throw_out_of_range();
|
williamr@2
|
766 |
size_type __len = _Traits::length(__s);
|
williamr@2
|
767 |
if (size() > max_size() - __len)
|
williamr@2
|
768 |
this->_M_throw_length_error();
|
williamr@2
|
769 |
insert(this->_M_start + __pos, __s, __s + __len);
|
williamr@2
|
770 |
return *this;
|
williamr@2
|
771 |
}
|
williamr@2
|
772 |
|
williamr@2
|
773 |
_Self& insert(size_type __pos, size_type __n, _CharT __c) {
|
williamr@2
|
774 |
if (__pos > size())
|
williamr@2
|
775 |
this->_M_throw_out_of_range();
|
williamr@2
|
776 |
if (size() > max_size() - __n)
|
williamr@2
|
777 |
this->_M_throw_length_error();
|
williamr@2
|
778 |
insert(begin() + __pos, __n, __c);
|
williamr@2
|
779 |
return *this;
|
williamr@2
|
780 |
}
|
williamr@2
|
781 |
|
williamr@2
|
782 |
iterator insert(iterator __p, _CharT __c) {
|
williamr@2
|
783 |
_STLP_FIX_LITERAL_BUG(__p)
|
williamr@2
|
784 |
if (__p == end()) {
|
williamr@2
|
785 |
push_back(__c);
|
williamr@2
|
786 |
return this->_M_finish - 1;
|
williamr@2
|
787 |
}
|
williamr@2
|
788 |
else
|
williamr@2
|
789 |
return _M_insert_aux(__p, __c);
|
williamr@2
|
790 |
}
|
williamr@2
|
791 |
|
williamr@2
|
792 |
void insert(iterator __p, size_t __n, _CharT __c);
|
williamr@2
|
793 |
|
williamr@2
|
794 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
795 |
|
williamr@2
|
796 |
// Check to see if _InputIterator is an integer type. If so, then
|
williamr@2
|
797 |
// it can't be an iterator.
|
williamr@2
|
798 |
template <class _InputIter> void insert(iterator __p, _InputIter __first, _InputIter __last) {
|
williamr@2
|
799 |
typedef typename _Is_integer<_InputIter>::_Integral _Integral;
|
williamr@2
|
800 |
_M_insert_dispatch(__p, __first, __last, _Integral());
|
williamr@2
|
801 |
}
|
williamr@2
|
802 |
|
williamr@2
|
803 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
804 |
|
williamr@2
|
805 |
_STLP_DECLSPEC void insert(iterator __p, const _CharT* __first, const _CharT* __last);
|
williamr@2
|
806 |
|
williamr@2
|
807 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
808 |
|
williamr@2
|
809 |
private: // Helper functions for insert.
|
williamr@2
|
810 |
|
williamr@2
|
811 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
812 |
|
williamr@2
|
813 |
template <class _InputIter> void insert(iterator __p, _InputIter __first, _InputIter __last,
|
williamr@2
|
814 |
const input_iterator_tag &)
|
williamr@2
|
815 |
{
|
williamr@2
|
816 |
for ( ; __first != __last; ++__first) {
|
williamr@2
|
817 |
__p = insert(__p, *__first);
|
williamr@2
|
818 |
++__p;
|
williamr@2
|
819 |
}
|
williamr@2
|
820 |
}
|
williamr@2
|
821 |
|
williamr@2
|
822 |
template <class _ForwardIter>
|
williamr@2
|
823 |
void insert(iterator __position, _ForwardIter __first, _ForwardIter __last,
|
williamr@2
|
824 |
const forward_iterator_tag &) {
|
williamr@2
|
825 |
if (__first != __last) {
|
williamr@2
|
826 |
difference_type __n = distance(__first, __last);
|
williamr@2
|
827 |
if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {
|
williamr@2
|
828 |
const difference_type __elems_after = this->_M_finish - __position;
|
williamr@2
|
829 |
pointer __old_finish = this->_M_finish;
|
williamr@2
|
830 |
if (__elems_after >= __n) {
|
williamr@2
|
831 |
uninitialized_copy((this->_M_finish - __n) + 1, this->_M_finish + 1,
|
williamr@2
|
832 |
this->_M_finish + 1);
|
williamr@2
|
833 |
this->_M_finish += __n;
|
williamr@2
|
834 |
_Traits::move(__position + __n,
|
williamr@2
|
835 |
__position, (__elems_after - __n) + 1);
|
williamr@2
|
836 |
_M_move(__first, __last, __position);
|
williamr@2
|
837 |
}
|
williamr@2
|
838 |
else {
|
williamr@2
|
839 |
_ForwardIter __mid = __first;
|
williamr@2
|
840 |
advance(__mid, __elems_after + 1);
|
williamr@2
|
841 |
uninitialized_copy(__mid, __last, this->_M_finish + 1);
|
williamr@2
|
842 |
this->_M_finish += __n - __elems_after;
|
williamr@2
|
843 |
_STLP_TRY {
|
williamr@2
|
844 |
uninitialized_copy(__position, __old_finish + 1, this->_M_finish);
|
williamr@2
|
845 |
this->_M_finish += __elems_after;
|
williamr@2
|
846 |
}
|
williamr@2
|
847 |
_STLP_UNWIND((_STLP_STD::_Destroy(__old_finish + 1, this->_M_finish),
|
williamr@2
|
848 |
this->_M_finish = __old_finish));
|
williamr@2
|
849 |
_M_move(__first, __mid, __position);
|
williamr@2
|
850 |
}
|
williamr@2
|
851 |
}
|
williamr@2
|
852 |
else {
|
williamr@2
|
853 |
const size_type __old_size = size();
|
williamr@2
|
854 |
const size_type __len
|
williamr@2
|
855 |
= __old_size + (max)(__old_size, __STATIC_CAST(size_type,__n)) + 1;
|
williamr@2
|
856 |
_STLP_LEAVE_VOLATILE pointer __new_start = this->_M_end_of_storage.allocate(__len);
|
williamr@2
|
857 |
_STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
|
williamr@2
|
858 |
_STLP_TRY {
|
williamr@2
|
859 |
__new_finish = uninitialized_copy(this->_M_start, __position, __new_start);
|
williamr@2
|
860 |
__new_finish = uninitialized_copy(__first, __last, __new_finish);
|
williamr@2
|
861 |
__new_finish
|
williamr@2
|
862 |
= uninitialized_copy(__position, this->_M_finish, __new_finish);
|
williamr@2
|
863 |
_M_construct_null(__new_finish);
|
williamr@2
|
864 |
}
|
williamr@2
|
865 |
_STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),
|
williamr@2
|
866 |
this->_M_end_of_storage.deallocate(__new_start,__len)));
|
williamr@2
|
867 |
_STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
|
williamr@2
|
868 |
this->_M_deallocate_block();
|
williamr@2
|
869 |
this->_M_start = __new_start;
|
williamr@2
|
870 |
this->_M_finish = __new_finish;
|
williamr@2
|
871 |
this->_M_end_of_storage._M_data = __new_start + __len;
|
williamr@2
|
872 |
}
|
williamr@2
|
873 |
}
|
williamr@2
|
874 |
}
|
williamr@2
|
875 |
|
williamr@2
|
876 |
template <class _Integer> void _M_insert_dispatch(iterator __p, _Integer __n, _Integer __x,
|
williamr@2
|
877 |
const __true_type&) {
|
williamr@2
|
878 |
insert(__p, (size_type) __n, (_CharT) __x);
|
williamr@2
|
879 |
}
|
williamr@2
|
880 |
|
williamr@2
|
881 |
template <class _InputIter> void _M_insert_dispatch(iterator __p, _InputIter __first, _InputIter __last,
|
williamr@2
|
882 |
const __false_type&) {
|
williamr@2
|
883 |
insert(__p, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
|
williamr@2
|
884 |
}
|
williamr@2
|
885 |
|
williamr@2
|
886 |
template <class _InputIterator> void
|
williamr@2
|
887 |
_M_copy(_InputIterator __first, _InputIterator __last, pointer __result) {
|
williamr@2
|
888 |
for ( ; __first != __last; ++__first, ++__result)
|
williamr@2
|
889 |
_Traits::assign(*__result, *__first);
|
williamr@2
|
890 |
}
|
williamr@2
|
891 |
|
williamr@2
|
892 |
template <class _InputIterator>
|
williamr@2
|
893 |
void _M_move(_InputIterator __first, _InputIterator __last, pointer __result) {
|
williamr@2
|
894 |
//call _M_copy as being here means that __result is not within [__first, __last)
|
williamr@2
|
895 |
for ( ; __first != __last; ++__first, ++__result)
|
williamr@2
|
896 |
_Traits::assign(*__result, *__first);
|
williamr@2
|
897 |
}
|
williamr@2
|
898 |
|
williamr@2
|
899 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
900 |
|
williamr@2
|
901 |
pointer _M_insert_aux(pointer, _CharT);
|
williamr@2
|
902 |
|
williamr@2
|
903 |
void
|
williamr@2
|
904 |
_M_copy(const _CharT* __first, const _CharT* __last, _CharT* __result) {
|
williamr@2
|
905 |
_Traits::copy(__result, __first, __last - __first);
|
williamr@2
|
906 |
}
|
williamr@2
|
907 |
void _M_move(const _CharT* __first, const _CharT* __last, _CharT* __result) {
|
williamr@2
|
908 |
_Traits::move(__result, __first, __last - __first);
|
williamr@2
|
909 |
}
|
williamr@2
|
910 |
|
williamr@2
|
911 |
public: // Erase.
|
williamr@2
|
912 |
|
williamr@2
|
913 |
_Self& erase(size_type __pos = 0, size_type __n = npos) {
|
williamr@2
|
914 |
if (__pos > size())
|
williamr@2
|
915 |
this->_M_throw_out_of_range();
|
williamr@2
|
916 |
erase(begin() + __pos, begin() + __pos + (min) (__n, size() - __pos));
|
williamr@2
|
917 |
return *this;
|
williamr@2
|
918 |
}
|
williamr@2
|
919 |
|
williamr@2
|
920 |
iterator erase(iterator __position) {
|
williamr@2
|
921 |
// The move includes the terminating _CharT().
|
williamr@2
|
922 |
_Traits::move(__position, __position + 1, this->_M_finish - __position);
|
williamr@2
|
923 |
_STLP_STD::_Destroy(this->_M_finish);
|
williamr@2
|
924 |
--this->_M_finish;
|
williamr@2
|
925 |
return __position;
|
williamr@2
|
926 |
}
|
williamr@2
|
927 |
|
williamr@2
|
928 |
iterator erase(iterator __first, iterator __last) {
|
williamr@2
|
929 |
if (__first != __last) {
|
williamr@2
|
930 |
// The move includes the terminating _CharT().
|
williamr@2
|
931 |
traits_type::move(__first, __last, (this->_M_finish - __last) + 1);
|
williamr@2
|
932 |
pointer __new_finish = this->_M_finish - (__last - __first);
|
williamr@2
|
933 |
_STLP_STD::_Destroy(__new_finish + 1, this->_M_finish + 1);
|
williamr@2
|
934 |
this->_M_finish = __new_finish;
|
williamr@2
|
935 |
}
|
williamr@2
|
936 |
return __first;
|
williamr@2
|
937 |
}
|
williamr@2
|
938 |
|
williamr@2
|
939 |
public: // Replace. (Conceptually equivalent
|
williamr@2
|
940 |
// to erase followed by insert.)
|
williamr@2
|
941 |
_Self& replace(size_type __pos, size_type __n,
|
williamr@2
|
942 |
const _Self& __s) {
|
williamr@2
|
943 |
if (__pos > size())
|
williamr@2
|
944 |
this->_M_throw_out_of_range();
|
williamr@2
|
945 |
const size_type __len = (min) (__n, size() - __pos);
|
williamr@2
|
946 |
if (size() - __len >= max_size() - __s.size())
|
williamr@2
|
947 |
this->_M_throw_length_error();
|
williamr@2
|
948 |
return replace(begin() + __pos, begin() + __pos + __len,
|
williamr@2
|
949 |
__s._M_start, __s._M_finish);
|
williamr@2
|
950 |
}
|
williamr@2
|
951 |
|
williamr@2
|
952 |
_Self& replace(size_type __pos1, size_type __n1,
|
williamr@2
|
953 |
const _Self& __s,
|
williamr@2
|
954 |
size_type __pos2, size_type __n2) {
|
williamr@2
|
955 |
if (__pos1 > size() || __pos2 > __s.size())
|
williamr@2
|
956 |
this->_M_throw_out_of_range();
|
williamr@2
|
957 |
const size_type __len1 = (min) (__n1, size() - __pos1);
|
williamr@2
|
958 |
const size_type __len2 = (min) (__n2, __s.size() - __pos2);
|
williamr@2
|
959 |
if (size() - __len1 >= max_size() - __len2)
|
williamr@2
|
960 |
this->_M_throw_length_error();
|
williamr@2
|
961 |
return replace(begin() + __pos1, begin() + __pos1 + __len1,
|
williamr@2
|
962 |
__s._M_start + __pos2, __s._M_start + __pos2 + __len2);
|
williamr@2
|
963 |
}
|
williamr@2
|
964 |
|
williamr@2
|
965 |
_Self& replace(size_type __pos, size_type __n1,
|
williamr@2
|
966 |
const _CharT* __s, size_type __n2) {
|
williamr@2
|
967 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
968 |
if (__pos > size())
|
williamr@2
|
969 |
this->_M_throw_out_of_range();
|
williamr@2
|
970 |
const size_type __len = (min) (__n1, size() - __pos);
|
williamr@2
|
971 |
if (__n2 > max_size() || size() - __len >= max_size() - __n2)
|
williamr@2
|
972 |
this->_M_throw_length_error();
|
williamr@2
|
973 |
return replace(begin() + __pos, begin() + __pos + __len,
|
williamr@2
|
974 |
__s, __s + __n2);
|
williamr@2
|
975 |
}
|
williamr@2
|
976 |
|
williamr@2
|
977 |
_Self& replace(size_type __pos, size_type __n1,
|
williamr@2
|
978 |
const _CharT* __s) {
|
williamr@2
|
979 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
980 |
if (__pos > size())
|
williamr@2
|
981 |
this->_M_throw_out_of_range();
|
williamr@2
|
982 |
const size_type __len = (min) (__n1, size() - __pos);
|
williamr@2
|
983 |
const size_type __n2 = _Traits::length(__s);
|
williamr@2
|
984 |
if (__n2 > max_size() || size() - __len >= max_size() - __n2)
|
williamr@2
|
985 |
this->_M_throw_length_error();
|
williamr@2
|
986 |
return replace(begin() + __pos, begin() + __pos + __len,
|
williamr@2
|
987 |
__s, __s + _Traits::length(__s));
|
williamr@2
|
988 |
}
|
williamr@2
|
989 |
|
williamr@2
|
990 |
_Self& replace(size_type __pos, size_type __n1,
|
williamr@2
|
991 |
size_type __n2, _CharT __c) {
|
williamr@2
|
992 |
if (__pos > size())
|
williamr@2
|
993 |
this->_M_throw_out_of_range();
|
williamr@2
|
994 |
const size_type __len = (min) (__n1, size() - __pos);
|
williamr@2
|
995 |
if (__n2 > max_size() || size() - __len >= max_size() - __n2)
|
williamr@2
|
996 |
this->_M_throw_length_error();
|
williamr@2
|
997 |
return replace(begin() + __pos, begin() + __pos + __len, __n2, __c);
|
williamr@2
|
998 |
}
|
williamr@2
|
999 |
|
williamr@2
|
1000 |
_Self& replace(iterator __first, iterator __last,
|
williamr@2
|
1001 |
const _Self& __s)
|
williamr@2
|
1002 |
{ return replace(__first, __last, __s._M_start, __s._M_finish); }
|
williamr@2
|
1003 |
|
williamr@2
|
1004 |
_Self& replace(iterator __first, iterator __last,
|
williamr@2
|
1005 |
const _CharT* __s, size_type __n)
|
williamr@2
|
1006 |
{ _STLP_FIX_LITERAL_BUG(__s) return replace(__first, __last, __s, __s + __n); }
|
williamr@2
|
1007 |
|
williamr@2
|
1008 |
_Self& replace(iterator __first, iterator __last,
|
williamr@2
|
1009 |
const _CharT* __s) {
|
williamr@2
|
1010 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1011 |
return replace(__first, __last, __s, __s + _Traits::length(__s));
|
williamr@2
|
1012 |
}
|
williamr@2
|
1013 |
|
williamr@2
|
1014 |
_Self& replace(iterator __first, iterator __last,
|
williamr@2
|
1015 |
size_type __n, _CharT __c);
|
williamr@2
|
1016 |
|
williamr@2
|
1017 |
// Check to see if _InputIterator is an integer type. If so, then
|
williamr@2
|
1018 |
// it can't be an iterator.
|
williamr@2
|
1019 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
1020 |
template <class _InputIter> _Self& replace(iterator __first, iterator __last,
|
williamr@2
|
1021 |
_InputIter __f, _InputIter __l) {
|
williamr@2
|
1022 |
typedef typename _Is_integer<_InputIter>::_Integral _Integral;
|
williamr@2
|
1023 |
return _M_replace_dispatch(__first, __last, __f, __l, _Integral());
|
williamr@2
|
1024 |
}
|
williamr@2
|
1025 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
1026 |
_Self& replace(iterator __first, iterator __last,
|
williamr@2
|
1027 |
const _CharT* __f, const _CharT* __l);
|
williamr@2
|
1028 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
1029 |
|
williamr@2
|
1030 |
private: // Helper functions for replace.
|
williamr@2
|
1031 |
|
williamr@2
|
1032 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
1033 |
|
williamr@2
|
1034 |
template <class _Integer> _Self& _M_replace_dispatch(iterator __first, iterator __last,
|
williamr@2
|
1035 |
_Integer __n, _Integer __x,
|
williamr@2
|
1036 |
const __true_type&) {
|
williamr@2
|
1037 |
return replace(__first, __last, (size_type) __n, (_CharT) __x);
|
williamr@2
|
1038 |
}
|
williamr@2
|
1039 |
|
williamr@2
|
1040 |
template <class _InputIter> _Self& _M_replace_dispatch(iterator __first, iterator __last,
|
williamr@2
|
1041 |
_InputIter __f, _InputIter __l,
|
williamr@2
|
1042 |
const __false_type&) {
|
williamr@2
|
1043 |
return replace(__first, __last, __f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
|
williamr@2
|
1044 |
}
|
williamr@2
|
1045 |
|
williamr@2
|
1046 |
template <class _InputIter> _Self& replace(iterator __first, iterator __last,
|
williamr@2
|
1047 |
_InputIter __f, _InputIter __l, const input_iterator_tag &) {
|
williamr@2
|
1048 |
for ( ; __first != __last && __f != __l; ++__first, ++__f)
|
williamr@2
|
1049 |
_Traits::assign(*__first, *__f);
|
williamr@2
|
1050 |
|
williamr@2
|
1051 |
if (__f == __l)
|
williamr@2
|
1052 |
erase(__first, __last);
|
williamr@2
|
1053 |
else
|
williamr@2
|
1054 |
insert(__last, __f, __l);
|
williamr@2
|
1055 |
return *this;
|
williamr@2
|
1056 |
}
|
williamr@2
|
1057 |
|
williamr@2
|
1058 |
template <class _InputIter>
|
williamr@2
|
1059 |
_Self& replace(iterator __first, iterator __last,
|
williamr@2
|
1060 |
_InputIter __f, _InputIter __l, const random_access_iterator_tag &) {
|
williamr@2
|
1061 |
//might be overlapping
|
williamr@2
|
1062 |
if (_M_inside(__f)) {
|
williamr@2
|
1063 |
difference_type __n = __l - __f;
|
williamr@2
|
1064 |
const difference_type __len = __last - __first;
|
williamr@2
|
1065 |
if (__len >= __n) {
|
williamr@2
|
1066 |
_M_move(__f, __l, __first);
|
williamr@2
|
1067 |
erase(__first + __n, __last);
|
williamr@2
|
1068 |
}
|
williamr@2
|
1069 |
else {
|
williamr@2
|
1070 |
_InputIter __m = __f + __len;
|
williamr@2
|
1071 |
if ((__l <= __first) || (__f >= __last)) {
|
williamr@2
|
1072 |
//no overlap:
|
williamr@2
|
1073 |
_M_copy(__f, __m, __first);
|
williamr@2
|
1074 |
insert(__last, __m, __l);
|
williamr@2
|
1075 |
}
|
williamr@2
|
1076 |
else {
|
williamr@2
|
1077 |
//we have to take care of reallocation:
|
williamr@2
|
1078 |
const difference_type __off_dest = __first - this->begin();
|
williamr@2
|
1079 |
const difference_type __off_src = __f - this->begin();
|
williamr@2
|
1080 |
insert(__last, __m, __l);
|
williamr@2
|
1081 |
_Traits::move(begin() + __off_dest, begin() + __off_src, __n);
|
williamr@2
|
1082 |
}
|
williamr@2
|
1083 |
}
|
williamr@2
|
1084 |
return *this;
|
williamr@2
|
1085 |
}
|
williamr@2
|
1086 |
else {
|
williamr@2
|
1087 |
return replace(__first, __last, __f, __l, forward_iterator_tag());
|
williamr@2
|
1088 |
}
|
williamr@2
|
1089 |
}
|
williamr@2
|
1090 |
|
williamr@2
|
1091 |
|
williamr@2
|
1092 |
template <class _ForwardIter> _Self& replace(iterator __first, iterator __last,
|
williamr@2
|
1093 |
_ForwardIter __f, _ForwardIter __l,
|
williamr@2
|
1094 |
const forward_iterator_tag &) {
|
williamr@2
|
1095 |
difference_type __n = distance(__f, __l);
|
williamr@2
|
1096 |
const difference_type __len = __last - __first;
|
williamr@2
|
1097 |
if (__len >= __n) {
|
williamr@2
|
1098 |
_M_copy(__f, __l, __first);
|
williamr@2
|
1099 |
erase(__first + __n, __last);
|
williamr@2
|
1100 |
}
|
williamr@2
|
1101 |
else {
|
williamr@2
|
1102 |
_ForwardIter __m = __f;
|
williamr@2
|
1103 |
advance(__m, __len);
|
williamr@2
|
1104 |
_M_copy(__f, __m, __first);
|
williamr@2
|
1105 |
insert(__last, __m, __l);
|
williamr@2
|
1106 |
}
|
williamr@2
|
1107 |
return *this;
|
williamr@2
|
1108 |
}
|
williamr@2
|
1109 |
|
williamr@2
|
1110 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
1111 |
|
williamr@2
|
1112 |
public: // Other modifier member functions.
|
williamr@2
|
1113 |
|
williamr@2
|
1114 |
size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const {
|
williamr@2
|
1115 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1116 |
if (__pos > size())
|
williamr@2
|
1117 |
this->_M_throw_out_of_range();
|
williamr@2
|
1118 |
const size_type __len = (min) (__n, size() - __pos);
|
williamr@2
|
1119 |
_Traits::copy(__s, this->_M_start + __pos, __len);
|
williamr@2
|
1120 |
return __len;
|
williamr@2
|
1121 |
}
|
williamr@2
|
1122 |
|
williamr@2
|
1123 |
void swap(_Self& __s) {
|
williamr@2
|
1124 |
_STLP_STD::swap(this->_M_start, __s._M_start);
|
williamr@2
|
1125 |
_STLP_STD::swap(this->_M_finish, __s._M_finish);
|
williamr@2
|
1126 |
_STLP_STD::swap(this->_M_end_of_storage, __s._M_end_of_storage);
|
williamr@2
|
1127 |
}
|
williamr@2
|
1128 |
|
williamr@2
|
1129 |
public: // Conversion to C string.
|
williamr@2
|
1130 |
|
williamr@2
|
1131 |
const _CharT* c_str() const { return this->_M_start; }
|
williamr@2
|
1132 |
const _CharT* data() const { return this->_M_start; }
|
williamr@2
|
1133 |
|
williamr@2
|
1134 |
public: // find.
|
williamr@2
|
1135 |
|
williamr@2
|
1136 |
size_type find(const _Self& __s, size_type __pos = 0) const
|
williamr@2
|
1137 |
{ return find(__s._M_start, __pos, __s.size()); }
|
williamr@2
|
1138 |
|
williamr@2
|
1139 |
size_type find(const _CharT* __s, size_type __pos = 0) const
|
williamr@2
|
1140 |
{ _STLP_FIX_LITERAL_BUG(__s) return find(__s, __pos, _Traits::length(__s)); }
|
williamr@2
|
1141 |
|
williamr@2
|
1142 |
_STLP_DECLSPEC size_type find(const _CharT* __s, size_type __pos, size_type __n) const;
|
williamr@2
|
1143 |
|
williamr@2
|
1144 |
// WIE: Versant schema compiler 5.2.2 ICE workaround
|
williamr@2
|
1145 |
size_type find(_CharT __c) const
|
williamr@2
|
1146 |
{ return find(__c, 0) ; }
|
williamr@2
|
1147 |
size_type find(_CharT __c, size_type __pos /* = 0 */) const;
|
williamr@2
|
1148 |
|
williamr@2
|
1149 |
public: // rfind.
|
williamr@2
|
1150 |
|
williamr@2
|
1151 |
size_type rfind(const _Self& __s, size_type __pos = npos) const
|
williamr@2
|
1152 |
{ return rfind(__s._M_start, __pos, __s.size()); }
|
williamr@2
|
1153 |
|
williamr@2
|
1154 |
size_type rfind(const _CharT* __s, size_type __pos = npos) const
|
williamr@2
|
1155 |
{ _STLP_FIX_LITERAL_BUG(__s) return rfind(__s, __pos, _Traits::length(__s)); }
|
williamr@2
|
1156 |
|
williamr@2
|
1157 |
_STLP_DECLSPEC size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const;
|
williamr@2
|
1158 |
_STLP_DECLSPEC size_type rfind(_CharT __c, size_type __pos = npos) const;
|
williamr@2
|
1159 |
|
williamr@2
|
1160 |
public: // find_first_of
|
williamr@2
|
1161 |
|
williamr@2
|
1162 |
size_type find_first_of(const _Self& __s, size_type __pos = 0) const
|
williamr@2
|
1163 |
{ return find_first_of(__s._M_start, __pos, __s.size()); }
|
williamr@2
|
1164 |
|
williamr@2
|
1165 |
size_type find_first_of(const _CharT* __s, size_type __pos = 0) const
|
williamr@2
|
1166 |
{ _STLP_FIX_LITERAL_BUG(__s) return find_first_of(__s, __pos, _Traits::length(__s)); }
|
williamr@2
|
1167 |
|
williamr@2
|
1168 |
_STLP_DECLSPEC size_type find_first_of(const _CharT* __s, size_type __pos,
|
williamr@2
|
1169 |
size_type __n) const;
|
williamr@2
|
1170 |
|
williamr@2
|
1171 |
size_type find_first_of(_CharT __c, size_type __pos = 0) const
|
williamr@2
|
1172 |
{ return find(__c, __pos); }
|
williamr@2
|
1173 |
|
williamr@2
|
1174 |
public: // find_last_of
|
williamr@2
|
1175 |
|
williamr@2
|
1176 |
size_type find_last_of(const _Self& __s,
|
williamr@2
|
1177 |
size_type __pos = npos) const
|
williamr@2
|
1178 |
{ return find_last_of(__s._M_start, __pos, __s.size()); }
|
williamr@2
|
1179 |
|
williamr@2
|
1180 |
size_type find_last_of(const _CharT* __s, size_type __pos = npos) const
|
williamr@2
|
1181 |
{ _STLP_FIX_LITERAL_BUG(__s) return find_last_of(__s, __pos, _Traits::length(__s)); }
|
williamr@2
|
1182 |
|
williamr@2
|
1183 |
_STLP_DECLSPEC size_type find_last_of(const _CharT* __s, size_type __pos,
|
williamr@2
|
1184 |
size_type __n) const;
|
williamr@2
|
1185 |
|
williamr@2
|
1186 |
size_type find_last_of(_CharT __c, size_type __pos = npos) const {
|
williamr@2
|
1187 |
return rfind(__c, __pos);
|
williamr@2
|
1188 |
}
|
williamr@2
|
1189 |
|
williamr@2
|
1190 |
public: // find_first_not_of
|
williamr@2
|
1191 |
|
williamr@2
|
1192 |
size_type find_first_not_of(const _Self& __s,
|
williamr@2
|
1193 |
size_type __pos = 0) const
|
williamr@2
|
1194 |
{ return find_first_not_of(__s._M_start, __pos, __s.size()); }
|
williamr@2
|
1195 |
|
williamr@2
|
1196 |
size_type find_first_not_of(const _CharT* __s, size_type __pos = 0) const
|
williamr@2
|
1197 |
{ _STLP_FIX_LITERAL_BUG(__s) return find_first_not_of(__s, __pos, _Traits::length(__s)); }
|
williamr@2
|
1198 |
|
williamr@2
|
1199 |
_STLP_DECLSPEC size_type find_first_not_of(const _CharT* __s, size_type __pos,
|
williamr@2
|
1200 |
size_type __n) const;
|
williamr@2
|
1201 |
|
williamr@2
|
1202 |
_STLP_DECLSPEC size_type find_first_not_of(_CharT __c, size_type __pos = 0) const;
|
williamr@2
|
1203 |
|
williamr@2
|
1204 |
public: // find_last_not_of
|
williamr@2
|
1205 |
|
williamr@2
|
1206 |
size_type find_last_not_of(const _Self& __s,
|
williamr@2
|
1207 |
size_type __pos = npos) const
|
williamr@2
|
1208 |
{ return find_last_not_of(__s._M_start, __pos, __s.size()); }
|
williamr@2
|
1209 |
|
williamr@2
|
1210 |
size_type find_last_not_of(const _CharT* __s, size_type __pos = npos) const
|
williamr@2
|
1211 |
{ _STLP_FIX_LITERAL_BUG(__s) return find_last_not_of(__s, __pos, _Traits::length(__s)); }
|
williamr@2
|
1212 |
|
williamr@2
|
1213 |
_STLP_DECLSPEC size_type find_last_not_of(const _CharT* __s, size_type __pos,
|
williamr@2
|
1214 |
size_type __n) const;
|
williamr@2
|
1215 |
|
williamr@2
|
1216 |
_STLP_DECLSPEC size_type find_last_not_of(_CharT __c, size_type __pos = npos) const;
|
williamr@2
|
1217 |
|
williamr@2
|
1218 |
public: // Substring.
|
williamr@2
|
1219 |
|
williamr@2
|
1220 |
_Self substr(size_type __pos = 0, size_type __n = npos) const {
|
williamr@2
|
1221 |
if (__pos > size())
|
williamr@2
|
1222 |
this->_M_throw_out_of_range();
|
williamr@2
|
1223 |
return _Self(this->_M_start + __pos,
|
williamr@2
|
1224 |
this->_M_start + __pos + (min) (__n, size() - __pos));
|
williamr@2
|
1225 |
}
|
williamr@2
|
1226 |
|
williamr@2
|
1227 |
public: // Compare
|
williamr@2
|
1228 |
|
williamr@2
|
1229 |
int compare(const _Self& __s) const
|
williamr@2
|
1230 |
{ return _M_compare(this->_M_start, this->_M_finish, __s._M_start, __s._M_finish); }
|
williamr@2
|
1231 |
|
williamr@2
|
1232 |
int compare(size_type __pos1, size_type __n1,
|
williamr@2
|
1233 |
const _Self& __s) const {
|
williamr@2
|
1234 |
if (__pos1 > size())
|
williamr@2
|
1235 |
this->_M_throw_out_of_range();
|
williamr@2
|
1236 |
return _M_compare(this->_M_start + __pos1,
|
williamr@2
|
1237 |
this->_M_start + __pos1 + (min) (__n1, size() - __pos1),
|
williamr@2
|
1238 |
__s._M_start, __s._M_finish);
|
williamr@2
|
1239 |
}
|
williamr@2
|
1240 |
|
williamr@2
|
1241 |
int compare(size_type __pos1, size_type __n1,
|
williamr@2
|
1242 |
const _Self& __s,
|
williamr@2
|
1243 |
size_type __pos2, size_type __n2) const {
|
williamr@2
|
1244 |
if (__pos1 > size() || __pos2 > __s.size())
|
williamr@2
|
1245 |
this->_M_throw_out_of_range();
|
williamr@2
|
1246 |
return _M_compare(this->_M_start + __pos1,
|
williamr@2
|
1247 |
this->_M_start + __pos1 + (min) (__n1, size() - __pos1),
|
williamr@2
|
1248 |
__s._M_start + __pos2,
|
williamr@2
|
1249 |
__s._M_start + __pos2 + (min) (__n2, __s.size() - __pos2));
|
williamr@2
|
1250 |
}
|
williamr@2
|
1251 |
|
williamr@2
|
1252 |
int compare(const _CharT* __s) const {
|
williamr@2
|
1253 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1254 |
return _M_compare(this->_M_start, this->_M_finish, __s, __s + _Traits::length(__s));
|
williamr@2
|
1255 |
}
|
williamr@2
|
1256 |
|
williamr@2
|
1257 |
int compare(size_type __pos1, size_type __n1, const _CharT* __s) const {
|
williamr@2
|
1258 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1259 |
if (__pos1 > size())
|
williamr@2
|
1260 |
this->_M_throw_out_of_range();
|
williamr@2
|
1261 |
return _M_compare(this->_M_start + __pos1,
|
williamr@2
|
1262 |
this->_M_start + __pos1 + (min) (__n1, size() - __pos1),
|
williamr@2
|
1263 |
__s, __s + _Traits::length(__s));
|
williamr@2
|
1264 |
}
|
williamr@2
|
1265 |
|
williamr@2
|
1266 |
int compare(size_type __pos1, size_type __n1, const _CharT* __s,
|
williamr@2
|
1267 |
size_type __n2) const {
|
williamr@2
|
1268 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1269 |
if (__pos1 > size())
|
williamr@2
|
1270 |
this->_M_throw_out_of_range();
|
williamr@2
|
1271 |
return _M_compare(this->_M_start + __pos1,
|
williamr@2
|
1272 |
this->_M_start + __pos1 + (min) (__n1, size() - __pos1),
|
williamr@2
|
1273 |
__s, __s + __n2);
|
williamr@2
|
1274 |
}
|
williamr@2
|
1275 |
|
williamr@2
|
1276 |
public: // Helper functions for compare.
|
williamr@2
|
1277 |
|
williamr@2
|
1278 |
static int _STLP_CALL _M_compare(const _CharT* __f1, const _CharT* __l1,
|
williamr@2
|
1279 |
const _CharT* __f2, const _CharT* __l2) {
|
williamr@2
|
1280 |
const ptrdiff_t __n1 = __l1 - __f1;
|
williamr@2
|
1281 |
const ptrdiff_t __n2 = __l2 - __f2;
|
williamr@2
|
1282 |
const int cmp = _Traits::compare(__f1, __f2, (min) (__n1, __n2));
|
williamr@2
|
1283 |
return cmp != 0 ? cmp : (__n1 < __n2 ? -1 : (__n1 > __n2 ? 1 : 0));
|
williamr@2
|
1284 |
}
|
williamr@2
|
1285 |
|
williamr@2
|
1286 |
#ifdef _STLP_IMPLICIT_STRING_TO_DESC
|
williamr@2
|
1287 |
public:
|
williamr@2
|
1288 |
operator _DescConv<_CharT>::DescT() const
|
williamr@2
|
1289 |
{
|
williamr@2
|
1290 |
return _DescConv<_CharT>::convert( c_str(), size() );
|
williamr@2
|
1291 |
}
|
williamr@2
|
1292 |
|
williamr@2
|
1293 |
#endif // _STLP_IMPLICIT_STRING_TO_DESC
|
williamr@2
|
1294 |
};
|
williamr@2
|
1295 |
|
williamr@2
|
1296 |
#if ! defined (_STLP_STATIC_CONST_INIT_BUG) && \
|
williamr@2
|
1297 |
__GNUC__ == 2 && __GNUC_MINOR__ == 96
|
williamr@2
|
1298 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
1299 |
const size_t basic_string<_CharT, _Traits, _Alloc>::npos = ~(size_t) 0;
|
williamr@2
|
1300 |
#endif
|
williamr@2
|
1301 |
|
williamr@2
|
1302 |
# if defined (_STLP_USE_TEMPLATE_EXPORT)
|
williamr@2
|
1303 |
_STLP_EXPORT_TEMPLATE_CLASS basic_string<char, char_traits<char>, allocator<char> >;
|
williamr@2
|
1304 |
# if defined (_STLP_HAS_WCHAR_T)
|
williamr@2
|
1305 |
_STLP_EXPORT_TEMPLATE_CLASS basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
|
williamr@2
|
1306 |
# endif
|
williamr@2
|
1307 |
# endif /* _STLP_USE_TEMPLATE_EXPORT */
|
williamr@2
|
1308 |
|
williamr@2
|
1309 |
// ------------------------------------------------------------
|
williamr@2
|
1310 |
// Non-member functions.
|
williamr@2
|
1311 |
|
williamr@2
|
1312 |
template <class _CharT, class _Traits, class _Alloc> inline basic_string<_CharT,_Traits,_Alloc> _STLP_CALL
|
williamr@2
|
1313 |
operator+(const basic_string<_CharT,_Traits,_Alloc>& __s,
|
williamr@2
|
1314 |
const basic_string<_CharT,_Traits,_Alloc>& __y)
|
williamr@2
|
1315 |
{
|
williamr@2
|
1316 |
typedef basic_string<_CharT,_Traits,_Alloc> _Str;
|
williamr@2
|
1317 |
typedef typename _Str::_Reserve_t _Reserve_t;
|
williamr@4
|
1318 |
# if defined( __GNUC__ ) || defined (__GCCXML__)
|
williamr@2
|
1319 |
// gcc counts this as a function
|
williamr@2
|
1320 |
_Str __result = _Str(_Reserve_t(),__s.size() + __y.size());
|
williamr@2
|
1321 |
# else
|
williamr@2
|
1322 |
_Str __result(_Reserve_t(), __s.size() + __y.size());
|
williamr@2
|
1323 |
# endif
|
williamr@2
|
1324 |
__result.append(__s);
|
williamr@2
|
1325 |
__result.append(__y);
|
williamr@2
|
1326 |
return __result;
|
williamr@2
|
1327 |
}
|
williamr@2
|
1328 |
|
williamr@2
|
1329 |
# if defined (__GNUC__) || defined (__MLCCPP__)
|
williamr@2
|
1330 |
# define _STLP_INIT_AMBIGUITY 1
|
williamr@2
|
1331 |
# endif
|
williamr@2
|
1332 |
|
williamr@2
|
1333 |
template <class _CharT, class _Traits, class _Alloc> inline basic_string<_CharT,_Traits,_Alloc> _STLP_CALL
|
williamr@2
|
1334 |
operator+(const _CharT* __s,
|
williamr@2
|
1335 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1336 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1337 |
typedef basic_string<_CharT,_Traits,_Alloc> _Str;
|
williamr@2
|
1338 |
typedef typename _Str::_Reserve_t _Reserve_t;
|
williamr@2
|
1339 |
const size_t __n = _Traits::length(__s);
|
williamr@2
|
1340 |
# ifdef _STLP_INIT_AMBIGUITY
|
williamr@2
|
1341 |
_Str __result = _Str(_Reserve_t(), __n + __y.size());
|
williamr@2
|
1342 |
# else
|
williamr@2
|
1343 |
_Str __result(_Reserve_t(), __n + __y.size());
|
williamr@2
|
1344 |
# endif
|
williamr@2
|
1345 |
__result.append(__s, __s + __n);
|
williamr@2
|
1346 |
__result.append(__y);
|
williamr@2
|
1347 |
return __result;
|
williamr@2
|
1348 |
}
|
williamr@2
|
1349 |
|
williamr@2
|
1350 |
template <class _CharT, class _Traits, class _Alloc> inline basic_string<_CharT,_Traits,_Alloc> _STLP_CALL
|
williamr@2
|
1351 |
operator+(_CharT __c,
|
williamr@2
|
1352 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1353 |
typedef basic_string<_CharT,_Traits,_Alloc> _Str;
|
williamr@2
|
1354 |
typedef typename _Str::_Reserve_t _Reserve_t;
|
williamr@2
|
1355 |
# ifdef _STLP_INIT_AMBIGUITY
|
williamr@2
|
1356 |
_Str __result = _Str(_Reserve_t(), 1 + __y.size());
|
williamr@2
|
1357 |
# else
|
williamr@2
|
1358 |
_Str __result(_Reserve_t(), 1 + __y.size());
|
williamr@2
|
1359 |
# endif
|
williamr@2
|
1360 |
__result.push_back(__c);
|
williamr@2
|
1361 |
__result.append(__y);
|
williamr@2
|
1362 |
return __result;
|
williamr@2
|
1363 |
}
|
williamr@2
|
1364 |
|
williamr@2
|
1365 |
template <class _CharT, class _Traits, class _Alloc> inline basic_string<_CharT,_Traits,_Alloc> _STLP_CALL
|
williamr@2
|
1366 |
operator+(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1367 |
const _CharT* __s) {
|
williamr@2
|
1368 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1369 |
typedef basic_string<_CharT,_Traits,_Alloc> _Str;
|
williamr@2
|
1370 |
typedef typename _Str::_Reserve_t _Reserve_t;
|
williamr@2
|
1371 |
const size_t __n = _Traits::length(__s);
|
williamr@2
|
1372 |
# ifdef _STLP_INIT_AMBIGUITY
|
williamr@2
|
1373 |
_Str __result = _Str(_Reserve_t(), __x.size() + __n, __x.get_allocator());
|
williamr@2
|
1374 |
# else
|
williamr@2
|
1375 |
_Str __result(_Reserve_t(), __x.size() + __n, __x.get_allocator());
|
williamr@2
|
1376 |
# endif
|
williamr@2
|
1377 |
__result.append(__x);
|
williamr@2
|
1378 |
__result.append(__s, __s + __n);
|
williamr@2
|
1379 |
return __result;
|
williamr@2
|
1380 |
}
|
williamr@2
|
1381 |
|
williamr@2
|
1382 |
template <class _CharT, class _Traits, class _Alloc> inline basic_string<_CharT,_Traits,_Alloc> _STLP_CALL
|
williamr@2
|
1383 |
operator+(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1384 |
const _CharT __c) {
|
williamr@2
|
1385 |
typedef basic_string<_CharT,_Traits,_Alloc> _Str;
|
williamr@2
|
1386 |
typedef typename _Str::_Reserve_t _Reserve_t;
|
williamr@2
|
1387 |
# ifdef _STLP_INIT_AMBIGUITY
|
williamr@2
|
1388 |
_Str __result = _Str(_Reserve_t(), __x.size() + 1, __x.get_allocator());
|
williamr@2
|
1389 |
# else
|
williamr@2
|
1390 |
_Str __result(_Reserve_t(), __x.size() + 1, __x.get_allocator());
|
williamr@2
|
1391 |
# endif
|
williamr@2
|
1392 |
__result.append(__x);
|
williamr@2
|
1393 |
__result.push_back(__c);
|
williamr@2
|
1394 |
return __result;
|
williamr@2
|
1395 |
}
|
williamr@2
|
1396 |
|
williamr@2
|
1397 |
# undef _STLP_INIT_AMBIGUITY
|
williamr@2
|
1398 |
|
williamr@2
|
1399 |
// Operator== and operator!=
|
williamr@2
|
1400 |
|
williamr@2
|
1401 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1402 |
operator==(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1403 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1404 |
return __x.size() == __y.size() && _Traits::compare(__x.data(), __y.data(), __x.size()) == 0;
|
williamr@2
|
1405 |
}
|
williamr@2
|
1406 |
|
williamr@2
|
1407 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1408 |
operator==(const _CharT* __s,
|
williamr@2
|
1409 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1410 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1411 |
size_t __n = _Traits::length(__s);
|
williamr@2
|
1412 |
return __n == __y.size() && _Traits::compare(__s, __y.data(), __n) == 0;
|
williamr@2
|
1413 |
}
|
williamr@2
|
1414 |
|
williamr@2
|
1415 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1416 |
operator==(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1417 |
const _CharT* __s) {
|
williamr@2
|
1418 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1419 |
size_t __n = _Traits::length(__s);
|
williamr@2
|
1420 |
return __x.size() == __n && _Traits::compare(__x.data(), __s, __n) == 0;
|
williamr@2
|
1421 |
}
|
williamr@2
|
1422 |
|
williamr@2
|
1423 |
// Operator< (and also >, <=, and >=).
|
williamr@2
|
1424 |
|
williamr@2
|
1425 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1426 |
operator<(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1427 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1428 |
return basic_string<_CharT,_Traits,_Alloc> ::_M_compare(__x.begin(), __x.end(),
|
williamr@2
|
1429 |
__y.begin(), __y.end()) < 0;
|
williamr@2
|
1430 |
}
|
williamr@2
|
1431 |
|
williamr@2
|
1432 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1433 |
operator<(const _CharT* __s,
|
williamr@2
|
1434 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1435 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1436 |
size_t __n = _Traits::length(__s);
|
williamr@2
|
1437 |
return basic_string<_CharT,_Traits,_Alloc> ::_M_compare(__s, __s + __n, __y.begin(), __y.end()) < 0;
|
williamr@2
|
1438 |
}
|
williamr@2
|
1439 |
|
williamr@2
|
1440 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1441 |
operator<(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1442 |
const _CharT* __s) {
|
williamr@2
|
1443 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1444 |
size_t __n = _Traits::length(__s);
|
williamr@2
|
1445 |
return basic_string<_CharT,_Traits,_Alloc> ::_M_compare(__x.begin(), __x.end(), __s, __s + __n) < 0;
|
williamr@2
|
1446 |
}
|
williamr@2
|
1447 |
|
williamr@2
|
1448 |
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
|
williamr@2
|
1449 |
|
williamr@2
|
1450 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1451 |
operator!=(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1452 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1453 |
return !(__x == __y);
|
williamr@2
|
1454 |
}
|
williamr@2
|
1455 |
|
williamr@2
|
1456 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1457 |
operator>(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1458 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1459 |
return __y < __x;
|
williamr@2
|
1460 |
}
|
williamr@2
|
1461 |
|
williamr@2
|
1462 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1463 |
operator<=(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1464 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1465 |
return !(__y < __x);
|
williamr@2
|
1466 |
}
|
williamr@2
|
1467 |
|
williamr@2
|
1468 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1469 |
operator>=(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1470 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1471 |
return !(__x < __y);
|
williamr@2
|
1472 |
}
|
williamr@2
|
1473 |
|
williamr@2
|
1474 |
#endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
|
williamr@2
|
1475 |
|
williamr@2
|
1476 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1477 |
operator!=(const _CharT* __s,
|
williamr@2
|
1478 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1479 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1480 |
return !(__s == __y);
|
williamr@2
|
1481 |
}
|
williamr@2
|
1482 |
|
williamr@2
|
1483 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1484 |
operator!=(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1485 |
const _CharT* __s) {
|
williamr@2
|
1486 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1487 |
return !(__x == __s);
|
williamr@2
|
1488 |
}
|
williamr@2
|
1489 |
|
williamr@2
|
1490 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1491 |
operator>(const _CharT* __s,
|
williamr@2
|
1492 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1493 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1494 |
return __y < __s;
|
williamr@2
|
1495 |
}
|
williamr@2
|
1496 |
|
williamr@2
|
1497 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1498 |
operator>(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1499 |
const _CharT* __s) {
|
williamr@2
|
1500 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1501 |
return __s < __x;
|
williamr@2
|
1502 |
}
|
williamr@2
|
1503 |
|
williamr@2
|
1504 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1505 |
operator<=(const _CharT* __s,
|
williamr@2
|
1506 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1507 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1508 |
return !(__y < __s);
|
williamr@2
|
1509 |
}
|
williamr@2
|
1510 |
|
williamr@2
|
1511 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1512 |
operator<=(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1513 |
const _CharT* __s) {
|
williamr@2
|
1514 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1515 |
return !(__s < __x);
|
williamr@2
|
1516 |
}
|
williamr@2
|
1517 |
|
williamr@2
|
1518 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1519 |
operator>=(const _CharT* __s,
|
williamr@2
|
1520 |
const basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1521 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1522 |
return !(__s < __y);
|
williamr@2
|
1523 |
}
|
williamr@2
|
1524 |
|
williamr@2
|
1525 |
template <class _CharT, class _Traits, class _Alloc> inline bool _STLP_CALL
|
williamr@2
|
1526 |
operator>=(const basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1527 |
const _CharT* __s) {
|
williamr@2
|
1528 |
_STLP_FIX_LITERAL_BUG(__s)
|
williamr@2
|
1529 |
return !(__x < __s);
|
williamr@2
|
1530 |
}
|
williamr@2
|
1531 |
|
williamr@2
|
1532 |
|
williamr@2
|
1533 |
// Swap.
|
williamr@2
|
1534 |
|
williamr@2
|
1535 |
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
|
williamr@2
|
1536 |
|
williamr@2
|
1537 |
template <class _CharT, class _Traits, class _Alloc> inline void _STLP_CALL
|
williamr@2
|
1538 |
swap(basic_string<_CharT,_Traits,_Alloc>& __x,
|
williamr@2
|
1539 |
basic_string<_CharT,_Traits,_Alloc>& __y) {
|
williamr@2
|
1540 |
__x.swap(__y);
|
williamr@2
|
1541 |
}
|
williamr@2
|
1542 |
|
williamr@2
|
1543 |
#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
|
williamr@2
|
1544 |
|
williamr@2
|
1545 |
template <class _CharT, class _Traits, class _Alloc> void _STLP_CALL _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s,
|
williamr@2
|
1546 |
_CharT* __buf,
|
williamr@2
|
1547 |
size_t __n);
|
williamr@2
|
1548 |
|
williamr@2
|
1549 |
# undef basic_string
|
williamr@2
|
1550 |
|
williamr@2
|
1551 |
#if defined(_STLP_WINCE)
|
williamr@2
|
1552 |
// A couple of functions to transfer between ASCII/Unicode
|
williamr@2
|
1553 |
|
williamr@2
|
1554 |
wstring __ASCIIToWide(const char *ascii);
|
williamr@2
|
1555 |
string __WideToASCII(const wchar_t *wide);
|
williamr@2
|
1556 |
#endif
|
williamr@2
|
1557 |
|
williamr@2
|
1558 |
_STLP_END_NAMESPACE
|
williamr@2
|
1559 |
|
williamr@2
|
1560 |
# ifdef _STLP_DEBUG
|
williamr@2
|
1561 |
# include <stl/debug/_string.h>
|
williamr@2
|
1562 |
# endif
|
williamr@2
|
1563 |
|
williamr@2
|
1564 |
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
|
williamr@2
|
1565 |
# include <stl/_string.c>
|
williamr@2
|
1566 |
# endif
|
williamr@2
|
1567 |
|
williamr@2
|
1568 |
#ifndef _STLP_NO_IOSTREAMS
|
williamr@2
|
1569 |
# include <stl/_string_io.h>
|
williamr@2
|
1570 |
#endif
|
williamr@2
|
1571 |
|
williamr@2
|
1572 |
# include <stl/_string_hash.h>
|
williamr@2
|
1573 |
|
williamr@2
|
1574 |
#endif /* _STLP_STRING_H */
|
williamr@2
|
1575 |
|
williamr@2
|
1576 |
|
williamr@2
|
1577 |
// Local Variables:
|
williamr@2
|
1578 |
// mode:C++
|
williamr@2
|
1579 |
// End:
|