1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_string_io.c Wed Mar 31 12:27:01 2010 +0100
1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_string_io.c Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -1,98 +1,56 @@
1.4 -/*
1.5 -* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.6 -
1.7 -* Redistribution and use in source and binary forms, with or without
1.8 -* modification, are permitted provided that the following conditions are met:
1.9 -
1.10 -* Redistributions of source code must retain the above copyright notice, this
1.11 -* list of conditions and the following disclaimer.
1.12 -* Redistributions in binary form must reproduce the above copyright notice,
1.13 -* this list of conditions and the following disclaimer in the documentation
1.14 -* and/or other materials provided with the distribution.
1.15 -* Neither the name of Nokia Corporation nor the names of its contributors
1.16 -* may be used to endorse or promote products derived from this software
1.17 -* without specific prior written permission.
1.18 -
1.19 -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1.20 -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.21 -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1.22 -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1.23 -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.24 -* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1.25 -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1.26 -* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1.27 -* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1.28 -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.29 -*
1.30 -* Description:
1.31 -*
1.32 -*/
1.33 -
1.34 #ifndef _STLP_STRING_IO_C
1.35 #define _STLP_STRING_IO_C
1.36
1.37 #ifndef _STLP_STRING_IO_H
1.38 -# include <stl/_string_io.h>
1.39 +# include <stl/_string_io.h>
1.40 #endif
1.41
1.42 #ifndef _STLP_INTERNAL_CTYPE_H
1.43 -# include <stl/_ctype.h>
1.44 +# include <stl/_ctype.h>
1.45 #endif
1.46
1.47 -# ifdef _STLP_DEBUG
1.48 -# define basic_string _Nondebug_string
1.49 -# endif
1.50 -
1.51 _STLP_BEGIN_NAMESPACE
1.52
1.53 -# if defined (_STLP_OWN_IOSTREAMS)
1.54 -# define _STLP_USING_IO
1.55 -# else
1.56 -# define _STLP_USING_IO _STLP_USING_VENDOR_STD
1.57 -# endif
1.58 -
1.59 -#if defined (_STLP_USE_NEW_IOSTREAMS)
1.60 -
1.61 template <class _CharT, class _Traits>
1.62 bool _STLP_CALL
1.63 __stlp_string_fill(basic_ostream<_CharT, _Traits>& __os,
1.64 - basic_streambuf<_CharT, _Traits>* __buf,
1.65 - size_t __n)
1.66 -{
1.67 + basic_streambuf<_CharT, _Traits>* __buf,
1.68 + streamsize __n) {
1.69 _CharT __f = __os.fill();
1.70 - size_t __i;
1.71 - bool __ok = true;
1.72 + for (streamsize __i = 0; __i < __n; ++__i) {
1.73 + if (_Traits::eq_int_type(__buf->sputc(__f), _Traits::eof()))
1.74 + return false;
1.75 + }
1.76 + return true;
1.77 +}
1.78
1.79 - for (__i = 0; __i < __n; ++__i)
1.80 - __ok = __ok && !_Traits::eq_int_type(__buf->sputc(__f), _Traits::eof());
1.81 - return __ok;
1.82 -}
1.83
1.84 template <class _CharT, class _Traits, class _Alloc>
1.85 basic_ostream<_CharT, _Traits>& _STLP_CALL
1.86 -operator<<(basic_ostream<_CharT, _Traits>& __os,
1.87 - const basic_string<_CharT,_Traits,_Alloc>& __s)
1.88 -{
1.89 +operator << (basic_ostream<_CharT, _Traits>& __os,
1.90 + const basic_string<_CharT,_Traits,_Alloc>& __s) {
1.91 + typedef basic_ostream<_CharT, _Traits> __ostream;
1.92 + typedef typename basic_string<_CharT, _Traits, _Alloc>::size_type size_type;
1.93
1.94 - _STLP_USING_IO
1.95 - typedef basic_ostream<_CharT, _Traits> __ostream;
1.96 + // The hypothesis of this implementation is that size_type is unsigned:
1.97 + _STLP_STATIC_ASSERT(__STATIC_CAST(size_type, -1) > 0)
1.98 +
1.99 typename __ostream::sentry __sentry(__os);
1.100 bool __ok = false;
1.101
1.102 if (__sentry) {
1.103 __ok = true;
1.104 - size_t __n = __s.size();
1.105 - size_t __pad_len = 0;
1.106 + size_type __n = __s.size();
1.107 const bool __left = (__os.flags() & __ostream::left) != 0;
1.108 - const size_t __w = __os.width(0);
1.109 + const streamsize __w = __os.width(0);
1.110 basic_streambuf<_CharT, _Traits>* __buf = __os.rdbuf();
1.111
1.112 - if (__n < __w) {
1.113 - __pad_len = __w - __n;
1.114 - }
1.115 -
1.116 + const bool __need_pad = (((sizeof(streamsize) > sizeof(size_t)) && (__STATIC_CAST(streamsize, __n) < __w)) ||
1.117 + ((sizeof(streamsize) <= sizeof(size_t)) && (__n < __STATIC_CAST(size_t, __w))));
1.118 + streamsize __pad_len = __need_pad ? __w - __n : 0;
1.119 +
1.120 if (!__left)
1.121 - __ok = __stlp_string_fill(__os, __buf, __pad_len);
1.122 + __ok = __stlp_string_fill(__os, __buf, __pad_len);
1.123
1.124 __ok = __ok && (__buf->sputn(__s.data(), streamsize(__n)) == streamsize(__n));
1.125
1.126 @@ -105,42 +63,41 @@
1.127
1.128 return __os;
1.129 }
1.130 -
1.131 +
1.132 template <class _CharT, class _Traits, class _Alloc>
1.133 -basic_istream<_CharT, _Traits>& _STLP_CALL
1.134 -operator>>(basic_istream<_CharT, _Traits>& __is,
1.135 - basic_string<_CharT,_Traits, _Alloc>& __s)
1.136 -{
1.137 - _STLP_USING_IO
1.138 +basic_istream<_CharT, _Traits>& _STLP_CALL
1.139 +operator >> (basic_istream<_CharT, _Traits>& __is,
1.140 + basic_string<_CharT,_Traits, _Alloc>& __s) {
1.141 typedef basic_istream<_CharT, _Traits> __istream;
1.142 + typedef typename basic_string<_CharT, _Traits, _Alloc>::size_type size_type;
1.143 +
1.144 + // The hypothesis of this implementation is that size_type is unsigned:
1.145 + _STLP_STATIC_ASSERT(__STATIC_CAST(size_type, -1) > 0)
1.146 +
1.147 typename __istream::sentry __sentry(__is);
1.148
1.149 if (__sentry) {
1.150 basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf();
1.151 typedef ctype<_CharT> _C_type;
1.152
1.153 -#ifdef _STLP_OWN_IOSTREAMS
1.154 - // const _C_type& _Ctype = use_facet<_C_type>(__loc);
1.155 - const _C_type& _Ctype = *(const _C_type*)__is._M_ctype_facet();
1.156 -#else
1.157 -# if defined (_STLP_MSVC) && (_STLP_MSVC <= 1200 ) || defined (__ICL)
1.158 - const locale& __loc = __is.getloc();
1.159 - const _C_type& _Ctype = use_facet(__loc , ( _C_type * ) 0, true);
1.160 -# elif defined (__SUNPRO_CC)
1.161 - const locale& __loc = __is.getloc();
1.162 - const _C_type& _Ctype = use_facet(__loc , ( _C_type * ) 0);
1.163 -# else
1.164 const locale& __loc = __is.getloc();
1.165 const _C_type& _Ctype = use_facet<_C_type>(__loc);
1.166 -# endif
1.167 -#endif
1.168 __s.clear();
1.169 - size_t __n = __is.width(0);
1.170 - if (__n == 0)
1.171 - __n = __STATIC_CAST(size_t,-1);
1.172 - else
1.173 + streamsize __width = __is.width(0);
1.174 + size_type __n;
1.175 + if (__width <= 0)
1.176 + __n = __s.max_size();
1.177 + /* __width can only overflow size_type if sizeof(streamsize) > sizeof(size_type)
1.178 + * because here we know that __width is positive and the stattic assertion check
1.179 + * that size_type is unsigned.
1.180 + */
1.181 + else if (sizeof(streamsize) > sizeof(size_type) &&
1.182 + (__width > __STATIC_CAST(streamsize, __s.max_size())))
1.183 + __n = 0;
1.184 + else {
1.185 + __n = __STATIC_CAST(size_type, __width);
1.186 __s.reserve(__n);
1.187 -
1.188 + }
1.189
1.190 while (__n-- > 0) {
1.191 typename _Traits::int_type __c1 = __buf->sbumpc();
1.192 @@ -156,18 +113,13 @@
1.193 __is.setstate(__istream::failbit);
1.194 break;
1.195 }
1.196 -#ifdef __SYMBIAN32__
1.197 - else if (__c == '\b') {
1.198 - __s.pop_back();
1.199 - }
1.200 -#endif
1.201 else
1.202 __s.push_back(__c);
1.203 }
1.204 }
1.205 -
1.206 +
1.207 // If we have read no characters, then set failbit.
1.208 - if (__s.size() == 0)
1.209 + if (__s.empty())
1.210 __is.setstate(__istream::failbit);
1.211 }
1.212 else
1.213 @@ -176,15 +128,14 @@
1.214 return __is;
1.215 }
1.216
1.217 -template <class _CharT, class _Traits, class _Alloc>
1.218 -basic_istream<_CharT, _Traits>& _STLP_CALL
1.219 +template <class _CharT, class _Traits, class _Alloc>
1.220 +basic_istream<_CharT, _Traits>& _STLP_CALL
1.221 getline(basic_istream<_CharT, _Traits>& __is,
1.222 basic_string<_CharT,_Traits,_Alloc>& __s,
1.223 - _CharT __delim)
1.224 -{
1.225 - _STLP_USING_IO
1.226 + _CharT __delim) {
1.227 typedef basic_istream<_CharT, _Traits> __istream;
1.228 - size_t __nread = 0;
1.229 + typedef typename basic_string<_CharT, _Traits, _Alloc>::size_type size_type;
1.230 + size_type __nread = 0;
1.231 typename basic_istream<_CharT, _Traits>::sentry __sentry(__is, true);
1.232 if (__sentry) {
1.233 basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf();
1.234 @@ -199,7 +150,7 @@
1.235 else {
1.236 ++__nread;
1.237 _CharT __c = _Traits::to_char_type(__c1);
1.238 - if (!_Traits::eq(__c, __delim))
1.239 + if (!_Traits::eq(__c, __delim))
1.240 __s.push_back(__c);
1.241 else
1.242 break; // Character is extracted but not appended.
1.243 @@ -212,158 +163,10 @@
1.244 return __is;
1.245 }
1.246
1.247 -#elif ! defined ( _STLP_USE_NO_IOSTREAMS )
1.248 -
1.249 -// (reg) For Watcom IO, _OSTREAM_DLL tells if ostream class is in .exe or in .dll
1.250 -
1.251 -template <class _CharT, class _Traits, class _Alloc>
1.252 -_OSTREAM_DLL& _STLP_CALL operator<<(_OSTREAM_DLL& __os,
1.253 - const basic_string<_CharT,_Traits,_Alloc>& __s)
1.254 -{
1.255 - _STLP_USING_IO
1.256 - streambuf* __buf = __os.rdbuf();
1.257 - if (__buf) {
1.258 - size_t __n = __s.size();
1.259 - size_t __pad_len = 0;
1.260 - const bool __left = (__os.flags() & ios::left) !=0;
1.261 - const size_t __w = __os.width();
1.262 -
1.263 - if (__n < __w) {
1.264 - __pad_len = __w - __n;
1.265 - }
1.266 -
1.267 - if (!__left)
1.268 - __stlp_string_fill(__os, __buf, __pad_len);
1.269 -
1.270 - const size_t __nwritten = __buf->sputn(__s.data(), __n);
1.271 -
1.272 - if (__left)
1.273 - __stlp_string_fill(__os, __buf, __pad_len);
1.274 -
1.275 - if (__nwritten != __n)
1.276 - __os.clear(__os.rdstate() | ios::failbit);
1.277 -
1.278 - __os.width(0);
1.279 - }
1.280 - else
1.281 - __os.clear(__os.rdstate() | ios::badbit);
1.282 -
1.283 - return __os;
1.284 -}
1.285 -
1.286 -template <class _CharT, class _Traits, class _Alloc>
1.287 -_ISTREAM_DLL& _STLP_CALL operator>>(_ISTREAM_DLL& __is, basic_string<_CharT,_Traits,_Alloc>& __s)
1.288 -{
1.289 - _STLP_USING_IO
1.290 - if (!__is)
1.291 - return __is;
1.292 -
1.293 - streambuf* __buf = __is.rdbuf();
1.294 - if (__buf) {
1.295 -
1.296 - if (__is.flags() & ios::skipws) {
1.297 - // _CharT __c;
1.298 - int __c;
1.299 - do {
1.300 - __c = __buf->sbumpc();
1.301 - }
1.302 - while (__c != EOF && isspace((unsigned char)__c));
1.303 -
1.304 - if (__c == EOF) {
1.305 - __is.clear(__is.rdstate() | ios::eofbit | ios::failbit);
1.306 - }
1.307 - else {
1.308 - if (__buf->sputbackc(__c) == EOF)
1.309 - __is.clear(__is.rdstate() | ios::failbit);
1.310 - }
1.311 - }
1.312 -
1.313 - // If we arrive at end of file (or fail for some other reason) while
1.314 - // still discarding whitespace, then we don't try to read the string.
1.315 - if (__is) {
1.316 - __s.clear();
1.317 -
1.318 - size_t __n = __is.width();
1.319 - if (__n == 0)
1.320 - __n = __STATIC_CAST(size_t,-1);
1.321 - else
1.322 - __s.reserve(__n);
1.323 -
1.324 - while (__n-- > 0) {
1.325 - int __c1 = __buf->sbumpc();
1.326 - if (__c1 == EOF) {
1.327 - __is.clear(__is.rdstate() | ios::eofbit);
1.328 - break;
1.329 - }
1.330 - else {
1.331 - _CharT __c = _Traits::to_char_type(__c1);
1.332 -
1.333 - if (isspace((unsigned char) __c)) {
1.334 - if (__buf->sputbackc(__c) == EOF)
1.335 - __is.clear(__is.rdstate() | ios::failbit);
1.336 - break;
1.337 - }
1.338 - else
1.339 - __s.push_back(__c);
1.340 - }
1.341 - }
1.342 -
1.343 - // If we have read no characters, then set failbit.
1.344 - if (__s.size() == 0)
1.345 - __is.clear(__is.rdstate() | ios::failbit);
1.346 - }
1.347 -
1.348 - __is.width(0);
1.349 - }
1.350 - else // We have no streambuf.
1.351 - __is.clear(__is.rdstate() | ios::badbit);
1.352 -
1.353 - return __is;
1.354 -}
1.355 -
1.356 -template <class _CharT, class _Traits, class _Alloc>
1.357 -_ISTREAM_DLL& _STLP_CALL getline(_ISTREAM_DLL& __is,
1.358 - basic_string<_CharT,_Traits,_Alloc>& __s,
1.359 - _CharT __delim)
1.360 -{
1.361 - _STLP_USING_IO
1.362 - streambuf* __buf = __is.rdbuf();
1.363 - if (__buf) {
1.364 - size_t __nread = 0;
1.365 - if (__is) {
1.366 - __s.clear();
1.367 -
1.368 - while (__nread < __s.max_size()) {
1.369 - int __c1 = __buf->sbumpc();
1.370 - if (__c1 == EOF) {
1.371 - __is.clear(__is.rdstate() | ios::eofbit);
1.372 - break;
1.373 - }
1.374 - else {
1.375 - ++__nread;
1.376 - _CharT __c = _Traits::to_char_type(__c1);
1.377 - if (!_Traits::eq(__c, __delim))
1.378 - __s.push_back(__c);
1.379 - else
1.380 - break; // Character is extracted but not appended.
1.381 - }
1.382 - }
1.383 - }
1.384 -
1.385 - if (__nread == 0 || __nread >= __s.max_size())
1.386 - __is.clear(__is.rdstate() | ios::failbit);
1.387 - }
1.388 - else
1.389 - __is.clear(__is.rdstate() | ios::badbit);
1.390 -
1.391 - return __is;
1.392 -}
1.393 -
1.394 -# endif /* _STLP_NEW_IOSTREAMS */
1.395 -
1.396 _STLP_END_NAMESPACE
1.397
1.398 -// # undef _STLP_USING_IO
1.399 -# undef basic_string
1.400 +#endif
1.401
1.402 -#endif
1.403 +// Local Variables:
1.404 +// mode:C++
1.405 +// End: