williamr@4
|
1 |
/*
|
williamr@4
|
2 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
williamr@4
|
3 |
* Copyright (c) 1999
|
williamr@4
|
4 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@4
|
5 |
*
|
williamr@4
|
6 |
* Copyright (c) 1999
|
williamr@4
|
7 |
* Boris Fomitchev
|
williamr@4
|
8 |
*
|
williamr@4
|
9 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@4
|
10 |
* or implied. Any use is at your own risk.
|
williamr@4
|
11 |
*
|
williamr@4
|
12 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@4
|
13 |
* without fee, provided the above notices are retained on all copies.
|
williamr@4
|
14 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@4
|
15 |
* provided the above notices are retained, and a notice that the code was
|
williamr@4
|
16 |
* modified is included with the above copyright notice.
|
williamr@4
|
17 |
*
|
williamr@4
|
18 |
*/
|
williamr@4
|
19 |
|
williamr@4
|
20 |
#ifndef _STLP_SSTREAM_C
|
williamr@4
|
21 |
#define _STLP_SSTREAM_C
|
williamr@4
|
22 |
|
williamr@4
|
23 |
#ifndef _STLP_SSTREAM_H
|
williamr@4
|
24 |
# include <stl/_sstream.h>
|
williamr@4
|
25 |
#include <stl/_stdio_file.h>
|
williamr@4
|
26 |
#endif
|
williamr@4
|
27 |
|
williamr@4
|
28 |
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
|
williamr@4
|
29 |
|
williamr@4
|
30 |
# if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
|
williamr@4
|
31 |
// no wint_t is supported for this mode
|
williamr@4
|
32 |
# define __BSB_int_type__ int
|
williamr@4
|
33 |
# define __BSB_pos_type__ streampos
|
williamr@4
|
34 |
# else
|
williamr@4
|
35 |
# define __BSB_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
|
williamr@4
|
36 |
# define __BSB_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
|
williamr@4
|
37 |
# endif
|
williamr@4
|
38 |
|
williamr@4
|
39 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
40 |
|
williamr@4
|
41 |
//----------------------------------------------------------------------
|
williamr@4
|
42 |
// Non-inline stringbuf member functions.
|
williamr@4
|
43 |
|
williamr@4
|
44 |
// Constructors. Note that the base class constructor sets all of the
|
williamr@4
|
45 |
// get and area pointers to null.
|
williamr@4
|
46 |
|
williamr@4
|
47 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
48 |
_STLP_EXP_DECLSPEC basic_stringbuf<_CharT, _Traits, _Alloc>
|
williamr@4
|
49 |
::basic_stringbuf(ios_base::openmode __mode)
|
williamr@4
|
50 |
: basic_streambuf<_CharT, _Traits>(), _M_mode(__mode), _M_str()
|
williamr@4
|
51 |
{
|
williamr@4
|
52 |
#ifdef __SYMBIAN32__
|
williamr@4
|
53 |
if (_M_mode & ios_base::out) {
|
williamr@4
|
54 |
if (_M_mode & (ios_base::app | ios_base::ate))
|
williamr@4
|
55 |
//increment the streampos to reflect the current streampos while writing
|
williamr@4
|
56 |
_M_str._M_stream_pos += _M_str.size();
|
williamr@4
|
57 |
}
|
williamr@4
|
58 |
#endif
|
williamr@4
|
59 |
}
|
williamr@4
|
60 |
|
williamr@4
|
61 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
62 |
_STLP_EXP_DECLSPEC basic_stringbuf<_CharT, _Traits, _Alloc>
|
williamr@4
|
63 |
::basic_stringbuf(const basic_string<_CharT, _Traits, _Alloc>& __s, ios_base::openmode __mode)
|
williamr@4
|
64 |
: basic_streambuf<_CharT, _Traits>(), _M_mode(__mode), _M_str(__s)
|
williamr@4
|
65 |
{
|
williamr@4
|
66 |
#ifdef __SYMBIAN32__
|
williamr@4
|
67 |
if (_M_mode & ios_base::out) {
|
williamr@4
|
68 |
if (_M_mode & (ios_base::app | ios_base::ate))
|
williamr@4
|
69 |
//increment the streampos to reflect the current streampos while writing
|
williamr@4
|
70 |
_M_str._M_stream_pos += _M_str.size();
|
williamr@4
|
71 |
}
|
williamr@4
|
72 |
#endif
|
williamr@4
|
73 |
_M_set_ptrs();
|
williamr@4
|
74 |
}
|
williamr@4
|
75 |
|
williamr@4
|
76 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
77 |
_STLP_EXP_DECLSPEC basic_stringbuf<_CharT, _Traits, _Alloc>::~basic_stringbuf()
|
williamr@4
|
78 |
{}
|
williamr@4
|
79 |
|
williamr@4
|
80 |
// Set the underlying string to a new value.
|
williamr@4
|
81 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
82 |
_STLP_EXP_DECLSPEC void
|
williamr@4
|
83 |
basic_stringbuf<_CharT, _Traits, _Alloc>::str(const basic_string<_CharT, _Traits, _Alloc>& __s)
|
williamr@4
|
84 |
{
|
williamr@4
|
85 |
_M_str = __s;
|
williamr@4
|
86 |
_M_set_ptrs();
|
williamr@4
|
87 |
}
|
williamr@4
|
88 |
|
williamr@4
|
89 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
90 |
void
|
williamr@4
|
91 |
basic_stringbuf<_CharT, _Traits, _Alloc>::_M_set_ptrs() {
|
williamr@4
|
92 |
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
|
williamr@4
|
93 |
_CharT* __data_end = __data_ptr + _M_str.size();
|
williamr@4
|
94 |
// The initial read position is the beginning of the string.
|
williamr@4
|
95 |
if (_M_mode & ios_base::in) {
|
williamr@4
|
96 |
if (_M_mode & ios_base::ate)
|
williamr@4
|
97 |
this->setg(__data_ptr, __data_end, __data_end);
|
williamr@4
|
98 |
else
|
williamr@4
|
99 |
this->setg(__data_ptr, __data_ptr, __data_end);
|
williamr@4
|
100 |
}
|
williamr@4
|
101 |
|
williamr@4
|
102 |
// The initial write position is the beginning of the string.
|
williamr@4
|
103 |
if (_M_mode & ios_base::out) {
|
williamr@4
|
104 |
if (_M_mode & (ios_base::app | ios_base::ate))
|
williamr@4
|
105 |
this->setp(__data_end, __data_end);
|
williamr@4
|
106 |
else
|
williamr@4
|
107 |
this->setp(__data_ptr, __data_end);
|
williamr@4
|
108 |
}
|
williamr@4
|
109 |
}
|
williamr@4
|
110 |
|
williamr@4
|
111 |
// Precondition: gptr() >= egptr(). Returns a character, if one is available.
|
williamr@4
|
112 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
113 |
_STLP_EXP_DECLSPEC __BSB_int_type__
|
williamr@4
|
114 |
basic_stringbuf<_CharT, _Traits, _Alloc>::underflow()
|
williamr@4
|
115 |
{
|
williamr@4
|
116 |
return this->gptr() != this->egptr()
|
williamr@4
|
117 |
? _Traits::to_int_type(*this->gptr())
|
williamr@4
|
118 |
: _Traits::eof();
|
williamr@4
|
119 |
}
|
williamr@4
|
120 |
|
williamr@4
|
121 |
// Precondition: gptr() >= egptr().
|
williamr@4
|
122 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
123 |
_STLP_EXP_DECLSPEC __BSB_int_type__
|
williamr@4
|
124 |
basic_stringbuf<_CharT, _Traits, _Alloc>::uflow()
|
williamr@4
|
125 |
{
|
williamr@4
|
126 |
if (this->gptr() != this->egptr()) {
|
williamr@4
|
127 |
int_type __c = _Traits::to_int_type(*this->gptr());
|
williamr@4
|
128 |
this->gbump(1);
|
williamr@4
|
129 |
return __c;
|
williamr@4
|
130 |
}
|
williamr@4
|
131 |
else
|
williamr@4
|
132 |
return _Traits::eof();
|
williamr@4
|
133 |
}
|
williamr@4
|
134 |
|
williamr@4
|
135 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
136 |
_STLP_EXP_DECLSPEC __BSB_int_type__
|
williamr@4
|
137 |
basic_stringbuf<_CharT, _Traits, _Alloc>::pbackfail(int_type __c)
|
williamr@4
|
138 |
{
|
williamr@4
|
139 |
if (this->gptr() != this->eback()) {
|
williamr@4
|
140 |
if (!_Traits::eq_int_type(__c, _Traits::eof())) {
|
williamr@4
|
141 |
|
williamr@4
|
142 |
if (_Traits::eq(_Traits::to_char_type(__c), this->gptr()[-1])
|
williamr@4
|
143 |
|| _M_mode == (ios_base::in | ios_base::out)) {
|
williamr@4
|
144 |
this->gbump(-1);
|
williamr@4
|
145 |
*this->gptr() = _Traits::to_char_type(__c);
|
williamr@4
|
146 |
return _Traits::not_eof(__c);
|
williamr@4
|
147 |
}
|
williamr@4
|
148 |
else{
|
williamr@4
|
149 |
return _Traits::eof();
|
williamr@4
|
150 |
}
|
williamr@4
|
151 |
}
|
williamr@4
|
152 |
else {
|
williamr@4
|
153 |
this->gbump(-1);
|
williamr@4
|
154 |
return _Traits::not_eof(__c);
|
williamr@4
|
155 |
}
|
williamr@4
|
156 |
}
|
williamr@4
|
157 |
else
|
williamr@4
|
158 |
return _Traits::eof();
|
williamr@4
|
159 |
}
|
williamr@4
|
160 |
|
williamr@4
|
161 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
162 |
_STLP_EXP_DECLSPEC __BSB_int_type__
|
williamr@4
|
163 |
basic_stringbuf<_CharT, _Traits, _Alloc>::overflow(int_type __c)
|
williamr@4
|
164 |
{
|
williamr@4
|
165 |
// fbp : reverse order of "ifs" to pass Dietmar's test.
|
williamr@4
|
166 |
// Apparently, standard allows overflow with eof even for read-only streams.
|
williamr@4
|
167 |
if (!_Traits::eq_int_type(__c, _Traits::eof())) {
|
williamr@4
|
168 |
if (_M_mode & ios_base::out) {
|
williamr@4
|
169 |
if (!(_M_mode & ios_base::in)) {
|
williamr@4
|
170 |
// It's a write-only streambuf, so we can use special append buffer.
|
williamr@4
|
171 |
if (this->pptr() == this->epptr())
|
williamr@4
|
172 |
this->_M_append_buffer();
|
williamr@4
|
173 |
|
williamr@4
|
174 |
if (this->pptr() != this->epptr()) {
|
williamr@4
|
175 |
*this->pptr() = _Traits::to_char_type(__c);
|
williamr@4
|
176 |
this->pbump(1);
|
williamr@4
|
177 |
return __c;
|
williamr@4
|
178 |
}
|
williamr@4
|
179 |
else
|
williamr@4
|
180 |
return _Traits::eof();
|
williamr@4
|
181 |
}
|
williamr@4
|
182 |
|
williamr@4
|
183 |
else {
|
williamr@4
|
184 |
// We're not using a special append buffer, just the string itself.
|
williamr@4
|
185 |
if (this->pptr() == this->epptr()) {
|
williamr@4
|
186 |
ptrdiff_t __offset = this->gptr() - this->eback();
|
williamr@4
|
187 |
_M_str.push_back(_Traits::to_char_type(__c));
|
williamr@4
|
188 |
|
williamr@4
|
189 |
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
|
williamr@4
|
190 |
size_t __data_size = _M_str.size();
|
williamr@4
|
191 |
|
williamr@4
|
192 |
this->setg(__data_ptr, __data_ptr + __offset, __data_ptr+__data_size);
|
williamr@4
|
193 |
this->setp(__data_ptr, __data_ptr + __data_size);
|
williamr@4
|
194 |
this->pbump((int)__data_size);
|
williamr@4
|
195 |
return __c;
|
williamr@4
|
196 |
}
|
williamr@4
|
197 |
else {
|
williamr@4
|
198 |
*this->pptr() = _Traits::to_char_type(__c);
|
williamr@4
|
199 |
this->pbump(1);
|
williamr@4
|
200 |
return __c;
|
williamr@4
|
201 |
}
|
williamr@4
|
202 |
}
|
williamr@4
|
203 |
}
|
williamr@4
|
204 |
else // Overflow always fails if it's read-only
|
williamr@4
|
205 |
return _Traits::eof();
|
williamr@4
|
206 |
}
|
williamr@4
|
207 |
else // __c is EOF, so we don't have to do anything
|
williamr@4
|
208 |
return _Traits::not_eof(__c);
|
williamr@4
|
209 |
}
|
williamr@4
|
210 |
|
williamr@4
|
211 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
212 |
_STLP_EXP_DECLSPEC streamsize
|
williamr@4
|
213 |
basic_stringbuf<_CharT, _Traits, _Alloc>::xsputn(const char_type* __s,
|
williamr@4
|
214 |
streamsize __n)
|
williamr@4
|
215 |
{
|
williamr@4
|
216 |
streamsize __nwritten = 0;
|
williamr@4
|
217 |
|
williamr@4
|
218 |
if ((_M_mode & ios_base::out) && __n > 0) {
|
williamr@4
|
219 |
// If the put pointer is somewhere in the middle of the string,
|
williamr@4
|
220 |
// then overwrite instead of append.
|
williamr@4
|
221 |
if (this->pbase() == _M_str.data() ) {
|
williamr@4
|
222 |
ptrdiff_t __avail = _M_str.data() + _M_str.size() - this->pptr();
|
williamr@4
|
223 |
if (__avail > __n) {
|
williamr@4
|
224 |
_Traits::copy(this->pptr(), __s, __n);
|
williamr@4
|
225 |
this->pbump((int)__n);
|
williamr@4
|
226 |
#ifdef __SYMBIAN32__
|
williamr@4
|
227 |
// _M_str._M_stream_pos += __n; //increment streampos to number of characters in stream
|
williamr@4
|
228 |
#endif
|
williamr@4
|
229 |
return __n;
|
williamr@4
|
230 |
}
|
williamr@4
|
231 |
else {
|
williamr@4
|
232 |
_Traits::copy(this->pptr(), __s, __avail);
|
williamr@4
|
233 |
__nwritten += __avail;
|
williamr@4
|
234 |
__n -= __avail;
|
williamr@4
|
235 |
__s += __avail;
|
williamr@4
|
236 |
#ifdef __SYMBIAN32__
|
williamr@4
|
237 |
// _M_str._M_stream_pos += __avail;//increment streampos to number of characters in stream
|
williamr@4
|
238 |
#endif
|
williamr@4
|
239 |
this->setp(_M_Buf, _M_Buf + __STATIC_CAST(int,_S_BufSiz));
|
williamr@4
|
240 |
}
|
williamr@4
|
241 |
}
|
williamr@4
|
242 |
|
williamr@4
|
243 |
// At this point we know we're appending.
|
williamr@4
|
244 |
if (_M_mode & ios_base::in) {
|
williamr@4
|
245 |
ptrdiff_t __get_offset = this->gptr() - this->eback();
|
williamr@4
|
246 |
_M_str.append(__s, __s + __n);
|
williamr@4
|
247 |
|
williamr@4
|
248 |
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
|
williamr@4
|
249 |
size_t __data_size = _M_str.size();
|
williamr@4
|
250 |
|
williamr@4
|
251 |
this->setg(__data_ptr, __data_ptr + __get_offset, __data_ptr+__data_size);
|
williamr@4
|
252 |
this->setp(__data_ptr, __data_ptr + __data_size);
|
williamr@4
|
253 |
this->pbump((int)__data_size);
|
williamr@4
|
254 |
}
|
williamr@4
|
255 |
else {
|
williamr@4
|
256 |
_M_append_buffer();
|
williamr@4
|
257 |
#ifdef __SYMBIAN32__
|
williamr@4
|
258 |
if (_M_str._M_stream_pos >= 0
|
williamr@4
|
259 |
&& (_M_str._M_stream_pos < _M_str.size())) {
|
williamr@4
|
260 |
if((_M_str.size() - _M_str._M_stream_pos) >= __n)
|
williamr@4
|
261 |
_M_str.replace(_M_str._M_stream_pos, __n, __s);
|
williamr@4
|
262 |
else
|
williamr@4
|
263 |
{
|
williamr@4
|
264 |
_M_str.replace(_M_str._M_stream_pos, (_M_str.size() - _M_str._M_stream_pos), __s);
|
williamr@4
|
265 |
_M_str.append(__s + (__n - (_M_str.size() - _M_str._M_stream_pos)), __s + __n);
|
williamr@4
|
266 |
}
|
williamr@4
|
267 |
} else {
|
williamr@4
|
268 |
_M_str.append(__s, __s + __n);
|
williamr@4
|
269 |
}
|
williamr@4
|
270 |
_M_str._M_stream_pos += __n;
|
williamr@4
|
271 |
#else //__SYMBIAN32__
|
williamr@4
|
272 |
_M_str.append(__s, __s + __n);
|
williamr@4
|
273 |
#endif // __SYMBIAN32__
|
williamr@4
|
274 |
}
|
williamr@4
|
275 |
__nwritten += __n;
|
williamr@4
|
276 |
}
|
williamr@4
|
277 |
|
williamr@4
|
278 |
return __nwritten;
|
williamr@4
|
279 |
}
|
williamr@4
|
280 |
|
williamr@4
|
281 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
282 |
streamsize
|
williamr@4
|
283 |
basic_stringbuf<_CharT, _Traits, _Alloc>::_M_xsputnc(char_type __c,
|
williamr@4
|
284 |
streamsize __n)
|
williamr@4
|
285 |
{
|
williamr@4
|
286 |
streamsize __nwritten = 0;
|
williamr@4
|
287 |
|
williamr@4
|
288 |
if ((_M_mode & ios_base::out) && __n > 0) {
|
williamr@4
|
289 |
// If the put pointer is somewhere in the middle of the string,
|
williamr@4
|
290 |
// then overwrite instead of append.
|
williamr@4
|
291 |
if (this->pbase() == _M_str.data()) {
|
williamr@4
|
292 |
ptrdiff_t __avail = _M_str.data() + _M_str.size() - this->pptr();
|
williamr@4
|
293 |
if (__avail > __n) {
|
williamr@4
|
294 |
_Traits::assign(this->pptr(), __n, __c);
|
williamr@4
|
295 |
this->pbump((int)__n);
|
williamr@4
|
296 |
return __n;
|
williamr@4
|
297 |
}
|
williamr@4
|
298 |
else {
|
williamr@4
|
299 |
_Traits::assign(this->pptr(), __avail, __c);
|
williamr@4
|
300 |
__nwritten += __avail;
|
williamr@4
|
301 |
__n -= __avail;
|
williamr@4
|
302 |
this->setp(_M_Buf, _M_Buf + __STATIC_CAST(int,_S_BufSiz));
|
williamr@4
|
303 |
}
|
williamr@4
|
304 |
}
|
williamr@4
|
305 |
|
williamr@4
|
306 |
// At this point we know we're appending.
|
williamr@4
|
307 |
if (this->_M_mode & ios_base::in) {
|
williamr@4
|
308 |
ptrdiff_t __get_offset = this->gptr() - this->eback();
|
williamr@4
|
309 |
_M_str.append(__n, __c);
|
williamr@4
|
310 |
|
williamr@4
|
311 |
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
|
williamr@4
|
312 |
size_t __data_size = _M_str.size();
|
williamr@4
|
313 |
|
williamr@4
|
314 |
this->setg(__data_ptr, __data_ptr + __get_offset, __data_ptr+__data_size);
|
williamr@4
|
315 |
this->setp(__data_ptr, __data_ptr + __data_size);
|
williamr@4
|
316 |
this->pbump((int)__data_size);
|
williamr@4
|
317 |
|
williamr@4
|
318 |
}
|
williamr@4
|
319 |
else {
|
williamr@4
|
320 |
_M_append_buffer();
|
williamr@4
|
321 |
// _M_str.append(__n, __c);
|
williamr@4
|
322 |
#ifdef __SYMBIAN32__
|
williamr@4
|
323 |
if (_M_str._M_stream_pos >= 0
|
williamr@4
|
324 |
&& (_M_str._M_stream_pos < _M_str.size())) {
|
williamr@4
|
325 |
if((_M_str.size() - _M_str._M_stream_pos) >= __n)
|
williamr@4
|
326 |
_M_str.replace(_M_str._M_stream_pos,__n, __n, __c);
|
williamr@4
|
327 |
else
|
williamr@4
|
328 |
{
|
williamr@4
|
329 |
_M_str.replace(_M_str._M_stream_pos, (_M_str.size() - _M_str._M_stream_pos), (_M_str.size() - _M_str._M_stream_pos), __c);
|
williamr@4
|
330 |
_M_str.append(__n, __c);
|
williamr@4
|
331 |
}
|
williamr@4
|
332 |
} else {
|
williamr@4
|
333 |
_M_str.append(__n, __c);
|
williamr@4
|
334 |
}
|
williamr@4
|
335 |
_M_str._M_stream_pos += __n;
|
williamr@4
|
336 |
#else //__SYMBIAN32__
|
williamr@4
|
337 |
_M_str.append(__n, __c);
|
williamr@4
|
338 |
#endif // __SYMBIAN32__
|
williamr@4
|
339 |
}
|
williamr@4
|
340 |
|
williamr@4
|
341 |
__nwritten += __n;
|
williamr@4
|
342 |
}
|
williamr@4
|
343 |
|
williamr@4
|
344 |
return __nwritten;
|
williamr@4
|
345 |
}
|
williamr@4
|
346 |
|
williamr@4
|
347 |
// According to the C++ standard the effects of setbuf are implementation
|
williamr@4
|
348 |
// defined, except that setbuf(0, 0) has no effect. In this implementation,
|
williamr@4
|
349 |
// setbuf(<anything>, n), for n > 0, calls reserve(n) on the underlying
|
williamr@4
|
350 |
// string.
|
williamr@4
|
351 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
352 |
_STLP_EXP_DECLSPEC basic_streambuf<_CharT, _Traits>*
|
williamr@4
|
353 |
#ifdef __SYMBIAN32__
|
williamr@4
|
354 |
basic_stringbuf<_CharT, _Traits, _Alloc>::setbuf(_CharT* __s, streamsize __n)
|
williamr@4
|
355 |
#else
|
williamr@4
|
356 |
basic_stringbuf<_CharT, _Traits, _Alloc>::setbuf(_CharT*, streamsize __n)
|
williamr@4
|
357 |
#endif //__SYMBIAN32__
|
williamr@4
|
358 |
{
|
williamr@4
|
359 |
if (__n > 0) {
|
williamr@4
|
360 |
bool __do_get_area = false;
|
williamr@4
|
361 |
bool __do_put_area = false;
|
williamr@4
|
362 |
ptrdiff_t __offg = 0;
|
williamr@4
|
363 |
ptrdiff_t __offp = 0;
|
williamr@4
|
364 |
|
williamr@4
|
365 |
if (this->pbase() == _M_str.data()) {
|
williamr@4
|
366 |
__do_put_area = true;
|
williamr@4
|
367 |
__offp = this->pptr() - this->pbase();
|
williamr@4
|
368 |
}
|
williamr@4
|
369 |
|
williamr@4
|
370 |
if (this->eback() == _M_str.data()) {
|
williamr@4
|
371 |
__do_get_area = true;
|
williamr@4
|
372 |
__offg = this->gptr() - this->eback();
|
williamr@4
|
373 |
}
|
williamr@4
|
374 |
|
williamr@4
|
375 |
if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
|
williamr@4
|
376 |
_M_append_buffer();
|
williamr@4
|
377 |
|
williamr@4
|
378 |
_M_str.reserve(__n);
|
williamr@4
|
379 |
|
williamr@4
|
380 |
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
|
williamr@4
|
381 |
#ifdef __SYMBIAN32__
|
williamr@4
|
382 |
size_t __data_size = __n;
|
williamr@4
|
383 |
memmove(__data_ptr, __s, __n*sizeof(_CharT));
|
williamr@4
|
384 |
_M_str._M_start = __data_ptr;
|
williamr@4
|
385 |
_M_str._M_finish = __data_ptr+__n;
|
williamr@4
|
386 |
#else
|
williamr@4
|
387 |
size_t __data_size = _M_str.size();
|
williamr@4
|
388 |
#endif //__SYMBIAN32__
|
williamr@4
|
389 |
|
williamr@4
|
390 |
if (__do_get_area) {
|
williamr@4
|
391 |
#ifdef __SYMBIAN32__
|
williamr@4
|
392 |
this->setg(__data_ptr, __data_ptr, __data_ptr+__data_size);
|
williamr@4
|
393 |
#else
|
williamr@4
|
394 |
this->setg(__data_ptr, __data_ptr + __offg, __data_ptr+__data_size);
|
williamr@4
|
395 |
#endif //__SYMBIAN32__
|
williamr@4
|
396 |
}
|
williamr@4
|
397 |
|
williamr@4
|
398 |
if (__do_put_area) {
|
williamr@4
|
399 |
this->setp(__data_ptr, __data_ptr+__data_size);
|
williamr@4
|
400 |
#ifndef __SYMBIAN32__
|
williamr@4
|
401 |
this->pbump((int)__offp);
|
williamr@4
|
402 |
#endif //__SYMBIAN32__
|
williamr@4
|
403 |
}
|
williamr@4
|
404 |
}
|
williamr@4
|
405 |
|
williamr@4
|
406 |
return this;
|
williamr@4
|
407 |
}
|
williamr@4
|
408 |
|
williamr@4
|
409 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
410 |
_STLP_EXP_DECLSPEC __BSB_pos_type__
|
williamr@4
|
411 |
basic_stringbuf<_CharT, _Traits, _Alloc>::seekoff(off_type __off,
|
williamr@4
|
412 |
ios_base::seekdir __dir,
|
williamr@4
|
413 |
ios_base::openmode __mode)
|
williamr@4
|
414 |
{
|
williamr@4
|
415 |
bool __stl_in = false;
|
williamr@4
|
416 |
bool __stl_out = false;
|
williamr@4
|
417 |
|
williamr@4
|
418 |
if ((__mode & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) ) {
|
williamr@4
|
419 |
if (__dir == ios_base::beg || __dir == ios_base::end)
|
williamr@4
|
420 |
__stl_in = __stl_out = true;
|
williamr@4
|
421 |
}
|
williamr@4
|
422 |
else if (__mode & ios_base::in)
|
williamr@4
|
423 |
__stl_in = true;
|
williamr@4
|
424 |
else if (__mode & ios_base::out)
|
williamr@4
|
425 |
__stl_out = true;
|
williamr@4
|
426 |
|
williamr@4
|
427 |
if (!__stl_in && !__stl_out)
|
williamr@4
|
428 |
return pos_type(off_type(-1));
|
williamr@4
|
429 |
else if ((__stl_in && (!(_M_mode & ios_base::in) || this->gptr() == 0)) ||
|
williamr@4
|
430 |
(__stl_out && (!(_M_mode & ios_base::out) || this->pptr() == 0)))
|
williamr@4
|
431 |
return pos_type(off_type(-1));
|
williamr@4
|
432 |
|
williamr@4
|
433 |
#ifdef __SYMBIAN32__
|
williamr@4
|
434 |
if (_M_mode & ios_base::out)
|
williamr@4
|
435 |
#else
|
williamr@4
|
436 |
if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
|
williamr@4
|
437 |
#endif
|
williamr@4
|
438 |
_M_append_buffer();
|
williamr@4
|
439 |
|
williamr@4
|
440 |
streamoff __newoff;
|
williamr@4
|
441 |
switch(__dir) {
|
williamr@4
|
442 |
case ios_base::beg:
|
williamr@4
|
443 |
__newoff = 0;
|
williamr@4
|
444 |
break;
|
williamr@4
|
445 |
case ios_base::end:
|
williamr@4
|
446 |
__newoff = _M_str.size();
|
williamr@4
|
447 |
break;
|
williamr@4
|
448 |
case ios_base::cur:
|
williamr@4
|
449 |
__newoff = __stl_in ? this->gptr() - this->eback()
|
williamr@4
|
450 |
#ifdef __SYMBIAN32__
|
williamr@4
|
451 |
: ((this->pbase() != this->_M_str) ? _M_str._M_stream_pos
|
williamr@4
|
452 |
: this->pptr() - this->pbase());
|
williamr@4
|
453 |
#else
|
williamr@4
|
454 |
: this->pptr() - this->pbase();
|
williamr@4
|
455 |
#endif //__SYMBIAN32__
|
williamr@4
|
456 |
break;
|
williamr@4
|
457 |
default:
|
williamr@4
|
458 |
return pos_type(off_type(-1));
|
williamr@4
|
459 |
}
|
williamr@4
|
460 |
|
williamr@4
|
461 |
__off += __newoff;
|
williamr@4
|
462 |
|
williamr@4
|
463 |
if (__stl_in) {
|
williamr@4
|
464 |
ptrdiff_t __n = this->egptr() - this->eback();
|
williamr@4
|
465 |
|
williamr@4
|
466 |
if (__off < 0 || __off > __n)
|
williamr@4
|
467 |
return pos_type(off_type(-1));
|
williamr@4
|
468 |
else
|
williamr@4
|
469 |
this->setg(this->eback(), this->eback() + __off, this->eback() + __n);
|
williamr@4
|
470 |
}
|
williamr@4
|
471 |
|
williamr@4
|
472 |
if (__stl_out) {
|
williamr@4
|
473 |
ptrdiff_t __n;
|
williamr@4
|
474 |
#ifdef __SYMBIAN32__
|
williamr@4
|
475 |
//if (this->pbase() != this->_M_str) {
|
williamr@4
|
476 |
void* __data_ptr1 = reinterpret_cast<void*>(this->pbase());
|
williamr@4
|
477 |
_CharT* __data_ptr2 = __CONST_CAST(_CharT*,this->_M_str.data());
|
williamr@4
|
478 |
|
williamr@4
|
479 |
if (__data_ptr1 != __data_ptr2) {
|
williamr@4
|
480 |
__n = _M_str.size();
|
williamr@4
|
481 |
} else {
|
williamr@4
|
482 |
#endif // __SYMBIAN32__
|
williamr@4
|
483 |
__n = this->epptr() - this->pbase();
|
williamr@4
|
484 |
#ifdef __SYMBIAN32__
|
williamr@4
|
485 |
}
|
williamr@4
|
486 |
#endif //__SYMBIAN32__
|
williamr@4
|
487 |
if (__off < 0 || __off > __n)
|
williamr@4
|
488 |
return pos_type(off_type(-1));
|
williamr@4
|
489 |
else {
|
williamr@4
|
490 |
#ifdef __SYMBIAN32__
|
williamr@4
|
491 |
void* __data_ptr1 = reinterpret_cast<void*>(this->pbase());
|
williamr@4
|
492 |
_CharT* __data_ptr2 = __CONST_CAST(_CharT*,this->_M_str.data());
|
williamr@4
|
493 |
|
williamr@4
|
494 |
if (__data_ptr1 != __data_ptr2) {
|
williamr@4
|
495 |
_M_str._M_stream_pos = __off;
|
williamr@4
|
496 |
} else {
|
williamr@4
|
497 |
#endif //__SYMBIAN32__
|
williamr@4
|
498 |
this->setp(this->pbase(), this->pbase() + __n);
|
williamr@4
|
499 |
this->pbump((int)__off);
|
williamr@4
|
500 |
#ifdef __SYMBIAN32__
|
williamr@4
|
501 |
}
|
williamr@4
|
502 |
#endif // __SYMBIAN32__
|
williamr@4
|
503 |
}
|
williamr@4
|
504 |
}
|
williamr@4
|
505 |
|
williamr@4
|
506 |
return pos_type(__off);
|
williamr@4
|
507 |
}
|
williamr@4
|
508 |
|
williamr@4
|
509 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
510 |
_STLP_EXP_DECLSPEC __BSB_pos_type__
|
williamr@4
|
511 |
basic_stringbuf<_CharT, _Traits, _Alloc>
|
williamr@4
|
512 |
::seekpos(pos_type __pos, ios_base::openmode __mode)
|
williamr@4
|
513 |
{
|
williamr@4
|
514 |
bool __stl_in = (__mode & ios_base::in) != 0;
|
williamr@4
|
515 |
bool __stl_out = (__mode & ios_base::out) != 0;
|
williamr@4
|
516 |
|
williamr@4
|
517 |
if ((__stl_in && (!(_M_mode & ios_base::in) || this->gptr() == 0)) ||
|
williamr@4
|
518 |
(__stl_out && (!(_M_mode & ios_base::out) || this->pptr() == 0)) ||
|
williamr@4
|
519 |
(!__stl_in && !__stl_out))
|
williamr@4
|
520 |
return pos_type(off_type(-1));
|
williamr@4
|
521 |
|
williamr@4
|
522 |
const off_type __n = __pos - pos_type(off_type(0));
|
williamr@4
|
523 |
if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
|
williamr@4
|
524 |
_M_append_buffer();
|
williamr@4
|
525 |
|
williamr@4
|
526 |
if (__stl_in) {
|
williamr@4
|
527 |
if (__n < 0 || __n > this->egptr() - this->eback())
|
williamr@4
|
528 |
return pos_type(off_type(-1));
|
williamr@4
|
529 |
this->setg(this->eback(), this->eback() + __n, this->egptr());
|
williamr@4
|
530 |
}
|
williamr@4
|
531 |
|
williamr@4
|
532 |
if (__stl_out) {
|
williamr@4
|
533 |
if (__n < 0 || size_t(__n) > _M_str.size())
|
williamr@4
|
534 |
return pos_type(off_type(-1));
|
williamr@4
|
535 |
|
williamr@4
|
536 |
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
|
williamr@4
|
537 |
size_t __data_size = _M_str.size();
|
williamr@4
|
538 |
|
williamr@4
|
539 |
this->setp(__data_ptr, __data_ptr+__data_size);
|
williamr@4
|
540 |
this->pbump((int)__n);
|
williamr@4
|
541 |
}
|
williamr@4
|
542 |
|
williamr@4
|
543 |
return __pos;
|
williamr@4
|
544 |
}
|
williamr@4
|
545 |
|
williamr@4
|
546 |
// This is declared as a const member function because it is
|
williamr@4
|
547 |
// called by basic_stringbuf<>::str(). Precondition: this is a
|
williamr@4
|
548 |
// write-only stringbuf. We can't use an output buffer for read-
|
williamr@4
|
549 |
// write stringbufs. Postcondition: pptr is reset to the beginning
|
williamr@4
|
550 |
// of the buffer.
|
williamr@4
|
551 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
552 |
void basic_stringbuf<_CharT, _Traits, _Alloc>::_M_append_buffer() const
|
williamr@4
|
553 |
|
williamr@4
|
554 |
{
|
williamr@4
|
555 |
// Do we have a buffer to append?
|
williamr@4
|
556 |
if (this->pbase() == this->_M_Buf && this->pptr() != this->_M_Buf) {
|
williamr@4
|
557 |
basic_stringbuf<_CharT, _Traits, _Alloc>* __this = __CONST_CAST(_Self*,this);
|
williamr@4
|
558 |
#ifdef __SYMBIAN32__
|
williamr@4
|
559 |
size_t __n = this->pptr() - this->pbase();
|
williamr@4
|
560 |
if (__this->_M_str._M_stream_pos >= 0
|
williamr@4
|
561 |
&& (__this->_M_str._M_stream_pos != __this->_M_str.size())) {
|
williamr@4
|
562 |
{
|
williamr@4
|
563 |
*(this->pptr()) = (_CharT)0;
|
williamr@4
|
564 |
#ifdef __SYMBIAN32__
|
williamr@4
|
565 |
__this->_M_str.replace(_M_str._M_stream_pos, __n, (const _CharT*)this->pbase(), (const _CharT*)this->pptr()-(const _CharT*)this->pbase());
|
williamr@4
|
566 |
#else
|
williamr@4
|
567 |
__this->_M_str.replace(_M_str._M_stream_pos, __n, (const _CharT*)this->pbase());
|
williamr@4
|
568 |
|
williamr@4
|
569 |
#endif
|
williamr@4
|
570 |
}
|
williamr@4
|
571 |
} else {
|
williamr@4
|
572 |
__this->_M_str.append((const _CharT*)this->pbase(), (const _CharT*)this->pptr());
|
williamr@4
|
573 |
}
|
williamr@4
|
574 |
__this->_M_str._M_stream_pos += __n;
|
williamr@4
|
575 |
#else // __SYMBAIN32__
|
williamr@4
|
576 |
__this->_M_str.append((const _CharT*)this->pbase(), (const _CharT*)this->pptr());
|
williamr@4
|
577 |
#endif // __SYMBIAN32__
|
williamr@4
|
578 |
__this->setp(__CONST_CAST(_CharT*,_M_Buf),
|
williamr@4
|
579 |
__CONST_CAST(_CharT*,_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
|
williamr@4
|
580 |
}
|
williamr@4
|
581 |
|
williamr@4
|
582 |
// Have we run off the end of the string?
|
williamr@4
|
583 |
else if (this->pptr() == this->epptr()) {
|
williamr@4
|
584 |
basic_stringbuf<_CharT, _Traits, _Alloc>* __this = __CONST_CAST(_Self*,this);
|
williamr@4
|
585 |
__this->setp(__CONST_CAST(_CharT*,_M_Buf),
|
williamr@4
|
586 |
__CONST_CAST(_CharT*,_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
|
williamr@4
|
587 |
__this->_M_str._M_stream_pos = __this->_M_str._M_finish - __this->_M_str._M_start;
|
williamr@4
|
588 |
}
|
williamr@4
|
589 |
}
|
williamr@4
|
590 |
|
williamr@4
|
591 |
//----------------------------------------------------------------------
|
williamr@4
|
592 |
// Non-inline istringstream member functions.
|
williamr@4
|
593 |
|
williamr@4
|
594 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
595 |
basic_istringstream<_CharT, _Traits, _Alloc>
|
williamr@4
|
596 |
::basic_istringstream(ios_base::openmode __mode)
|
williamr@4
|
597 |
: basic_istream<_CharT, _Traits>(0),
|
williamr@4
|
598 |
_M_buf(__mode | ios_base::in)
|
williamr@4
|
599 |
{
|
williamr@4
|
600 |
this->init(&_M_buf);
|
williamr@4
|
601 |
}
|
williamr@4
|
602 |
|
williamr@4
|
603 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
604 |
basic_istringstream<_CharT, _Traits, _Alloc>
|
williamr@4
|
605 |
::basic_istringstream(const _String& __str,ios_base::openmode __mode)
|
williamr@4
|
606 |
: basic_istream<_CharT, _Traits>(0),
|
williamr@4
|
607 |
_M_buf(__str, __mode | ios_base::in)
|
williamr@4
|
608 |
{
|
williamr@4
|
609 |
this->init(&_M_buf);
|
williamr@4
|
610 |
}
|
williamr@4
|
611 |
|
williamr@4
|
612 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
613 |
basic_istringstream<_CharT, _Traits, _Alloc>::~basic_istringstream()
|
williamr@4
|
614 |
{}
|
williamr@4
|
615 |
|
williamr@4
|
616 |
//----------------------------------------------------------------------
|
williamr@4
|
617 |
// Non-inline ostringstream member functions.
|
williamr@4
|
618 |
|
williamr@4
|
619 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
620 |
basic_ostringstream<_CharT, _Traits, _Alloc>
|
williamr@4
|
621 |
::basic_ostringstream(ios_base::openmode __mode)
|
williamr@4
|
622 |
: basic_ostream<_CharT, _Traits>(0),
|
williamr@4
|
623 |
_M_buf(__mode | ios_base::out)
|
williamr@4
|
624 |
{
|
williamr@4
|
625 |
this->init(&_M_buf);
|
williamr@4
|
626 |
}
|
williamr@4
|
627 |
|
williamr@4
|
628 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
629 |
basic_ostringstream<_CharT, _Traits, _Alloc>
|
williamr@4
|
630 |
::basic_ostringstream(const _String& __str, ios_base::openmode __mode)
|
williamr@4
|
631 |
: basic_ostream<_CharT, _Traits>(0),
|
williamr@4
|
632 |
_M_buf(__str, __mode | ios_base::out)
|
williamr@4
|
633 |
{
|
williamr@4
|
634 |
this->init(&_M_buf);
|
williamr@4
|
635 |
}
|
williamr@4
|
636 |
|
williamr@4
|
637 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
638 |
basic_ostringstream<_CharT, _Traits, _Alloc>::~basic_ostringstream()
|
williamr@4
|
639 |
{}
|
williamr@4
|
640 |
|
williamr@4
|
641 |
//----------------------------------------------------------------------
|
williamr@4
|
642 |
// Non-inline stringstream member functions.
|
williamr@4
|
643 |
|
williamr@4
|
644 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
645 |
_STLP_EXP_DECLSPEC basic_stringstream<_CharT, _Traits, _Alloc>
|
williamr@4
|
646 |
::basic_stringstream(ios_base::openmode __mode)
|
williamr@4
|
647 |
: basic_iostream<_CharT, _Traits>(0), _M_buf(__mode)
|
williamr@4
|
648 |
{
|
williamr@4
|
649 |
this->init(&_M_buf);
|
williamr@4
|
650 |
}
|
williamr@4
|
651 |
|
williamr@4
|
652 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
653 |
_STLP_EXP_DECLSPEC basic_stringstream<_CharT, _Traits, _Alloc>
|
williamr@4
|
654 |
::basic_stringstream(const _String& __str, ios_base::openmode __mode)
|
williamr@4
|
655 |
: basic_iostream<_CharT, _Traits>(0), _M_buf(__str, __mode)
|
williamr@4
|
656 |
{
|
williamr@4
|
657 |
this->init(&_M_buf);
|
williamr@4
|
658 |
}
|
williamr@4
|
659 |
|
williamr@4
|
660 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
661 |
basic_stringstream<_CharT, _Traits, _Alloc>::~basic_stringstream()
|
williamr@4
|
662 |
{}
|
williamr@4
|
663 |
|
williamr@4
|
664 |
_STLP_END_NAMESPACE
|
williamr@4
|
665 |
|
williamr@4
|
666 |
# undef __BSB_int_type__
|
williamr@4
|
667 |
# undef __BSB_pos_type__
|
williamr@4
|
668 |
|
williamr@4
|
669 |
# endif /* EXPOSE */
|
williamr@4
|
670 |
|
williamr@4
|
671 |
#endif /* _STLP_SSTREAM_C */
|