1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_string_io.c Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,172 @@
1.4 +#ifndef _STLP_STRING_IO_C
1.5 +#define _STLP_STRING_IO_C
1.6 +
1.7 +#ifndef _STLP_STRING_IO_H
1.8 +# include <stl/_string_io.h>
1.9 +#endif
1.10 +
1.11 +#ifndef _STLP_INTERNAL_CTYPE_H
1.12 +# include <stl/_ctype.h>
1.13 +#endif
1.14 +
1.15 +_STLP_BEGIN_NAMESPACE
1.16 +
1.17 +template <class _CharT, class _Traits>
1.18 +bool _STLP_CALL
1.19 +__stlp_string_fill(basic_ostream<_CharT, _Traits>& __os,
1.20 + basic_streambuf<_CharT, _Traits>* __buf,
1.21 + streamsize __n) {
1.22 + _CharT __f = __os.fill();
1.23 + for (streamsize __i = 0; __i < __n; ++__i) {
1.24 + if (_Traits::eq_int_type(__buf->sputc(__f), _Traits::eof()))
1.25 + return false;
1.26 + }
1.27 + return true;
1.28 +}
1.29 +
1.30 +
1.31 +template <class _CharT, class _Traits, class _Alloc>
1.32 +basic_ostream<_CharT, _Traits>& _STLP_CALL
1.33 +operator << (basic_ostream<_CharT, _Traits>& __os,
1.34 + const basic_string<_CharT,_Traits,_Alloc>& __s) {
1.35 + typedef basic_ostream<_CharT, _Traits> __ostream;
1.36 + typedef typename basic_string<_CharT, _Traits, _Alloc>::size_type size_type;
1.37 +
1.38 + // The hypothesis of this implementation is that size_type is unsigned:
1.39 + _STLP_STATIC_ASSERT(__STATIC_CAST(size_type, -1) > 0)
1.40 +
1.41 + typename __ostream::sentry __sentry(__os);
1.42 + bool __ok = false;
1.43 +
1.44 + if (__sentry) {
1.45 + __ok = true;
1.46 + size_type __n = __s.size();
1.47 + const bool __left = (__os.flags() & __ostream::left) != 0;
1.48 + const streamsize __w = __os.width(0);
1.49 + basic_streambuf<_CharT, _Traits>* __buf = __os.rdbuf();
1.50 +
1.51 + const bool __need_pad = (((sizeof(streamsize) > sizeof(size_t)) && (__STATIC_CAST(streamsize, __n) < __w)) ||
1.52 + ((sizeof(streamsize) <= sizeof(size_t)) && (__n < __STATIC_CAST(size_t, __w))));
1.53 + streamsize __pad_len = __need_pad ? __w - __n : 0;
1.54 +
1.55 + if (!__left)
1.56 + __ok = __stlp_string_fill(__os, __buf, __pad_len);
1.57 +
1.58 + __ok = __ok && (__buf->sputn(__s.data(), streamsize(__n)) == streamsize(__n));
1.59 +
1.60 + if (__left)
1.61 + __ok = __ok && __stlp_string_fill(__os, __buf, __pad_len);
1.62 + }
1.63 +
1.64 + if (!__ok)
1.65 + __os.setstate(__ostream::failbit);
1.66 +
1.67 + return __os;
1.68 +}
1.69 +
1.70 +template <class _CharT, class _Traits, class _Alloc>
1.71 +basic_istream<_CharT, _Traits>& _STLP_CALL
1.72 +operator >> (basic_istream<_CharT, _Traits>& __is,
1.73 + basic_string<_CharT,_Traits, _Alloc>& __s) {
1.74 + typedef basic_istream<_CharT, _Traits> __istream;
1.75 + typedef typename basic_string<_CharT, _Traits, _Alloc>::size_type size_type;
1.76 +
1.77 + // The hypothesis of this implementation is that size_type is unsigned:
1.78 + _STLP_STATIC_ASSERT(__STATIC_CAST(size_type, -1) > 0)
1.79 +
1.80 + typename __istream::sentry __sentry(__is);
1.81 +
1.82 + if (__sentry) {
1.83 + basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf();
1.84 + typedef ctype<_CharT> _C_type;
1.85 +
1.86 + const locale& __loc = __is.getloc();
1.87 + const _C_type& _Ctype = use_facet<_C_type>(__loc);
1.88 + __s.clear();
1.89 + streamsize __width = __is.width(0);
1.90 + size_type __n;
1.91 + if (__width <= 0)
1.92 + __n = __s.max_size();
1.93 + /* __width can only overflow size_type if sizeof(streamsize) > sizeof(size_type)
1.94 + * because here we know that __width is positive and the stattic assertion check
1.95 + * that size_type is unsigned.
1.96 + */
1.97 + else if (sizeof(streamsize) > sizeof(size_type) &&
1.98 + (__width > __STATIC_CAST(streamsize, __s.max_size())))
1.99 + __n = 0;
1.100 + else {
1.101 + __n = __STATIC_CAST(size_type, __width);
1.102 + __s.reserve(__n);
1.103 + }
1.104 +
1.105 + while (__n-- > 0) {
1.106 + typename _Traits::int_type __c1 = __buf->sbumpc();
1.107 + if (_Traits::eq_int_type(__c1, _Traits::eof())) {
1.108 + __is.setstate(__istream::eofbit);
1.109 + break;
1.110 + }
1.111 + else {
1.112 + _CharT __c = _Traits::to_char_type(__c1);
1.113 +
1.114 + if (_Ctype.is(_C_type::space, __c)) {
1.115 + if (_Traits::eq_int_type(__buf->sputbackc(__c), _Traits::eof()))
1.116 + __is.setstate(__istream::failbit);
1.117 + break;
1.118 + }
1.119 + else
1.120 + __s.push_back(__c);
1.121 + }
1.122 + }
1.123 +
1.124 + // If we have read no characters, then set failbit.
1.125 + if (__s.empty())
1.126 + __is.setstate(__istream::failbit);
1.127 + }
1.128 + else
1.129 + __is.setstate(__istream::failbit);
1.130 +
1.131 + return __is;
1.132 +}
1.133 +
1.134 +template <class _CharT, class _Traits, class _Alloc>
1.135 +basic_istream<_CharT, _Traits>& _STLP_CALL
1.136 +getline(basic_istream<_CharT, _Traits>& __is,
1.137 + basic_string<_CharT,_Traits,_Alloc>& __s,
1.138 + _CharT __delim) {
1.139 + typedef basic_istream<_CharT, _Traits> __istream;
1.140 + typedef typename basic_string<_CharT, _Traits, _Alloc>::size_type size_type;
1.141 + size_type __nread = 0;
1.142 + typename basic_istream<_CharT, _Traits>::sentry __sentry(__is, true);
1.143 + if (__sentry) {
1.144 + basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf();
1.145 + __s.clear();
1.146 +
1.147 + while (__nread < __s.max_size()) {
1.148 + int __c1 = __buf->sbumpc();
1.149 + if (_Traits::eq_int_type(__c1, _Traits::eof())) {
1.150 + __is.setstate(__istream::eofbit);
1.151 + break;
1.152 + }
1.153 + else {
1.154 + ++__nread;
1.155 + _CharT __c = _Traits::to_char_type(__c1);
1.156 + if (!_Traits::eq(__c, __delim))
1.157 + __s.push_back(__c);
1.158 + else
1.159 + break; // Character is extracted but not appended.
1.160 + }
1.161 + }
1.162 + }
1.163 + if (__nread == 0 || __nread >= __s.max_size())
1.164 + __is.setstate(__istream::failbit);
1.165 +
1.166 + return __is;
1.167 +}
1.168 +
1.169 +_STLP_END_NAMESPACE
1.170 +
1.171 +#endif
1.172 +
1.173 +// Local Variables:
1.174 +// mode:C++
1.175 +// End: