ReactOS  0.4.14-dev-114-gc8cbd56
_istream.c File Reference
#include <stl/_istream.h>
#include <stl/_limits.h>
#include <stl/_num_get.h>
Include dependency graph for _istream.c:

Go to the source code of this file.

Classes

struct  _Is_not_wspace< _Traits >
 
struct  _Is_wspace_null< _Traits >
 
struct  _Scan_for_wspace< _Traits >
 
struct  _Scan_wspace_null< _Traits >
 
struct  _Scan_for_not_wspace< _Traits >
 
struct  _Scan_for_char_val< _Traits >
 
struct  _Scan_for_int_val< _Traits >
 

Macros

#define _STLP_ISTREAM_C
 
#define __BIS_int_type__   _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::int_type
 
#define __BIS_pos_type__   _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::pos_type
 
#define __BIS_off_type__   _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::off_type
 

Functions

template<class _CharT , class _Traits >
bool _STLP_CALL __pushback (basic_streambuf< _CharT, _Traits > *__buf, _CharT __c)
 
template<class _CharT , class _Traits , class _Number >
ios_base::iostate _STLP_CALL __get_num (basic_istream< _CharT, _Traits > &__that, _Number &__val)
 
template<class _CharT , class _Traits , class _Is_Delim >
_STLP_MOVE_TO_PRIV_NAMESPACE streamsize _STLP_CALL __read_unbuffered (basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__buf, streamsize _Num, _CharT *__s, _Is_Delim __is_delim, bool __extract_delim, bool __append_null, bool __is_getline)
 
template<class _CharT , class _Traits , class _Is_Delim , class _Scan_Delim >
streamsize _STLP_CALL __read_buffered (basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__buf, streamsize _Num, _CharT *__s, _Is_Delim __is_delim, _Scan_Delim __scan_delim, bool __extract_delim, bool __append_null, bool __is_getline)
 
template<class _CharT , class _Traits , class _Is_Delim >
void _STLP_CALL _M_ignore_unbuffered (basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__buf, _Is_Delim __is_delim, bool __extract_delim, bool __set_failbit)
 
template<class _CharT , class _Traits , class _Is_Delim , class _Scan_Delim >
void _STLP_CALL _M_ignore_buffered (basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__buf, _Is_Delim __is_delim, _Scan_Delim __scan_delim, bool __extract_delim, bool __set_failbit)
 
template<class _CharT , class _Traits , class _Max_Chars , class _Is_Delim >
streamsize _STLP_CALL _M_ignore_unbuffered (basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__buf, streamsize _Num, _Max_Chars __max_chars, _Is_Delim __is_delim, bool __extract_delim, bool __set_failbit)
 
template<class _CharT , class _Traits , class _Max_Chars , class _Is_Delim , class _Scan_Delim >
streamsize _STLP_CALL _M_ignore_buffered (basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__buf, streamsize _Num, _Max_Chars __max_chars, _Is_Delim __is_delim, _Scan_Delim __scan_delim, bool __extract_delim, bool __set_failbit)
 
template<class _CharT , class _Traits , class _Is_Delim >
_STLP_MOVE_TO_PRIV_NAMESPACE streamsize _STLP_CALL __copy_unbuffered (basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__src, basic_streambuf< _CharT, _Traits > *__dest, _Is_Delim __is_delim, bool __extract_delim, bool __rethrow)
 
template<class _CharT , class _Traits , class _Is_Delim , class _Scan_Delim >
streamsize _STLP_CALL __copy_buffered (basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__src, basic_streambuf< _CharT, _Traits > *__dest, _Scan_Delim __scan_delim, _Is_Delim __is_delim, bool __extract_delim, bool __rethrow)
 

Macro Definition Documentation

◆ __BIS_int_type__

#define __BIS_int_type__   _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::int_type

Definition at line 39 of file _istream.c.

◆ __BIS_off_type__

#define __BIS_off_type__   _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::off_type

Definition at line 41 of file _istream.c.

◆ __BIS_pos_type__

#define __BIS_pos_type__   _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::pos_type

Definition at line 40 of file _istream.c.

◆ _STLP_ISTREAM_C

#define _STLP_ISTREAM_C

Definition at line 19 of file _istream.c.

Function Documentation

◆ __copy_buffered()

template<class _CharT , class _Traits , class _Is_Delim , class _Scan_Delim >
streamsize _STLP_CALL __copy_buffered ( basic_istream< _CharT, _Traits > *  __that,
basic_streambuf< _CharT, _Traits > *  __src,
basic_streambuf< _CharT, _Traits > *  __dest,
_Scan_Delim  __scan_delim,
_Is_Delim  __is_delim,
bool  __extract_delim,
bool  __rethrow 
)

Definition at line 1282 of file _istream.c.

1285  {
1286  streamsize __extracted = 0;
1287  ios_base::iostate __status = 0;
1288  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
1289  //Borland compiler generates a warning if assignment because value is never used:
1290  int_type __c /*= _Traits::eof()*/;
1291  _CharT* __first = __src->_M_gptr();
1292  ptrdiff_t __avail = __src->_M_egptr() - __first;
1293  // fbp : introduced to move catch/try blocks out of the loop
1294  bool __do_handle_exceptions = false;
1295 
1296  _STLP_TRY {
1297  for (;;) {
1298  const _CharT* __last = __scan_delim(__first, __src->_M_egptr());
1299 
1300  // Try to copy the entire input buffer to the output buffer.
1301  streamsize __n = __dest->sputn(__first, __extract_delim && __last != __src->_M_egptr()
1302  ? (__last - __first) + 1
1303  : (__last - __first));
1304  __src->_M_gbump((int)__n);
1305  __extracted += __n;
1306 
1307  // from this on, catch() will call _M_handle_exceptions()
1308  __do_handle_exceptions = true;
1309 
1310  if (__n < __avail) // We found the delimiter, or else failed to
1311  break; // copy some characters.
1312 
1313  __c = __src->sgetc();
1314 
1315  // Three possibilities: we succeeded in refilling the buffer, or
1316  // we got EOF, or the streambuf has switched to unbuffered mode.
1317  __first = __src->_M_gptr();
1318  __avail = __src->_M_egptr() - __first;
1319 
1320  if (__avail > 0)
1321  {} // dwa 1/16/00 -- suppress a Metrowerks warning
1322  else if (__that->_S_eof(__c)) {
1323  __status |= ios_base::eofbit;
1324  break;
1325  }
1326  else {
1327  return __extracted + __copy_unbuffered(__that, __src, __dest, __is_delim,
1328  __extract_delim, __rethrow);
1329  }
1330 
1331  __do_handle_exceptions = false;
1332  }
1333  }
1334 
1335  _STLP_CATCH_ALL {
1336  // See 27.6.1.2.3, paragraph 13.
1337  if (__rethrow && __do_handle_exceptions && __extracted == 0)
1338  __that->_M_handle_exception(ios_base::failbit);
1339  }
1340 
1341  if (__status)
1342  __that->setstate(__status); // This might throw.
1343  return __extracted;
1344 }
static bool _STLP_CALL _S_eof(int_type __c)
Definition: _ios.h:110
return __n
Definition: _algo.h:75
void _M_handle_exception(ios_base::iostate __flag)
Definition: _ios.c:114
char_type * _M_egptr() const
Definition: _streambuf.h:104
#define __c
Definition: schilyio.h:209
char_type * _M_gptr() const
Definition: _streambuf.h:103
#define _STLP_CATCH_ALL
Definition: features.h:818
_STLP_INLINE_LOOP _InputIter __last
Definition: _algo.h:68
void _M_gbump(int __n)
Definition: _streambuf.h:105
int iostate
Definition: _ios_base.h:58
void setstate(iostate __state)
Definition: _ios.h:95
_STLP_MOVE_TO_PRIV_NAMESPACE streamsize _STLP_CALL __copy_unbuffered(basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__src, basic_streambuf< _CharT, _Traits > *__dest, _Is_Delim __is_delim, bool __extract_delim, bool __rethrow)
Definition: _istream.c:1213
streamsize sputn(const char_type *__s, streamsize __n)
Definition: _streambuf.h:204
#define _STLP_TRY
Definition: features.h:817
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
ptrdiff_t streamsize
Definition: char_traits.h:81
int_type sgetc()
Definition: _streambuf.h:233
_Traits::int_type int_type
Definition: _istream.h:75

Referenced by basic_istream< char, char_traits< char > >::get(), and basic_istream< char, char_traits< char > >::operator>>().

◆ __copy_unbuffered()

template<class _CharT , class _Traits , class _Is_Delim >
_STLP_MOVE_TO_PRIV_NAMESPACE streamsize _STLP_CALL __copy_unbuffered ( basic_istream< _CharT, _Traits > *  __that,
basic_streambuf< _CharT, _Traits > *  __src,
basic_streambuf< _CharT, _Traits > *  __dest,
_Is_Delim  __is_delim,
bool  __extract_delim,
bool  __rethrow 
)

Definition at line 1213 of file _istream.c.

1216  {
1217  streamsize __extracted = 0;
1218  ios_base::iostate __status = 0;
1219  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
1220  int_type __c;
1221 
1222  _STLP_TRY {
1223  for (;;) {
1224  // Get a character. If there's an exception, catch and (maybe) rethrow it.
1225  __c = __src->sbumpc();
1226 
1227  // If we failed to get a character, then quit.
1228  if (__that->_S_eof(__c)) {
1229  __status |= ios_base::eofbit;
1230  break;
1231  }
1232  // If it's the delimiter, then quit.
1233  else if (__is_delim(_Traits::to_char_type(__c))) {
1234  if (!__extract_delim && !__pushback(__src, _Traits::to_char_type(__c)))
1235  __status |= ios_base::failbit;
1236  break;
1237  }
1238  else {
1239  // Try to put the character in the output streambuf.
1240  bool __failed = false;
1241  _STLP_TRY {
1242  if (!__that->_S_eof(__dest->sputc(_Traits::to_char_type(__c))))
1243  ++__extracted;
1244  else
1245  __failed = true;
1246  }
1247  _STLP_CATCH_ALL {
1248  __failed = true;
1249  }
1250 
1251  // If we failed to put the character in the output streambuf, then
1252  // try to push it back to the input streambuf.
1253  if (__failed && !__pushback(__src, _Traits::to_char_type(__c)))
1254  __status |= ios_base::failbit;
1255 
1256  // fbp : avoiding infinite loop in io-27-6-1-2-3.exp
1257  if (__failed)
1258  break;
1259  }
1260 
1261  } /* for (;;) */
1262 
1263  }
1264  // fbp : this try/catch moved here in reasonable assumption
1265  // __is_delim never throw (__pushback is guaranteed not to)
1266  _STLP_CATCH_ALL {
1267  // See 27.6.1.2.3, paragraph 13.
1268  if (__rethrow && __extracted == 0)
1269  __that->_M_handle_exception(ios_base::failbit);
1270  }
1271  __that->setstate(__status);
1272  return __extracted;
1273 }
static bool _STLP_CALL _S_eof(int_type __c)
Definition: _ios.h:110
void _M_handle_exception(ios_base::iostate __flag)
Definition: _ios.c:114
int_type sputc(char_type __c)
Definition: _streambuf.h:198
#define __c
Definition: schilyio.h:209
int_type sbumpc()
Definition: _streambuf.h:227
#define _STLP_CATCH_ALL
Definition: features.h:818
bool _STLP_CALL __pushback(basic_streambuf< _CharT, _Traits > *__buf, _CharT __c)
Definition: _istream.c:168
int iostate
Definition: _ios_base.h:58
void setstate(iostate __state)
Definition: _ios.h:95
#define _STLP_TRY
Definition: features.h:817
ptrdiff_t streamsize
Definition: char_traits.h:81
_Traits::int_type int_type
Definition: _istream.h:75

Referenced by __copy_buffered(), basic_istream< char, char_traits< char > >::get(), and basic_istream< char, char_traits< char > >::operator>>().

◆ __get_num()

template<class _CharT , class _Traits , class _Number >
ios_base::iostate _STLP_CALL __get_num ( basic_istream< _CharT, _Traits > &  __that,
_Number &  __val 
)

Definition at line 186 of file _istream.c.

186  {
187  typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
188  ios_base::iostate __err = 0;
189  _Sentry __sentry( __that ); // Skip whitespace.
190  if (__sentry) {
192  _STLP_TRY {
193  // Do not remove additional parenthesis around use_facet instanciation, some compilers (VC6)
194  // require it when building the library.
195  (use_facet<_Num_get>(__that.getloc())).get(istreambuf_iterator<_CharT, _Traits>(__that.rdbuf()),
196  0, __that, __err, __val);
197  }
199  __that._M_handle_exception(ios_base::badbit);
200  }
201  if (__err) __that.setstate(__err);
202  }
203  return __err;
204 }
basic_streambuf< _CharT, _Traits > * rdbuf() const
Definition: _ios.h:72
void _M_handle_exception(ios_base::iostate __flag)
Definition: _ios.c:114
locale getloc() const
Definition: _ios_base.h:143
#define _STLP_CATCH_ALL
Definition: features.h:818
_STLP_INLINE_LOOP _InputIter const _Tp & __val
Definition: _algobase.h:656
int iostate
Definition: _ios_base.h:58
void setstate(iostate __state)
Definition: _ios.h:95
#define _STLP_TRY
Definition: features.h:817

Referenced by basic_istream< char, char_traits< char > >::operator>>().

◆ __pushback()

template<class _CharT , class _Traits >
bool _STLP_CALL __pushback ( basic_streambuf< _CharT, _Traits > *  __buf,
_CharT  __c 
)

Definition at line 168 of file _istream.c.

168  {
169  bool ret;
170  _STLP_TRY {
171  const typename _Traits::int_type __eof = _Traits::eof();
172  ret = !_Traits::eq_int_type(__buf->sputbackc(__c), __eof);
173  }
175  ret = false;
176  }
177  return ret;
178 }
#define __c
Definition: schilyio.h:209
#define _STLP_CATCH_ALL
Definition: features.h:818
int ret
_Check_return_ _CRTIMP int __cdecl __cdecl eof(_In_ int _FileHandle)
#define _STLP_TRY
Definition: features.h:817
int_type sputbackc(char_type __c)
Definition: _streambuf.h:241

Referenced by __copy_unbuffered(), and __read_unbuffered().

◆ __read_buffered()

template<class _CharT , class _Traits , class _Is_Delim , class _Scan_Delim >
streamsize _STLP_CALL __read_buffered ( basic_istream< _CharT, _Traits > *  __that,
basic_streambuf< _CharT, _Traits > *  __buf,
streamsize  _Num,
_CharT *  __s,
_Is_Delim  __is_delim,
_Scan_Delim  __scan_delim,
bool  __extract_delim,
bool  __append_null,
bool  __is_getline 
)

Definition at line 635 of file _istream.c.

639  {
640  streamsize __n = 0;
641  ios_base::iostate __status = 0;
642  bool __done = false;
643 
644  _STLP_TRY {
645  while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
646  const _CharT* __first = __buf->_M_gptr();
647  const _CharT* __last = __buf->_M_egptr();
648  //casting numeric_limits<ptrdiff_t>::max to streamsize only works is ptrdiff_t is signed or streamsize representation
649  //is larger than ptrdiff_t one.
650  _STLP_STATIC_ASSERT((sizeof(streamsize) > sizeof(ptrdiff_t)) ||
653 
654  const _CharT* __p = __scan_delim(__first, __last);
655  ptrdiff_t __chunk = (min) (ptrdiff_t(__p - __first), __request);
656  _Traits::copy(__s, __first, __chunk);
657  __s += __chunk;
658  __n += __chunk;
659  __buf->_M_gbump((int)__chunk);
660 
661  // We terminated by finding delim.
662  if (__p != __last && __p - __first <= __request) {
663  if (__extract_delim) {
664  __n += 1;
665  __buf->_M_gbump(1);
666  }
667  __done = true;
668  }
669 
670  // We terminated by reading all the characters we were asked for.
671  else if (__n == _Num) {
672 
673  // Find out if we have reached eof. This matters for getline.
674  if (__is_getline) {
675  if (__chunk == __last - __first) {
676  if (__that->_S_eof(__buf->sgetc()))
677  __status |= ios_base::eofbit;
678  }
679  else
680  __status |= ios_base::failbit;
681  }
682  __done = true;
683  }
684 
685  // The buffer contained fewer than _Num - __n characters. Either we're
686  // at eof, or we should refill the buffer and try again.
687  else {
688  if (__that->_S_eof(__buf->sgetc())) {
689  __status |= ios_base::eofbit;
690  __done = true;
691  }
692  }
693  } // Close the while loop.
694  }
696  __that->_M_handle_exception(ios_base::badbit);
697  __done = true;
698  }
699 
700  if (__done) {
701  if (__append_null)
702  *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
703  if (__status != 0)
704  __that->setstate(__status); // This might throw.
705  return __n;
706  }
707 
708  // If execution has reached this point, then we have an empty buffer but
709  // we have not reached eof. What that means is that the streambuf has
710  // decided to switch from buffered to unbuffered input. We switch to
711  // to __read_unbuffered.
712 
713  return __n + __read_unbuffered(__that, __buf, _Num - __n, __s, __is_delim,
714  __extract_delim,__append_null,__is_getline);
715 }
static bool _STLP_CALL _S_eof(int_type __c)
Definition: _ios.h:110
return __n
Definition: _algo.h:75
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
void _M_handle_exception(ios_base::iostate __flag)
Definition: _ios.c:114
char_type * _M_egptr() const
Definition: _streambuf.h:104
char_type * _M_gptr() const
Definition: _streambuf.h:103
#define _STLP_DEFAULT_CONSTRUCTED(_TTp)
Definition: _construct.h:265
#define _STLP_CATCH_ALL
Definition: features.h:818
_STLP_INLINE_LOOP _InputIter __last
Definition: _algo.h:68
void _M_gbump(int __n)
Definition: _streambuf.h:105
_STLP_STATIC_ASSERT(sizeof(nl_catd_type)<=sizeof(int)) class _STLP_CLASS_DECLSPEC _Catalog_nl_catd_map
_STLP_MOVE_TO_PRIV_NAMESPACE streamsize _STLP_CALL __read_unbuffered(basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__buf, streamsize _Num, _CharT *__s, _Is_Delim __is_delim, bool __extract_delim, bool __append_null, bool __is_getline)
Definition: _istream.c:579
int iostate
Definition: _ios_base.h:58
void setstate(iostate __state)
Definition: _ios.h:95
#define _STLP_TRY
Definition: features.h:817
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
#define min(a, b)
Definition: monoChain.cc:55
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
ptrdiff_t streamsize
Definition: char_traits.h:81
int_type sgetc()
Definition: _streambuf.h:233

Referenced by basic_istream< char, char_traits< char > >::_M_formatted_get(), basic_istream< char, char_traits< char > >::get(), basic_istream< char, char_traits< char > >::getline(), basic_istream< char, char_traits< char > >::read(), and basic_istream< char, char_traits< char > >::readsome().

◆ __read_unbuffered()

template<class _CharT , class _Traits , class _Is_Delim >
_STLP_MOVE_TO_PRIV_NAMESPACE streamsize _STLP_CALL __read_unbuffered ( basic_istream< _CharT, _Traits > *  __that,
basic_streambuf< _CharT, _Traits > *  __buf,
streamsize  _Num,
_CharT *  __s,
_Is_Delim  __is_delim,
bool  __extract_delim,
bool  __append_null,
bool  __is_getline 
)

Definition at line 579 of file _istream.c.

584 {
585  streamsize __n = 0;
586  ios_base::iostate __status = 0;
587 
588  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
589  // The operations that can potentially throw are sbumpc, snextc, and sgetc.
590  _STLP_TRY {
591  for (;;) {
592  if (__n == _Num) {
593  if (__is_getline) // didn't find delimiter as one of the _Num chars
594  __status |= ios_base::failbit;
595  break;
596  }
597  int_type __c = __buf->sbumpc(); // sschwarz
598 
599  if (__that->_S_eof(__c)) {
600  if (__n < _Num || __is_getline)
601  __status |= ios_base::eofbit;
602  break;
603  } else if (__is_delim(_Traits::to_char_type(__c))) {
604  if (__extract_delim) { // Extract and discard current character.
605  ++__n;
606  } else if ( !__pushback(__buf, _Traits::to_char_type(__c)) ) { // leave delimiter
607  __status |= ios_base::failbit;
608  }
609  break;
610  }
611  // regular character
612  *__s++ = _Traits::to_char_type(__c);
613  ++__n;
614  }
615  }
617  __that->_M_handle_exception(ios_base::badbit);
618  *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
619  return __n;
620  }
621 
622  if (__append_null)
623  *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
624  if (__status)
625  __that->setstate(__status); // This might throw.
626  return __n;
627 }
static bool _STLP_CALL _S_eof(int_type __c)
Definition: _ios.h:110
return __n
Definition: _algo.h:75
void _M_handle_exception(ios_base::iostate __flag)
Definition: _ios.c:114
#define __c
Definition: schilyio.h:209
#define _STLP_DEFAULT_CONSTRUCTED(_TTp)
Definition: _construct.h:265
int_type sbumpc()
Definition: _streambuf.h:227
#define _STLP_CATCH_ALL
Definition: features.h:818
bool _STLP_CALL __pushback(basic_streambuf< _CharT, _Traits > *__buf, _CharT __c)
Definition: _istream.c:168
int iostate
Definition: _ios_base.h:58
void setstate(iostate __state)
Definition: _ios.h:95
#define _STLP_TRY
Definition: features.h:817
ptrdiff_t streamsize
Definition: char_traits.h:81
_Traits::int_type int_type
Definition: _istream.h:75

Referenced by __read_buffered(), basic_istream< char, char_traits< char > >::_M_formatted_get(), basic_istream< char, char_traits< char > >::get(), basic_istream< char, char_traits< char > >::getline(), basic_istream< char, char_traits< char > >::read(), and basic_istream< char, char_traits< char > >::readsome().

◆ _M_ignore_buffered() [1/2]

template<class _CharT , class _Traits , class _Is_Delim , class _Scan_Delim >
void _STLP_CALL _M_ignore_buffered ( basic_istream< _CharT, _Traits > *  __that,
basic_streambuf< _CharT, _Traits > *  __buf,
_Is_Delim  __is_delim,
_Scan_Delim  __scan_delim,
bool  __extract_delim,
bool  __set_failbit 
)

Definition at line 928 of file _istream.c.

931  {
932  bool __at_eof = false;
933  bool __found_delim = false;
934 
935  _STLP_TRY {
936  while (__buf->_M_egptr() != __buf->_M_gptr() && !__at_eof && !__found_delim) {
937  const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
938  __buf->_M_gbump((int)(__p - __buf->_M_gptr()));
939 
940  if (__p != __buf->_M_egptr()) { // We found delim, so we're done.
941  if (__extract_delim)
942  __buf->_M_gbump(1);
943  __found_delim = true;
944  }
945 
946  else // No delim. Try to refil the buffer.
947  __at_eof = __that->_S_eof(__buf->sgetc());
948  } // Close the while loop.
949  }
951  __that->_M_handle_exception(ios_base::badbit);
952  return;
953  }
954 
955  if (__at_eof) {
956  __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
957  : ios_base::eofbit);
958  return;
959  }
960  if (__found_delim)
961  return;
962 
963  // If execution has reached this point, then we have an empty buffer but
964  // we have not reached eof. What that means is that the streambuf has
965  // decided to switch from a buffered to an unbuffered mode. We switch
966  // to _M_ignore_unbuffered.
967  _M_ignore_unbuffered(__that, __buf, __is_delim, __extract_delim, __set_failbit);
968 }
static bool _STLP_CALL _S_eof(int_type __c)
Definition: _ios.h:110
void _M_handle_exception(ios_base::iostate __flag)
Definition: _ios.c:114
char_type * _M_egptr() const
Definition: _streambuf.h:104
char_type * _M_gptr() const
Definition: _streambuf.h:103
#define _STLP_CATCH_ALL
Definition: features.h:818
void _M_gbump(int __n)
Definition: _streambuf.h:105
void _STLP_CALL _M_ignore_unbuffered(basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__buf, _Is_Delim __is_delim, bool __extract_delim, bool __set_failbit)
Definition: _istream.c:888
void setstate(iostate __state)
Definition: _ios.h:95
#define _STLP_TRY
Definition: features.h:817
int_type sgetc()
Definition: _streambuf.h:233

Referenced by basic_istream< char, char_traits< char > >::_M_skip_whitespace(), and basic_istream< char, char_traits< char > >::ignore().

◆ _M_ignore_buffered() [2/2]

template<class _CharT , class _Traits , class _Max_Chars , class _Is_Delim , class _Scan_Delim >
streamsize _STLP_CALL _M_ignore_buffered ( basic_istream< _CharT, _Traits > *  __that,
basic_streambuf< _CharT, _Traits > *  __buf,
streamsize  _Num,
_Max_Chars  __max_chars,
_Is_Delim  __is_delim,
_Scan_Delim  __scan_delim,
bool  __extract_delim,
bool  __set_failbit 
)

Definition at line 1025 of file _istream.c.

1030  {
1031  streamsize __n = 0;
1032  bool __at_eof = false;
1033  bool __done = false;
1034 
1035  _STLP_TRY {
1036  while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
1037  ptrdiff_t __avail = __buf->_M_egptr() - __buf->_M_gptr();
1038  streamsize __m = __max_chars(_Num, __n);
1039 
1040  if (__avail >= __m) { // We have more characters than we need.
1041  const _CharT* __last = __buf->_M_gptr() + __STATIC_CAST(ptrdiff_t, __m);
1042  const _CharT* __p = __scan_delim(__buf->_M_gptr(), __last);
1043  ptrdiff_t __chunk = __p - __buf->_M_gptr();
1044  __n += __chunk;
1045  __buf->_M_gbump((int)__chunk);
1046 
1047  if (__extract_delim && __p != __last) {
1048  __n += 1;
1049  __buf->_M_gbump(1);
1050  }
1051 
1052  __done = true;
1053  }
1054 
1055  else {
1056  const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
1057  ptrdiff_t __chunk = __p - __buf->_M_gptr();
1058  __n += __chunk;
1059  __buf->_M_gbump((int)__chunk);
1060 
1061  if (__p != __buf->_M_egptr()) { // We found delim.
1062  if (__extract_delim) {
1063  __n += 1;
1064  __buf->_M_gbump(1);
1065  }
1066 
1067  __done = true;
1068  }
1069 
1070  // We didn't find delim. Try to refill the buffer.
1071  else if (__that->_S_eof(__buf->sgetc())) {
1072  __done = true;
1073  __at_eof = true;
1074  }
1075  }
1076  } // Close the while loop.
1077  }
1078  _STLP_CATCH_ALL {
1079  __that->_M_handle_exception(ios_base::badbit);
1080  return __n;
1081  }
1082 
1083  if (__at_eof)
1084  __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
1085  : ios_base::eofbit);
1086 
1087  if (__done)
1088  return __n;
1089 
1090  // If execution has reached this point, then we have an empty buffer but
1091  // we have not reached eof. What that means is that the streambuf has
1092  // decided to switch from buffered to unbuffered input. We switch to
1093  // to _M_ignore_unbuffered.
1094 
1095  return __n + _M_ignore_unbuffered(__that, __buf, _Num, __max_chars,
1096  __is_delim, __extract_delim, __set_failbit);
1097 }
static bool _STLP_CALL _S_eof(int_type __c)
Definition: _ios.h:110
return __n
Definition: _algo.h:75
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
void _M_handle_exception(ios_base::iostate __flag)
Definition: _ios.c:114
char_type * _M_egptr() const
Definition: _streambuf.h:104
char_type * _M_gptr() const
Definition: _streambuf.h:103
#define _STLP_CATCH_ALL
Definition: features.h:818
_STLP_INLINE_LOOP _InputIter __last
Definition: _algo.h:68
void _M_gbump(int __n)
Definition: _streambuf.h:105
void _STLP_CALL _M_ignore_unbuffered(basic_istream< _CharT, _Traits > *__that, basic_streambuf< _CharT, _Traits > *__buf, _Is_Delim __is_delim, bool __extract_delim, bool __set_failbit)
Definition: _istream.c:888
void setstate(iostate __state)
Definition: _ios.h:95
#define _STLP_TRY
Definition: features.h:817
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
ptrdiff_t streamsize
Definition: char_traits.h:81
int_type sgetc()
Definition: _streambuf.h:233

◆ _M_ignore_unbuffered() [1/2]

template<class _CharT , class _Traits , class _Is_Delim >
void _STLP_CALL _M_ignore_unbuffered ( basic_istream< _CharT, _Traits > *  __that,
basic_streambuf< _CharT, _Traits > *  __buf,
_Is_Delim  __is_delim,
bool  __extract_delim,
bool  __set_failbit 
)

Definition at line 888 of file _istream.c.

891  {
892  bool __done = false;
893  ios_base::iostate __status = 0;
894  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
895 
896  _STLP_TRY {
897  while (!__done) {
898  int_type __c = __buf->sbumpc();
899 
900  if (__that->_S_eof(__c)) {
901  __done = true;
902  __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
903  : ios_base::eofbit;
904  }
905 
906  else if (__is_delim(_Traits::to_char_type(__c))) {
907  __done = true;
908  if (!__extract_delim)
909  if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
910  __status |= ios_base::failbit;
911  }
912  }
913  }
915  __that->_M_handle_exception(ios_base::badbit);
916  }
917 
918  __that->setstate(__status);
919 }
static bool _STLP_CALL _S_eof(int_type __c)
Definition: _ios.h:110
void _M_handle_exception(ios_base::iostate __flag)
Definition: _ios.c:114
#define __c
Definition: schilyio.h:209
int_type sbumpc()
Definition: _streambuf.h:227
#define _STLP_CATCH_ALL
Definition: features.h:818
int iostate
Definition: _ios_base.h:58
void setstate(iostate __state)
Definition: _ios.h:95
#define _STLP_TRY
Definition: features.h:817
int_type sputbackc(char_type __c)
Definition: _streambuf.h:241
_Traits::int_type int_type
Definition: _istream.h:75

Referenced by _M_ignore_buffered(), basic_istream< char, char_traits< char > >::_M_skip_whitespace(), and basic_istream< char, char_traits< char > >::ignore().

◆ _M_ignore_unbuffered() [2/2]

template<class _CharT , class _Traits , class _Max_Chars , class _Is_Delim >
streamsize _STLP_CALL _M_ignore_unbuffered ( basic_istream< _CharT, _Traits > *  __that,
basic_streambuf< _CharT, _Traits > *  __buf,
streamsize  _Num,
_Max_Chars  __max_chars,
_Is_Delim  __is_delim,
bool  __extract_delim,
bool  __set_failbit 
)

Definition at line 983 of file _istream.c.

987  {
988  streamsize __n = 0;
989  ios_base::iostate __status = 0;
990  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
991 
992  _STLP_TRY {
993  while (__max_chars(_Num, __n) > 0) {
994  int_type __c = __buf->sbumpc();
995 
996  if (__that->_S_eof(__c)) {
997  __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
998  : ios_base::eofbit;
999  break;
1000  }
1001 
1002  else if (__is_delim(_Traits::to_char_type(__c))) {
1003  if (__extract_delim)
1004  ++__n;
1005  else if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
1006  __status |= ios_base::failbit;
1007 
1008  break;
1009  }
1010  // fbp : added counter increment to pass Dietmar's test
1011  ++__n;
1012  }
1013  }
1014  _STLP_CATCH_ALL {
1015  __that->_M_handle_exception(ios_base::badbit);
1016  }
1017 
1018  if (__status)
1019  __that->setstate(__status); // This might throw.
1020  return __n;
1021 }
static bool _STLP_CALL _S_eof(int_type __c)
Definition: _ios.h:110
return __n
Definition: _algo.h:75
void _M_handle_exception(ios_base::iostate __flag)
Definition: _ios.c:114
#define __c
Definition: schilyio.h:209
int_type sbumpc()
Definition: _streambuf.h:227
#define _STLP_CATCH_ALL
Definition: features.h:818
int iostate
Definition: _ios_base.h:58
void setstate(iostate __state)
Definition: _ios.h:95
#define _STLP_TRY
Definition: features.h:817
int_type sputbackc(char_type __c)
Definition: _streambuf.h:241
ptrdiff_t streamsize
Definition: char_traits.h:81
_Traits::int_type int_type
Definition: _istream.h:75