ReactOS 0.4.15-dev-5863-g1fe3ab7
_string_io.c File Reference
#include <stl/_string_io.h>
#include <stl/_ctype.h>
Include dependency graph for _string_io.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _STLP_STRING_IO_C
 

Functions

template<class _CharT , class _Traits >
_STLP_BEGIN_NAMESPACE bool _STLP_CALL __stlp_string_fill (basic_ostream< _CharT, _Traits > &__os, basic_streambuf< _CharT, _Traits > *__buf, streamsize __n)
 
template<class _CharT , class _Traits , class _Alloc >
basic_ostream< _CharT, _Traits > &_STLP_CALL operator<< (basic_ostream< _CharT, _Traits > &__os, const basic_string< _CharT, _Traits, _Alloc > &__s)
 
template<class _CharT , class _Traits , class _Alloc >
basic_istream< _CharT, _Traits > &_STLP_CALL operator>> (basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Alloc > &__s)
 
template<class _CharT , class _Traits , class _Alloc >
basic_istream< _CharT, _Traits > &_STLP_CALL getline (basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Alloc > &__s, _CharT __delim)
 

Macro Definition Documentation

◆ _STLP_STRING_IO_C

#define _STLP_STRING_IO_C

Definition at line 2 of file _string_io.c.

Function Documentation

◆ __stlp_string_fill()

template<class _CharT , class _Traits >
_STLP_BEGIN_NAMESPACE bool _STLP_CALL __stlp_string_fill ( basic_ostream< _CharT, _Traits > &  __os,
basic_streambuf< _CharT, _Traits > *  __buf,
streamsize  __n 
)

Definition at line 16 of file _string_io.c.

18 {
19 _CharT __f = __os.fill();
20 for (streamsize __i = 0; __i < __n; ++__i) {
21 if (_Traits::eq_int_type(__buf->sputc(__f), _Traits::eof()))
22 return false;
23 }
24 return true;
25}
return __n
Definition: _algo.h:75
ptrdiff_t streamsize
Definition: char_traits.h:81
char_type fill() const
Definition: _ios.h:81
int_type sputc(char_type __c)
Definition: _streambuf.h:198

Referenced by operator<<().

◆ getline()

template<class _CharT , class _Traits , class _Alloc >
basic_istream< _CharT, _Traits > &_STLP_CALL getline ( basic_istream< _CharT, _Traits > &  __is,
basic_string< _CharT, _Traits, _Alloc > &  __s,
_CharT  __delim 
)

Definition at line 133 of file _string_io.c.

135 {
136 typedef basic_istream<_CharT, _Traits> __istream;
137 typedef typename basic_string<_CharT, _Traits, _Alloc>::size_type size_type;
138 size_type __nread = 0;
139 typename basic_istream<_CharT, _Traits>::sentry __sentry(__is, true);
140 if (__sentry) {
142 __s.clear();
143
144 while (__nread < __s.max_size()) {
145 int __c1 = __buf->sbumpc();
146 if (_Traits::eq_int_type(__c1, _Traits::eof())) {
147 __is.setstate(__istream::eofbit);
148 break;
149 }
150 else {
151 ++__nread;
152 _CharT __c = _Traits::to_char_type(__c1);
153 if (!_Traits::eq(__c, __delim))
154 __s.push_back(__c);
155 else
156 break; // Character is extracted but not appended.
157 }
158 }
159 }
160 if (__nread == 0 || __nread >= __s.max_size())
161 __is.setstate(__istream::failbit);
162
163 return __is;
164}
basic_streambuf< _CharT, _Traits > * rdbuf() const
Definition: _ios.h:72
void setstate(iostate __state)
Definition: _ios.h:95
int_type sbumpc()
Definition: _streambuf.h:227
_Base::size_type size_type
Definition: _string.h:138
void clear()
Definition: _string.h:421
size_type max_size() const
Definition: _string.h:402
void push_back(_CharT __c)
Definition: _string.h:534
#define __c
Definition: schilyio.h:209

◆ operator<<()

template<class _CharT , class _Traits , class _Alloc >
basic_ostream< _CharT, _Traits > &_STLP_CALL operator<< ( basic_ostream< _CharT, _Traits > &  __os,
const basic_string< _CharT, _Traits, _Alloc > &  __s 
)

Definition at line 29 of file _string_io.c.

31 {
32 typedef basic_ostream<_CharT, _Traits> __ostream;
33 typedef typename basic_string<_CharT, _Traits, _Alloc>::size_type size_type;
34
35 // The hypothesis of this implementation is that size_type is unsigned:
36 _STLP_STATIC_ASSERT(__STATIC_CAST(size_type, -1) > 0)
37
38 typename __ostream::sentry __sentry(__os);
39 bool __ok = false;
40
41 if (__sentry) {
42 __ok = true;
43 size_type __n = __s.size();
44 const bool __left = (__os.flags() & __ostream::left) != 0;
45 const streamsize __w = __os.width(0);
46 basic_streambuf<_CharT, _Traits>* __buf = __os.rdbuf();
47
48 const bool __need_pad = (((sizeof(streamsize) > sizeof(size_t)) && (__STATIC_CAST(streamsize, __n) < __w)) ||
49 ((sizeof(streamsize) <= sizeof(size_t)) && (__n < __STATIC_CAST(size_t, __w))));
50 streamsize __pad_len = __need_pad ? __w - __n : 0;
51
52 if (!__left)
53 __ok = __stlp_string_fill(__os, __buf, __pad_len);
54
55 __ok = __ok && (__buf->sputn(__s.data(), streamsize(__n)) == streamsize(__n));
56
57 if (__left)
58 __ok = __ok && __stlp_string_fill(__os, __buf, __pad_len);
59 }
60
61 if (!__ok)
62 __os.setstate(__ostream::failbit);
63
64 return __os;
65}
_STLP_BEGIN_NAMESPACE bool _STLP_CALL __stlp_string_fill(basic_ostream< _CharT, _Traits > &__os, basic_streambuf< _CharT, _Traits > *__buf, streamsize __n)
Definition: _string_io.c:16
streamsize sputn(const char_type *__s, streamsize __n)
Definition: _streambuf.h:204
size_type size() const
Definition: _string.h:400
const _CharT * data() const
Definition: _string.h:950
#define _STLP_STATIC_ASSERT(expr)
Definition: features.h:313
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
char typename[32]
Definition: main.c:84
if(dx< 0)
Definition: linetemp.h:194
#define false
Definition: osdep.h:35

◆ operator>>()

template<class _CharT , class _Traits , class _Alloc >
basic_istream< _CharT, _Traits > &_STLP_CALL operator>> ( basic_istream< _CharT, _Traits > &  __is,
basic_string< _CharT, _Traits, _Alloc > &  __s 
)

Definition at line 69 of file _string_io.c.

70 {
71 typedef basic_istream<_CharT, _Traits> __istream;
72 typedef typename basic_string<_CharT, _Traits, _Alloc>::size_type size_type;
73
74 // The hypothesis of this implementation is that size_type is unsigned:
75 _STLP_STATIC_ASSERT(__STATIC_CAST(size_type, -1) > 0)
76
77 typename __istream::sentry __sentry(__is);
78
79 if (__sentry) {
80 basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf();
81 typedef ctype<_CharT> _C_type;
82
83 const locale& __loc = __is.getloc();
84 const _C_type& _Ctype = use_facet<_C_type>(__loc);
85 __s.clear();
86 streamsize __width = __is.width(0);
87 size_type __n;
88 if (__width <= 0)
89 __n = __s.max_size();
90 /* __width can only overflow size_type if sizeof(streamsize) > sizeof(size_type)
91 * because here we know that __width is positive and the stattic assertion check
92 * that size_type is unsigned.
93 */
94 else if (sizeof(streamsize) > sizeof(size_type) &&
95 (__width > __STATIC_CAST(streamsize, __s.max_size())))
96 __n = 0;
97 else {
98 __n = __STATIC_CAST(size_type, __width);
99 __s.reserve(__n);
100 }
101
102 while (__n-- > 0) {
103 typename _Traits::int_type __c1 = __buf->sbumpc();
104 if (_Traits::eq_int_type(__c1, _Traits::eof())) {
105 __is.setstate(__istream::eofbit);
106 break;
107 }
108 else {
109 _CharT __c = _Traits::to_char_type(__c1);
110
111 if (_Ctype.is(_C_type::space, __c)) {
112 if (_Traits::eq_int_type(__buf->sputbackc(__c), _Traits::eof()))
113 __is.setstate(__istream::failbit);
114 break;
115 }
116 else
117 __s.push_back(__c);
118 }
119 }
120
121 // If we have read no characters, then set failbit.
122 if (__s.empty())
123 __is.setstate(__istream::failbit);
124 }
125 else
126 __is.setstate(__istream::failbit);
127
128 return __is;
129}
int_type sputbackc(char_type __c)
Definition: _streambuf.h:241
void reserve(size_type=0)
Definition: _string.c:158
bool empty() const
Definition: _string.h:428
Definition: _ctype.h:58
Definition: _locale.h:75