/src/llvm-project-16.0.6.build/include/c++/v1/sstream
Line | Count | Source (jump to first uncovered line) |
1 | | // -*- C++ -*- |
2 | | //===----------------------------------------------------------------------===// |
3 | | // |
4 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
5 | | // See https://llvm.org/LICENSE.txt for license information. |
6 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | |
10 | | #ifndef _LIBCPP_SSTREAM |
11 | | #define _LIBCPP_SSTREAM |
12 | | |
13 | | /* |
14 | | sstream synopsis [sstream.syn] |
15 | | |
16 | | // Class template basic_stringbuf [stringbuf] |
17 | | template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
18 | | class basic_stringbuf |
19 | | : public basic_streambuf<charT, traits> |
20 | | { |
21 | | public: |
22 | | typedef charT char_type; |
23 | | typedef traits traits_type; |
24 | | typedef typename traits_type::int_type int_type; |
25 | | typedef typename traits_type::pos_type pos_type; |
26 | | typedef typename traits_type::off_type off_type; |
27 | | typedef Allocator allocator_type; |
28 | | |
29 | | // [stringbuf.cons] constructors: |
30 | | explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); // before C++20 |
31 | | basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {} // C++20 |
32 | | explicit basic_stringbuf(ios_base::openmode which); // C++20 |
33 | | explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& str, |
34 | | ios_base::openmode which = ios_base::in | ios_base::out); |
35 | | basic_stringbuf(basic_stringbuf&& rhs); |
36 | | |
37 | | // [stringbuf.assign] Assign and swap: |
38 | | basic_stringbuf& operator=(basic_stringbuf&& rhs); |
39 | | void swap(basic_stringbuf& rhs); |
40 | | |
41 | | // [stringbuf.members] Member functions: |
42 | | basic_string<char_type, traits_type, allocator_type> str() const; |
43 | | void str(const basic_string<char_type, traits_type, allocator_type>& s); |
44 | | |
45 | | protected: |
46 | | // [stringbuf.virtuals] Overridden virtual functions: |
47 | | virtual int_type underflow(); |
48 | | virtual int_type pbackfail(int_type c = traits_type::eof()); |
49 | | virtual int_type overflow (int_type c = traits_type::eof()); |
50 | | virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize); |
51 | | virtual pos_type seekoff(off_type off, ios_base::seekdir way, |
52 | | ios_base::openmode which = ios_base::in | ios_base::out); |
53 | | virtual pos_type seekpos(pos_type sp, |
54 | | ios_base::openmode which = ios_base::in | ios_base::out); |
55 | | }; |
56 | | |
57 | | // [stringbuf.assign] non member swap |
58 | | template <class charT, class traits, class Allocator> |
59 | | void swap(basic_stringbuf<charT, traits, Allocator>& x, |
60 | | basic_stringbuf<charT, traits, Allocator>& y); |
61 | | |
62 | | typedef basic_stringbuf<char> stringbuf; |
63 | | typedef basic_stringbuf<wchar_t> wstringbuf; |
64 | | |
65 | | // Class template basic_istringstream [istringstream] |
66 | | template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
67 | | class basic_istringstream |
68 | | : public basic_istream<charT, traits> |
69 | | { |
70 | | public: |
71 | | typedef charT char_type; |
72 | | typedef traits traits_type; |
73 | | typedef typename traits_type::int_type int_type; |
74 | | typedef typename traits_type::pos_type pos_type; |
75 | | typedef typename traits_type::off_type off_type; |
76 | | typedef Allocator allocator_type; |
77 | | |
78 | | // [istringstream.cons] Constructors: |
79 | | explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++20 |
80 | | basic_istringstream() : basic_istringstream(ios_base::in) {} // C++20 |
81 | | explicit basic_istringstream(ios_base::openmode which); // C++20 |
82 | | |
83 | | explicit basic_istringstream(const basic_string<char_type, traits_type,allocator_type>& str, |
84 | | ios_base::openmode which = ios_base::in); |
85 | | basic_istringstream(basic_istringstream&& rhs); |
86 | | |
87 | | // [istringstream.assign] Assign and swap: |
88 | | basic_istringstream& operator=(basic_istringstream&& rhs); |
89 | | void swap(basic_istringstream& rhs); |
90 | | |
91 | | // [istringstream.members] Member functions: |
92 | | basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; |
93 | | basic_string<char_type, traits_type, allocator_type> str() const; |
94 | | void str(const basic_string<char_type, traits_type, allocator_type>& s); |
95 | | }; |
96 | | |
97 | | template <class charT, class traits, class Allocator> |
98 | | void swap(basic_istringstream<charT, traits, Allocator>& x, |
99 | | basic_istringstream<charT, traits, Allocator>& y); |
100 | | |
101 | | typedef basic_istringstream<char> istringstream; |
102 | | typedef basic_istringstream<wchar_t> wistringstream; |
103 | | |
104 | | // Class template basic_ostringstream [ostringstream] |
105 | | template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
106 | | class basic_ostringstream |
107 | | : public basic_ostream<charT, traits> |
108 | | { |
109 | | public: |
110 | | // types: |
111 | | typedef charT char_type; |
112 | | typedef traits traits_type; |
113 | | typedef typename traits_type::int_type int_type; |
114 | | typedef typename traits_type::pos_type pos_type; |
115 | | typedef typename traits_type::off_type off_type; |
116 | | typedef Allocator allocator_type; |
117 | | |
118 | | // [ostringstream.cons] Constructors: |
119 | | explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20 |
120 | | basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++20 |
121 | | explicit basic_ostringstream(ios_base::openmode which); // C++20 |
122 | | |
123 | | explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& str, |
124 | | ios_base::openmode which = ios_base::out); |
125 | | basic_ostringstream(basic_ostringstream&& rhs); |
126 | | |
127 | | // [ostringstream.assign] Assign and swap: |
128 | | basic_ostringstream& operator=(basic_ostringstream&& rhs); |
129 | | void swap(basic_ostringstream& rhs); |
130 | | |
131 | | // [ostringstream.members] Member functions: |
132 | | basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; |
133 | | basic_string<char_type, traits_type, allocator_type> str() const; |
134 | | void str(const basic_string<char_type, traits_type, allocator_type>& s); |
135 | | }; |
136 | | |
137 | | template <class charT, class traits, class Allocator> |
138 | | void swap(basic_ostringstream<charT, traits, Allocator>& x, |
139 | | basic_ostringstream<charT, traits, Allocator>& y); |
140 | | |
141 | | typedef basic_ostringstream<char> ostringstream; |
142 | | typedef basic_ostringstream<wchar_t> wostringstream; |
143 | | |
144 | | // Class template basic_stringstream [stringstream] |
145 | | template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
146 | | class basic_stringstream |
147 | | : public basic_iostream<charT, traits> |
148 | | { |
149 | | public: |
150 | | // types: |
151 | | typedef charT char_type; |
152 | | typedef traits traits_type; |
153 | | typedef typename traits_type::int_type int_type; |
154 | | typedef typename traits_type::pos_type pos_type; |
155 | | typedef typename traits_type::off_type off_type; |
156 | | typedef Allocator allocator_type; |
157 | | |
158 | | // [stringstream.cons] constructors |
159 | | explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20 |
160 | | basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} // C++20 |
161 | | explicit basic_stringstream(ios_base::openmode which); // C++20 |
162 | | |
163 | | explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& str, |
164 | | ios_base::openmode which = ios_base::out|ios_base::in); |
165 | | basic_stringstream(basic_stringstream&& rhs); |
166 | | |
167 | | // [stringstream.assign] Assign and swap: |
168 | | basic_stringstream& operator=(basic_stringstream&& rhs); |
169 | | void swap(basic_stringstream& rhs); |
170 | | |
171 | | // [stringstream.members] Member functions: |
172 | | basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; |
173 | | basic_string<char_type, traits_type, allocator_type> str() const; |
174 | | void str(const basic_string<char_type, traits_type, allocator_type>& str); |
175 | | }; |
176 | | |
177 | | template <class charT, class traits, class Allocator> |
178 | | void swap(basic_stringstream<charT, traits, Allocator>& x, |
179 | | basic_stringstream<charT, traits, Allocator>& y); |
180 | | |
181 | | typedef basic_stringstream<char> stringstream; |
182 | | typedef basic_stringstream<wchar_t> wstringstream; |
183 | | |
184 | | } // std |
185 | | |
186 | | */ |
187 | | |
188 | | #include <__assert> // all public C++ headers provide the assertion handler |
189 | | #include <__config> |
190 | | #include <__utility/swap.h> |
191 | | #include <istream> |
192 | | #include <ostream> |
193 | | #include <string> |
194 | | #include <version> |
195 | | |
196 | | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
197 | | # pragma GCC system_header |
198 | | #endif |
199 | | |
200 | | _LIBCPP_PUSH_MACROS |
201 | | #include <__undef_macros> |
202 | | |
203 | | |
204 | | _LIBCPP_BEGIN_NAMESPACE_STD |
205 | | |
206 | | // Class template basic_stringbuf [stringbuf] |
207 | | |
208 | | template <class _CharT, class _Traits, class _Allocator> |
209 | | class _LIBCPP_TEMPLATE_VIS basic_stringbuf |
210 | | : public basic_streambuf<_CharT, _Traits> |
211 | | { |
212 | | public: |
213 | | typedef _CharT char_type; |
214 | | typedef _Traits traits_type; |
215 | | typedef typename traits_type::int_type int_type; |
216 | | typedef typename traits_type::pos_type pos_type; |
217 | | typedef typename traits_type::off_type off_type; |
218 | | typedef _Allocator allocator_type; |
219 | | |
220 | | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
221 | | |
222 | | private: |
223 | | |
224 | | string_type __str_; |
225 | | mutable char_type* __hm_; |
226 | | ios_base::openmode __mode_; |
227 | | |
228 | | public: |
229 | | // [stringbuf.cons] constructors: |
230 | | _LIBCPP_INLINE_VISIBILITY |
231 | | basic_stringbuf() |
232 | | : __hm_(nullptr), __mode_(ios_base::in | ios_base::out) {} |
233 | | |
234 | | _LIBCPP_INLINE_VISIBILITY |
235 | | explicit basic_stringbuf(ios_base::openmode __wch) |
236 | | : __hm_(nullptr), __mode_(__wch) {} |
237 | | |
238 | | _LIBCPP_INLINE_VISIBILITY |
239 | | explicit basic_stringbuf(const string_type& __s, |
240 | | ios_base::openmode __wch = ios_base::in | ios_base::out) |
241 | | : __str_(__s.get_allocator()), __hm_(nullptr), __mode_(__wch) |
242 | | { |
243 | | str(__s); |
244 | | } |
245 | | |
246 | | basic_stringbuf(basic_stringbuf&& __rhs); |
247 | | |
248 | | // [stringbuf.assign] Assign and swap: |
249 | | basic_stringbuf& operator=(basic_stringbuf&& __rhs); |
250 | | void swap(basic_stringbuf& __rhs); |
251 | | |
252 | | // [stringbuf.members] Member functions: |
253 | | string_type str() const; |
254 | | void str(const string_type& __s); |
255 | | |
256 | | protected: |
257 | | // [stringbuf.virtuals] Overridden virtual functions: |
258 | | int_type underflow() override; |
259 | | int_type pbackfail(int_type __c = traits_type::eof()) override; |
260 | | int_type overflow (int_type __c = traits_type::eof()) override; |
261 | | pos_type seekoff(off_type __off, ios_base::seekdir __way, |
262 | | ios_base::openmode __wch = ios_base::in | ios_base::out) override; |
263 | | _LIBCPP_HIDE_FROM_ABI_VIRTUAL |
264 | | pos_type seekpos(pos_type __sp, |
265 | 0 | ios_base::openmode __wch = ios_base::in | ios_base::out) override { |
266 | 0 | return seekoff(__sp, ios_base::beg, __wch); |
267 | 0 | } |
268 | | }; |
269 | | |
270 | | template <class _CharT, class _Traits, class _Allocator> |
271 | | basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs) |
272 | | : __mode_(__rhs.__mode_) |
273 | 0 | { |
274 | 0 | char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); |
275 | 0 | ptrdiff_t __binp = -1; |
276 | 0 | ptrdiff_t __ninp = -1; |
277 | 0 | ptrdiff_t __einp = -1; |
278 | 0 | if (__rhs.eback() != nullptr) |
279 | 0 | { |
280 | 0 | __binp = __rhs.eback() - __p; |
281 | 0 | __ninp = __rhs.gptr() - __p; |
282 | 0 | __einp = __rhs.egptr() - __p; |
283 | 0 | } |
284 | 0 | ptrdiff_t __bout = -1; |
285 | 0 | ptrdiff_t __nout = -1; |
286 | 0 | ptrdiff_t __eout = -1; |
287 | 0 | if (__rhs.pbase() != nullptr) |
288 | 0 | { |
289 | 0 | __bout = __rhs.pbase() - __p; |
290 | 0 | __nout = __rhs.pptr() - __p; |
291 | 0 | __eout = __rhs.epptr() - __p; |
292 | 0 | } |
293 | 0 | ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; |
294 | 0 | __str_ = _VSTD::move(__rhs.__str_); |
295 | 0 | __p = const_cast<char_type*>(__str_.data()); |
296 | 0 | if (__binp != -1) |
297 | 0 | this->setg(__p + __binp, __p + __ninp, __p + __einp); |
298 | 0 | if (__bout != -1) |
299 | 0 | { |
300 | 0 | this->setp(__p + __bout, __p + __eout); |
301 | 0 | this->__pbump(__nout); |
302 | 0 | } |
303 | 0 | __hm_ = __hm == -1 ? nullptr : __p + __hm; |
304 | 0 | __p = const_cast<char_type*>(__rhs.__str_.data()); |
305 | 0 | __rhs.setg(__p, __p, __p); |
306 | 0 | __rhs.setp(__p, __p); |
307 | 0 | __rhs.__hm_ = __p; |
308 | 0 | this->pubimbue(__rhs.getloc()); |
309 | 0 | } |
310 | | |
311 | | template <class _CharT, class _Traits, class _Allocator> |
312 | | basic_stringbuf<_CharT, _Traits, _Allocator>& |
313 | | basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) |
314 | 0 | { |
315 | 0 | char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); |
316 | 0 | ptrdiff_t __binp = -1; |
317 | 0 | ptrdiff_t __ninp = -1; |
318 | 0 | ptrdiff_t __einp = -1; |
319 | 0 | if (__rhs.eback() != nullptr) |
320 | 0 | { |
321 | 0 | __binp = __rhs.eback() - __p; |
322 | 0 | __ninp = __rhs.gptr() - __p; |
323 | 0 | __einp = __rhs.egptr() - __p; |
324 | 0 | } |
325 | 0 | ptrdiff_t __bout = -1; |
326 | 0 | ptrdiff_t __nout = -1; |
327 | 0 | ptrdiff_t __eout = -1; |
328 | 0 | if (__rhs.pbase() != nullptr) |
329 | 0 | { |
330 | 0 | __bout = __rhs.pbase() - __p; |
331 | 0 | __nout = __rhs.pptr() - __p; |
332 | 0 | __eout = __rhs.epptr() - __p; |
333 | 0 | } |
334 | 0 | ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; |
335 | 0 | __str_ = _VSTD::move(__rhs.__str_); |
336 | 0 | __p = const_cast<char_type*>(__str_.data()); |
337 | 0 | if (__binp != -1) |
338 | 0 | this->setg(__p + __binp, __p + __ninp, __p + __einp); |
339 | 0 | else |
340 | 0 | this->setg(nullptr, nullptr, nullptr); |
341 | 0 | if (__bout != -1) |
342 | 0 | { |
343 | 0 | this->setp(__p + __bout, __p + __eout); |
344 | 0 | this->__pbump(__nout); |
345 | 0 | } |
346 | 0 | else |
347 | 0 | this->setp(nullptr, nullptr); |
348 | |
|
349 | 0 | __hm_ = __hm == -1 ? nullptr : __p + __hm; |
350 | 0 | __mode_ = __rhs.__mode_; |
351 | 0 | __p = const_cast<char_type*>(__rhs.__str_.data()); |
352 | 0 | __rhs.setg(__p, __p, __p); |
353 | 0 | __rhs.setp(__p, __p); |
354 | 0 | __rhs.__hm_ = __p; |
355 | 0 | this->pubimbue(__rhs.getloc()); |
356 | 0 | return *this; |
357 | 0 | } |
358 | | |
359 | | template <class _CharT, class _Traits, class _Allocator> |
360 | | void |
361 | | basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) |
362 | 0 | { |
363 | 0 | char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); |
364 | 0 | ptrdiff_t __rbinp = -1; |
365 | 0 | ptrdiff_t __rninp = -1; |
366 | 0 | ptrdiff_t __reinp = -1; |
367 | 0 | if (__rhs.eback() != nullptr) |
368 | 0 | { |
369 | 0 | __rbinp = __rhs.eback() - __p; |
370 | 0 | __rninp = __rhs.gptr() - __p; |
371 | 0 | __reinp = __rhs.egptr() - __p; |
372 | 0 | } |
373 | 0 | ptrdiff_t __rbout = -1; |
374 | 0 | ptrdiff_t __rnout = -1; |
375 | 0 | ptrdiff_t __reout = -1; |
376 | 0 | if (__rhs.pbase() != nullptr) |
377 | 0 | { |
378 | 0 | __rbout = __rhs.pbase() - __p; |
379 | 0 | __rnout = __rhs.pptr() - __p; |
380 | 0 | __reout = __rhs.epptr() - __p; |
381 | 0 | } |
382 | 0 | ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; |
383 | 0 | __p = const_cast<char_type*>(__str_.data()); |
384 | 0 | ptrdiff_t __lbinp = -1; |
385 | 0 | ptrdiff_t __lninp = -1; |
386 | 0 | ptrdiff_t __leinp = -1; |
387 | 0 | if (this->eback() != nullptr) |
388 | 0 | { |
389 | 0 | __lbinp = this->eback() - __p; |
390 | 0 | __lninp = this->gptr() - __p; |
391 | 0 | __leinp = this->egptr() - __p; |
392 | 0 | } |
393 | 0 | ptrdiff_t __lbout = -1; |
394 | 0 | ptrdiff_t __lnout = -1; |
395 | 0 | ptrdiff_t __leout = -1; |
396 | 0 | if (this->pbase() != nullptr) |
397 | 0 | { |
398 | 0 | __lbout = this->pbase() - __p; |
399 | 0 | __lnout = this->pptr() - __p; |
400 | 0 | __leout = this->epptr() - __p; |
401 | 0 | } |
402 | 0 | ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p; |
403 | 0 | _VSTD::swap(__mode_, __rhs.__mode_); |
404 | 0 | __str_.swap(__rhs.__str_); |
405 | 0 | __p = const_cast<char_type*>(__str_.data()); |
406 | 0 | if (__rbinp != -1) |
407 | 0 | this->setg(__p + __rbinp, __p + __rninp, __p + __reinp); |
408 | 0 | else |
409 | 0 | this->setg(nullptr, nullptr, nullptr); |
410 | 0 | if (__rbout != -1) |
411 | 0 | { |
412 | 0 | this->setp(__p + __rbout, __p + __reout); |
413 | 0 | this->__pbump(__rnout); |
414 | 0 | } |
415 | 0 | else |
416 | 0 | this->setp(nullptr, nullptr); |
417 | 0 | __hm_ = __rhm == -1 ? nullptr : __p + __rhm; |
418 | 0 | __p = const_cast<char_type*>(__rhs.__str_.data()); |
419 | 0 | if (__lbinp != -1) |
420 | 0 | __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp); |
421 | 0 | else |
422 | 0 | __rhs.setg(nullptr, nullptr, nullptr); |
423 | 0 | if (__lbout != -1) |
424 | 0 | { |
425 | 0 | __rhs.setp(__p + __lbout, __p + __leout); |
426 | 0 | __rhs.__pbump(__lnout); |
427 | 0 | } |
428 | 0 | else |
429 | 0 | __rhs.setp(nullptr, nullptr); |
430 | 0 | __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm; |
431 | 0 | locale __tl = __rhs.getloc(); |
432 | 0 | __rhs.pubimbue(this->getloc()); |
433 | 0 | this->pubimbue(__tl); |
434 | 0 | } |
435 | | |
436 | | template <class _CharT, class _Traits, class _Allocator> |
437 | | inline _LIBCPP_INLINE_VISIBILITY |
438 | | void |
439 | | swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, |
440 | | basic_stringbuf<_CharT, _Traits, _Allocator>& __y) |
441 | | { |
442 | | __x.swap(__y); |
443 | | } |
444 | | |
445 | | template <class _CharT, class _Traits, class _Allocator> |
446 | | basic_string<_CharT, _Traits, _Allocator> |
447 | | basic_stringbuf<_CharT, _Traits, _Allocator>::str() const |
448 | 2.88k | { |
449 | 2.88k | if (__mode_ & ios_base::out) |
450 | 2.88k | { |
451 | 2.88k | if (__hm_ < this->pptr()) |
452 | 2.65k | __hm_ = this->pptr(); |
453 | 2.88k | return string_type(this->pbase(), __hm_, __str_.get_allocator()); |
454 | 2.88k | } |
455 | 0 | else if (__mode_ & ios_base::in) |
456 | 0 | return string_type(this->eback(), this->egptr(), __str_.get_allocator()); |
457 | 0 | return string_type(__str_.get_allocator()); |
458 | 2.88k | } |
459 | | |
460 | | template <class _CharT, class _Traits, class _Allocator> |
461 | | void |
462 | | basic_stringbuf<_CharT, _Traits, _Allocator>::str(const string_type& __s) |
463 | 1.32k | { |
464 | 1.32k | __str_ = __s; |
465 | 1.32k | __hm_ = nullptr; |
466 | 1.32k | if (__mode_ & ios_base::in) |
467 | 1.32k | { |
468 | 1.32k | __hm_ = const_cast<char_type*>(__str_.data()) + __str_.size(); |
469 | 1.32k | this->setg(const_cast<char_type*>(__str_.data()), |
470 | 1.32k | const_cast<char_type*>(__str_.data()), |
471 | 1.32k | __hm_); |
472 | 1.32k | } |
473 | 1.32k | if (__mode_ & ios_base::out) |
474 | 0 | { |
475 | 0 | typename string_type::size_type __sz = __str_.size(); |
476 | 0 | __hm_ = const_cast<char_type*>(__str_.data()) + __sz; |
477 | 0 | __str_.resize(__str_.capacity()); |
478 | 0 | this->setp(const_cast<char_type*>(__str_.data()), |
479 | 0 | const_cast<char_type*>(__str_.data()) + __str_.size()); |
480 | 0 | if (__mode_ & (ios_base::app | ios_base::ate)) |
481 | 0 | { |
482 | 0 | while (__sz > INT_MAX) |
483 | 0 | { |
484 | 0 | this->pbump(INT_MAX); |
485 | 0 | __sz -= INT_MAX; |
486 | 0 | } |
487 | 0 | if (__sz > 0) |
488 | 0 | this->pbump(__sz); |
489 | 0 | } |
490 | 0 | } |
491 | 1.32k | } |
492 | | |
493 | | template <class _CharT, class _Traits, class _Allocator> |
494 | | typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type |
495 | | basic_stringbuf<_CharT, _Traits, _Allocator>::underflow() |
496 | 614 | { |
497 | 614 | if (__hm_ < this->pptr()) |
498 | 0 | __hm_ = this->pptr(); |
499 | 614 | if (__mode_ & ios_base::in) |
500 | 614 | { |
501 | 614 | if (this->egptr() < __hm_) |
502 | 0 | this->setg(this->eback(), this->gptr(), __hm_); |
503 | 614 | if (this->gptr() < this->egptr()) |
504 | 0 | return traits_type::to_int_type(*this->gptr()); |
505 | 614 | } |
506 | 614 | return traits_type::eof(); |
507 | 614 | } |
508 | | |
509 | | template <class _CharT, class _Traits, class _Allocator> |
510 | | typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type |
511 | | basic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c) |
512 | 0 | { |
513 | 0 | if (__hm_ < this->pptr()) |
514 | 0 | __hm_ = this->pptr(); |
515 | 0 | if (this->eback() < this->gptr()) |
516 | 0 | { |
517 | 0 | if (traits_type::eq_int_type(__c, traits_type::eof())) |
518 | 0 | { |
519 | 0 | this->setg(this->eback(), this->gptr()-1, __hm_); |
520 | 0 | return traits_type::not_eof(__c); |
521 | 0 | } |
522 | 0 | if ((__mode_ & ios_base::out) || |
523 | 0 | traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) |
524 | 0 | { |
525 | 0 | this->setg(this->eback(), this->gptr()-1, __hm_); |
526 | 0 | *this->gptr() = traits_type::to_char_type(__c); |
527 | 0 | return __c; |
528 | 0 | } |
529 | 0 | } |
530 | 0 | return traits_type::eof(); |
531 | 0 | } |
532 | | |
533 | | template <class _CharT, class _Traits, class _Allocator> |
534 | | typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type |
535 | | basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) |
536 | 3.53k | { |
537 | 3.53k | if (!traits_type::eq_int_type(__c, traits_type::eof())) |
538 | 3.53k | { |
539 | 3.53k | ptrdiff_t __ninp = this->gptr() - this->eback(); |
540 | 3.53k | if (this->pptr() == this->epptr()) |
541 | 3.53k | { |
542 | 3.53k | if (!(__mode_ & ios_base::out)) |
543 | 0 | return traits_type::eof(); |
544 | 3.53k | #ifndef _LIBCPP_NO_EXCEPTIONS |
545 | 3.53k | try |
546 | 3.53k | { |
547 | 3.53k | #endif // _LIBCPP_NO_EXCEPTIONS |
548 | 3.53k | ptrdiff_t __nout = this->pptr() - this->pbase(); |
549 | 3.53k | ptrdiff_t __hm = __hm_ - this->pbase(); |
550 | 3.53k | __str_.push_back(char_type()); |
551 | 3.53k | __str_.resize(__str_.capacity()); |
552 | 3.53k | char_type* __p = const_cast<char_type*>(__str_.data()); |
553 | 3.53k | this->setp(__p, __p + __str_.size()); |
554 | 3.53k | this->__pbump(__nout); |
555 | 3.53k | __hm_ = this->pbase() + __hm; |
556 | 3.53k | #ifndef _LIBCPP_NO_EXCEPTIONS |
557 | 3.53k | } |
558 | 3.53k | catch (...) |
559 | 3.53k | { |
560 | 0 | return traits_type::eof(); |
561 | 0 | } |
562 | 3.53k | #endif // _LIBCPP_NO_EXCEPTIONS |
563 | 3.53k | } |
564 | 3.53k | __hm_ = _VSTD::max(this->pptr() + 1, __hm_); |
565 | 3.53k | if (__mode_ & ios_base::in) |
566 | 0 | { |
567 | 0 | char_type* __p = const_cast<char_type*>(__str_.data()); |
568 | 0 | this->setg(__p, __p + __ninp, __hm_); |
569 | 0 | } |
570 | 3.53k | return this->sputc(traits_type::to_char_type(__c)); |
571 | 3.53k | } |
572 | 0 | return traits_type::not_eof(__c); |
573 | 3.53k | } |
574 | | |
575 | | template <class _CharT, class _Traits, class _Allocator> |
576 | | typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type |
577 | | basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off, |
578 | | ios_base::seekdir __way, |
579 | | ios_base::openmode __wch) |
580 | 0 | { |
581 | 0 | if (__hm_ < this->pptr()) |
582 | 0 | __hm_ = this->pptr(); |
583 | 0 | if ((__wch & (ios_base::in | ios_base::out)) == 0) |
584 | 0 | return pos_type(-1); |
585 | 0 | if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) |
586 | 0 | && __way == ios_base::cur) |
587 | 0 | return pos_type(-1); |
588 | 0 | const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data(); |
589 | 0 | off_type __noff; |
590 | 0 | switch (__way) |
591 | 0 | { |
592 | 0 | case ios_base::beg: |
593 | 0 | __noff = 0; |
594 | 0 | break; |
595 | 0 | case ios_base::cur: |
596 | 0 | if (__wch & ios_base::in) |
597 | 0 | __noff = this->gptr() - this->eback(); |
598 | 0 | else |
599 | 0 | __noff = this->pptr() - this->pbase(); |
600 | 0 | break; |
601 | 0 | case ios_base::end: |
602 | 0 | __noff = __hm; |
603 | 0 | break; |
604 | 0 | default: |
605 | 0 | return pos_type(-1); |
606 | 0 | } |
607 | 0 | __noff += __off; |
608 | 0 | if (__noff < 0 || __hm < __noff) |
609 | 0 | return pos_type(-1); |
610 | 0 | if (__noff != 0) |
611 | 0 | { |
612 | 0 | if ((__wch & ios_base::in) && this->gptr() == nullptr) |
613 | 0 | return pos_type(-1); |
614 | 0 | if ((__wch & ios_base::out) && this->pptr() == nullptr) |
615 | 0 | return pos_type(-1); |
616 | 0 | } |
617 | 0 | if (__wch & ios_base::in) |
618 | 0 | this->setg(this->eback(), this->eback() + __noff, __hm_); |
619 | 0 | if (__wch & ios_base::out) |
620 | 0 | { |
621 | 0 | this->setp(this->pbase(), this->epptr()); |
622 | 0 | this->pbump(__noff); |
623 | 0 | } |
624 | 0 | return pos_type(__noff); |
625 | 0 | } |
626 | | |
627 | | // Class template basic_istringstream [istringstream] |
628 | | |
629 | | template <class _CharT, class _Traits, class _Allocator> |
630 | | class _LIBCPP_TEMPLATE_VIS basic_istringstream |
631 | | : public basic_istream<_CharT, _Traits> |
632 | | { |
633 | | public: |
634 | | typedef _CharT char_type; |
635 | | typedef _Traits traits_type; |
636 | | typedef typename traits_type::int_type int_type; |
637 | | typedef typename traits_type::pos_type pos_type; |
638 | | typedef typename traits_type::off_type off_type; |
639 | | typedef _Allocator allocator_type; |
640 | | |
641 | | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
642 | | |
643 | | private: |
644 | | basic_stringbuf<char_type, traits_type, allocator_type> __sb_; |
645 | | |
646 | | public: |
647 | | // [istringstream.cons] Constructors: |
648 | | _LIBCPP_INLINE_VISIBILITY |
649 | | basic_istringstream() |
650 | | : basic_istream<_CharT, _Traits>(&__sb_), __sb_(ios_base::in) {} |
651 | | |
652 | | _LIBCPP_INLINE_VISIBILITY |
653 | | explicit basic_istringstream(ios_base::openmode __wch) |
654 | | : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::in) {} |
655 | | |
656 | | _LIBCPP_INLINE_VISIBILITY |
657 | | explicit basic_istringstream(const string_type& __s, |
658 | | ios_base::openmode __wch = ios_base::in) |
659 | | : basic_istream<_CharT, _Traits>(&__sb_) |
660 | | , __sb_(__s, __wch | ios_base::in) |
661 | | { } |
662 | | |
663 | | _LIBCPP_INLINE_VISIBILITY |
664 | | basic_istringstream(basic_istringstream&& __rhs) |
665 | | : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) |
666 | | , __sb_(_VSTD::move(__rhs.__sb_)) |
667 | | { |
668 | | basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); |
669 | | } |
670 | | |
671 | | // [istringstream.assign] Assign and swap: |
672 | 0 | basic_istringstream& operator=(basic_istringstream&& __rhs) { |
673 | 0 | basic_istream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); |
674 | 0 | __sb_ = _VSTD::move(__rhs.__sb_); |
675 | 0 | return *this; |
676 | 0 | } |
677 | | _LIBCPP_INLINE_VISIBILITY |
678 | | void swap(basic_istringstream& __rhs) { |
679 | | basic_istream<char_type, traits_type>::swap(__rhs); |
680 | | __sb_.swap(__rhs.__sb_); |
681 | | } |
682 | | |
683 | | // [istringstream.members] Member functions: |
684 | | _LIBCPP_INLINE_VISIBILITY |
685 | | basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { |
686 | | return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); |
687 | | } |
688 | | _LIBCPP_INLINE_VISIBILITY |
689 | | string_type str() const { |
690 | | return __sb_.str(); |
691 | | } |
692 | | _LIBCPP_INLINE_VISIBILITY |
693 | | void str(const string_type& __s) { |
694 | | __sb_.str(__s); |
695 | | } |
696 | | }; |
697 | | |
698 | | template <class _CharT, class _Traits, class _Allocator> |
699 | | inline _LIBCPP_INLINE_VISIBILITY |
700 | | void |
701 | | swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, |
702 | | basic_istringstream<_CharT, _Traits, _Allocator>& __y) |
703 | | { |
704 | | __x.swap(__y); |
705 | | } |
706 | | |
707 | | // Class template basic_ostringstream [ostringstream] |
708 | | |
709 | | template <class _CharT, class _Traits, class _Allocator> |
710 | | class _LIBCPP_TEMPLATE_VIS basic_ostringstream |
711 | | : public basic_ostream<_CharT, _Traits> |
712 | | { |
713 | | public: |
714 | | typedef _CharT char_type; |
715 | | typedef _Traits traits_type; |
716 | | typedef typename traits_type::int_type int_type; |
717 | | typedef typename traits_type::pos_type pos_type; |
718 | | typedef typename traits_type::off_type off_type; |
719 | | typedef _Allocator allocator_type; |
720 | | |
721 | | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
722 | | |
723 | | private: |
724 | | basic_stringbuf<char_type, traits_type, allocator_type> __sb_; |
725 | | |
726 | | public: |
727 | | // [ostringstream.cons] Constructors: |
728 | | _LIBCPP_INLINE_VISIBILITY |
729 | | basic_ostringstream() |
730 | | : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(ios_base::out) {} |
731 | | |
732 | | _LIBCPP_INLINE_VISIBILITY |
733 | | explicit basic_ostringstream(ios_base::openmode __wch) |
734 | | : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::out) {} |
735 | | |
736 | | _LIBCPP_INLINE_VISIBILITY |
737 | | explicit basic_ostringstream(const string_type& __s, |
738 | | ios_base::openmode __wch = ios_base::out) |
739 | | : basic_ostream<_CharT, _Traits>(&__sb_) |
740 | | , __sb_(__s, __wch | ios_base::out) |
741 | | { } |
742 | | |
743 | | _LIBCPP_INLINE_VISIBILITY |
744 | | basic_ostringstream(basic_ostringstream&& __rhs) |
745 | | : basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)) |
746 | | , __sb_(_VSTD::move(__rhs.__sb_)) |
747 | | { |
748 | | basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_); |
749 | | } |
750 | | |
751 | | // [ostringstream.assign] Assign and swap: |
752 | 0 | basic_ostringstream& operator=(basic_ostringstream&& __rhs) { |
753 | 0 | basic_ostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); |
754 | 0 | __sb_ = _VSTD::move(__rhs.__sb_); |
755 | 0 | return *this; |
756 | 0 | } |
757 | | |
758 | | _LIBCPP_INLINE_VISIBILITY |
759 | | void swap(basic_ostringstream& __rhs) { |
760 | | basic_ostream<char_type, traits_type>::swap(__rhs); |
761 | | __sb_.swap(__rhs.__sb_); |
762 | | } |
763 | | |
764 | | // [ostringstream.members] Member functions: |
765 | | _LIBCPP_INLINE_VISIBILITY |
766 | | basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { |
767 | | return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); |
768 | | } |
769 | | _LIBCPP_INLINE_VISIBILITY |
770 | | string_type str() const { |
771 | | return __sb_.str(); |
772 | | } |
773 | | _LIBCPP_INLINE_VISIBILITY |
774 | | void str(const string_type& __s) { |
775 | | __sb_.str(__s); |
776 | | } |
777 | | }; |
778 | | |
779 | | template <class _CharT, class _Traits, class _Allocator> |
780 | | inline _LIBCPP_INLINE_VISIBILITY |
781 | | void |
782 | | swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, |
783 | | basic_ostringstream<_CharT, _Traits, _Allocator>& __y) |
784 | | { |
785 | | __x.swap(__y); |
786 | | } |
787 | | |
788 | | // Class template basic_stringstream [stringstream] |
789 | | |
790 | | template <class _CharT, class _Traits, class _Allocator> |
791 | | class _LIBCPP_TEMPLATE_VIS basic_stringstream |
792 | | : public basic_iostream<_CharT, _Traits> |
793 | | { |
794 | | public: |
795 | | typedef _CharT char_type; |
796 | | typedef _Traits traits_type; |
797 | | typedef typename traits_type::int_type int_type; |
798 | | typedef typename traits_type::pos_type pos_type; |
799 | | typedef typename traits_type::off_type off_type; |
800 | | typedef _Allocator allocator_type; |
801 | | |
802 | | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
803 | | |
804 | | private: |
805 | | basic_stringbuf<char_type, traits_type, allocator_type> __sb_; |
806 | | |
807 | | public: |
808 | | // [stringstream.cons] constructors |
809 | | _LIBCPP_INLINE_VISIBILITY |
810 | | basic_stringstream() |
811 | | : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(ios_base::in | ios_base::out) {} |
812 | | |
813 | | _LIBCPP_INLINE_VISIBILITY |
814 | | explicit basic_stringstream(ios_base::openmode __wch) |
815 | | : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__wch) {} |
816 | | |
817 | | _LIBCPP_INLINE_VISIBILITY |
818 | | explicit basic_stringstream(const string_type& __s, |
819 | | ios_base::openmode __wch = ios_base::in | ios_base::out) |
820 | | : basic_iostream<_CharT, _Traits>(&__sb_) |
821 | | , __sb_(__s, __wch) |
822 | | { } |
823 | | |
824 | | _LIBCPP_INLINE_VISIBILITY |
825 | | basic_stringstream(basic_stringstream&& __rhs) |
826 | | : basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)) |
827 | | , __sb_(_VSTD::move(__rhs.__sb_)) |
828 | | { |
829 | | basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); |
830 | | } |
831 | | |
832 | | // [stringstream.assign] Assign and swap: |
833 | 0 | basic_stringstream& operator=(basic_stringstream&& __rhs) { |
834 | 0 | basic_iostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); |
835 | 0 | __sb_ = _VSTD::move(__rhs.__sb_); |
836 | 0 | return *this; |
837 | 0 | } |
838 | | _LIBCPP_INLINE_VISIBILITY |
839 | | void swap(basic_stringstream& __rhs) { |
840 | | basic_iostream<char_type, traits_type>::swap(__rhs); |
841 | | __sb_.swap(__rhs.__sb_); |
842 | | } |
843 | | |
844 | | // [stringstream.members] Member functions: |
845 | | _LIBCPP_INLINE_VISIBILITY |
846 | | basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { |
847 | | return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); |
848 | | } |
849 | | _LIBCPP_INLINE_VISIBILITY |
850 | | string_type str() const { |
851 | | return __sb_.str(); |
852 | | } |
853 | | _LIBCPP_INLINE_VISIBILITY |
854 | | void str(const string_type& __s) { |
855 | | __sb_.str(__s); |
856 | | } |
857 | | }; |
858 | | |
859 | | template <class _CharT, class _Traits, class _Allocator> |
860 | | inline _LIBCPP_INLINE_VISIBILITY |
861 | | void |
862 | | swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, |
863 | | basic_stringstream<_CharT, _Traits, _Allocator>& __y) |
864 | | { |
865 | | __x.swap(__y); |
866 | | } |
867 | | |
868 | | #if defined(_LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1) |
869 | | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>; |
870 | | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>; |
871 | | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>; |
872 | | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>; |
873 | | #endif |
874 | | |
875 | | _LIBCPP_END_NAMESPACE_STD |
876 | | |
877 | | _LIBCPP_POP_MACROS |
878 | | |
879 | | #if _LIBCPP_STD_VER <= 20 && !defined(_LIPCPP_REMOVE_TRANSITIVE_INCLUDES) |
880 | | # include <type_traits> |
881 | | #endif |
882 | | |
883 | | #endif // _LIBCPP_SSTREAM |