sentry __cerb(*this, true);
if (__cerb)
{
- if (__n > 0)
+ try
{
- try
- {
- const int_type __eof = traits_type::eof();
- __streambuf_type* __sb = this->rdbuf();
- int_type __c = __sb->sbumpc();
- bool __testeof = __c == __eof;
-
- while (_M_gcount < __n - 1 && !__testeof)
- {
- *__s++ = traits_type::to_char_type(__c);
- ++_M_gcount;
- __c = __sb->sbumpc();
- __testeof = __c == __eof;
- }
- if (__testeof)
- this->setstate(ios_base::eofbit | ios_base::failbit);
- else
- {
- // _M_gcount == __n - 1
- *__s++ = traits_type::to_char_type(__c);
- ++_M_gcount;
- }
- }
- catch(exception& __fail)
+ const int_type __eof = traits_type::eof();
+ __streambuf_type* __sb = this->rdbuf();
+ int_type __c = __sb->sgetc();
+
+ while (_M_gcount < __n && __c != __eof)
{
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
+ *__s++ = traits_type::to_char_type(__c);
+ ++_M_gcount;
+ __c = __sb->snextc();
}
+ if (__c == __eof)
+ this->setstate(ios_base::eofbit | ios_base::failbit);
+ }
+ catch(exception& __fail)
+ {
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ __throw_exception_again;
}
}
else
basic_istream<_CharT, _Traits>::
readsome(char_type* __s, streamsize __n)
{
- const int_type __eof = traits_type::eof();
_M_gcount = 0;
sentry __cerb(*this, true);
if (__cerb)
{
- if (__n > 0)
+ try
{
- try
- {
- streamsize __num = this->rdbuf()->in_avail();
- if (__num != static_cast<streamsize>(__eof))
- {
- __num = min(__num, __n);
- _M_gcount = this->rdbuf()->sgetn(__s, __num);
- }
- else
- this->setstate(ios_base::eofbit);
- }
- catch(exception& __fail)
+ const int_type __eof = traits_type::eof();
+ streamsize __num = this->rdbuf()->in_avail();
+ if (__num != static_cast<streamsize>(__eof))
{
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
+ __num = min(__num, __n);
+ if (__num)
+ _M_gcount = this->rdbuf()->sgetn(__s, __num);
}
+ else
+ this->setstate(ios_base::eofbit);
+ }
+ catch(exception& __fail)
+ {
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ __throw_exception_again;
}
}
else
// 1999-07-01 bkoz
-// Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
std::istringstream istrs01(str01);
istrs01 >> str10;
VERIFY( str10 == str02 );
- try {
- std::istringstream::int_type i01 = istrs01.peek(); //a-boo
- VERIFY( std::istringstream::traits_type::to_char_type(i01) == ' ' );
- }
- catch(std::exception& fail) {
- VERIFY( false ); // shouldn't throw
- }
+ try
+ {
+ std::istringstream::int_type i01 = istrs01.peek(); //a-boo
+ VERIFY( std::istringstream::traits_type::to_char_type(i01) == ' ' );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false ); // shouldn't throw
+ }
+ istrs01.clear();
istrs01 >> str10;
VERIFY( str10 == str03 );
+ istrs01.clear();
istrs01 >> str10;
VERIFY( str10 == str04 ); // sentry picks out the white spaces. .
// istream& getline(istream&, string&, char)
// istream& getline(istream&, string&)
- try {
- getline(istrs01, str10);
- VERIFY( !istrs01.fail() );
- VERIFY( !istrs01.eof() );
- VERIFY( istrs01.good() );
- VERIFY( str10 == " bay" );
- }
- catch(std::exception& fail) {
- VERIFY( false ); // shouldn't throw
- }
-
- try {
- istrs01.clear();
- getline(istrs01, str10,'\t');
- VERIFY( !istrs01.fail() );
- VERIFY( !istrs01.eof() );
- VERIFY( istrs01.good() );
- VERIFY( str10 == str05 );
- }
- catch(std::exception& fail) {
- VERIFY( false ); // shouldn't throw
- }
-
- try {
- istrs01.clear();
- getline(istrs01, str10,'\t');
- VERIFY( !istrs01.fail() );
- VERIFY( !istrs01.eof() );
- VERIFY( istrs01.good() );
- VERIFY( str10 == str05 );
- }
- catch(std::exception& fail) {
- VERIFY( false ); // shouldn't throw
- }
-
- try {
- istrs01.clear();
- getline(istrs01, str10, '.');
- VERIFY( !istrs01.fail() );
- VERIFY( istrs01.eof() );
- VERIFY( !istrs01.good() );
- VERIFY( str10 == "\t from Elk Rapids to the point reminds me of miles" );
- }
- catch(std::exception& fail) {
- VERIFY( false ); // shouldn't throw
- }
-
- try {
- getline(istrs02, str10);
- VERIFY( istrs02.fail() );
- VERIFY( istrs02.eof() );
- VERIFY( str10 =="\t from Elk Rapids to the point reminds me of miles" );
- }
- catch(std::exception& fail) {
- VERIFY( false ); // shouldn't throw
- }
+ try
+ {
+ istrs01.clear();
+ getline(istrs01, str10);
+ VERIFY( !istrs01.fail() );
+ VERIFY( !istrs01.eof() );
+ VERIFY( istrs01.good() );
+ VERIFY( str10 == " bay" );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false ); // shouldn't throw
+ }
+
+ try
+ {
+ istrs01.clear();
+ getline(istrs01, str10,'\t');
+ VERIFY( !istrs01.fail() );
+ VERIFY( !istrs01.eof() );
+ VERIFY( istrs01.good() );
+ VERIFY( str10 == str05 );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false ); // shouldn't throw
+ }
+
+ try
+ {
+ istrs01.clear();
+ getline(istrs01, str10,'\t');
+ VERIFY( !istrs01.fail() );
+ VERIFY( !istrs01.eof() );
+ VERIFY( istrs01.good() );
+ VERIFY( str10 == str05 );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false ); // shouldn't throw
+ }
+
+ try
+ {
+ istrs01.clear();
+ getline(istrs01, str10, '.');
+ VERIFY( !istrs01.fail() );
+ VERIFY( istrs01.eof() );
+ VERIFY( !istrs01.good() );
+ VERIFY( str10 == "\t from Elk Rapids to the point reminds me of miles" );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false ); // shouldn't throw
+ }
+ try
+ {
+ getline(istrs02, str10);
+ VERIFY( istrs02.fail() );
+ VERIFY( istrs02.eof() );
+ VERIFY( str10 =="\t from Elk Rapids to the point reminds me of miles" );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false ); // shouldn't throw
+ }
+
// ostream& operator<<(ostream&, const basic_string&)
std::ostringstream ostrs01;
- try {
- ostrs01 << str01;
- VERIFY( ostrs01.str() == str01 );
- }
- catch(std::exception& fail) {
- VERIFY( false );
- }
-
+ try
+ {
+ ostrs01 << str01;
+ VERIFY( ostrs01.str() == str01 );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false );
+ }
+
std::string hello_world;
std::cout << hello_world;