sbuf_iter.h (istreambuf_iterator): Correct.

2001-05-01  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/sbuf_iter.h (istreambuf_iterator): Correct.
	* testsuite/24_iterators/istreambuf_iterator.cc (test02): Add test.

	* include/bits/std_sstream.h (stringbuf): Leak
	copied string.
	* testsuite/24_iterators/ostreambuf_iterator.cc: Correct.

From-SVN: r41755
This commit is contained in:
Benjamin Kosnik 2001-05-02 05:50:20 +00:00 committed by Benjamin Kosnik
parent 0a5fee3256
commit a85afd69a3
5 changed files with 78 additions and 26 deletions

View File

@ -1,3 +1,12 @@
2001-05-01 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/sbuf_iter.h (istreambuf_iterator): Correct.
* testsuite/24_iterators/istreambuf_iterator.cc (test02): Add test.
* include/bits/std_sstream.h (stringbuf): Leak
copied string.
* testsuite/24_iterators/ostreambuf_iterator.cc: Correct.
2001-05-01 Tom Browder <tbrowder@home.com>
* docs/html/ext/howto.html: Fix typo.

View File

@ -141,18 +141,15 @@ namespace std
return *this;
}
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 14882 says return a proxy object. It should be a const
// proxy object, but since this class is not mandated, it
// should allow this signature:
const __istreambufiter_type
__istreambufiter_type
operator++(int)
{
__istreambufiter_type __old = *this;
if (_M_sbuf)
_M_c = _M_sbuf->sbumpc();
return *this;
__old._M_c = _M_sbuf->sbumpc();
_M_c = -2;
return __old;
}
#endif
bool
equal(const __istreambufiter_type& __b)
@ -205,3 +202,6 @@ namespace std
} // namespace std
#endif

View File

@ -71,16 +71,14 @@ namespace std
explicit
basic_stringbuf(const __string_type& __str,
ios_base::openmode __mode = ios_base::in | ios_base::out)
: __streambuf_type(), _M_string(__str)
: __streambuf_type(), _M_string(__str.c_str())
{ _M_stringbuf_init(__mode); }
// Get and set:
__string_type
str() const
{
if (_M_mode & ios_base::in && !(_M_mode & ios_base::out))
return _M_string;
else
if (_M_mode & ios_base::out)
{
// This is the deal: _M_string.size() is value that
// represents the size of the intial string that makes
@ -91,6 +89,8 @@ namespace std
__len = max(__size_type(_M_out_end - _M_out_beg), __len);
return __string_type(_M_out_beg, _M_out_beg + __len);
}
else
return _M_string;
}
void
@ -121,7 +121,7 @@ namespace std
if (_M_mode & ios_base::ate)
_M_really_sync(0, _M_buf_size);
else
_M_really_sync(0, 0);
_M_really_sync(0, 0);
}
// Overridden virtual functions:

View File

@ -1,6 +1,6 @@
// 1999-06-28 bkoz
// Copyright (C) 1999 Free Software Foundation, Inc.
// Copyright (C) 1999, 2001 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
@ -102,7 +102,7 @@ bool test01(void)
std::istringstream istrs02(str01);
cistreambuf_iter istrb_it28(istrs02);
for (int i = 0; i < sizeof(slit01) - 3;)
for (int i = 0; i < sizeof(slit01) - 2;)
{
c = *++istrb_it28;
VERIFY( c == slit01[++i] );
@ -115,9 +115,46 @@ bool test01(void)
return test;
}
// libstdc++/2627
void test02()
{
bool test = true;
const std::string s("free the vieques");
// 1
std::string res_postfix;
std::istringstream iss01(s);
std::istreambuf_iterator<char> isbufit01(iss01);
for (int j = 0; j < s.size(); ++j, isbufit01++)
res_postfix += *isbufit01;
// 2
std::string res_prefix;
std::istringstream iss02(s);
std::istreambuf_iterator<char> isbufit02(iss02);
for (int j = 0; j < s.size(); ++j, ++isbufit02)
res_prefix += *isbufit02;
// 3 mixed
std::string res_mixed;
std::istringstream iss03(s);
std::istreambuf_iterator<char> isbufit03(iss03);
for (int j = 0; j < int(s.size() / 2); ++j)
{
res_mixed += *isbufit03;
++isbufit03;
res_mixed += *isbufit03;
isbufit03++;
}
VERIFY ( res_postfix == res_prefix );
VERIFY ( res_mixed == res_prefix );
}
int main()
{
test01();
test02();
return 0;
}

View File

@ -30,7 +30,9 @@ bool test01(void)
typedef costreambuf_iter::streambuf_type cstreambuf_type;
bool test = true;
const char slit01[] = "playa hermosa, liberia, guanacaste";
const char slit02[] = "bodega bay, lost coast, california";
std::string str01(slit01);
std::string str02(slit02);
std::string tmp;
std::stringbuf strbuf01;
std::stringbuf strbuf02(str01);
@ -61,21 +63,25 @@ bool test01(void)
// charT operator*() const
// ostreambuf_iterator& operator++();
// ostreambuf_iterator& operator++(int);
costreambuf_iter ostrb_it27(ostrs00);
costreambuf_iter ostrb_it27(ostrs01);
VERIFY( !ostrb_it27.failed() );
for (int i = 0; i < strlen(slit01) - 2; ++i)
ostrb_it27 = 'a';
int j = str02.size();
for (int i = 0; i < j; ++i)
ostrb_it27 = str02[i];
VERIFY( !ostrb_it27.failed() );
tmp = ostrs00.str();
VERIFY ( tmp == str01 );
costreambuf_iter ostrb_it28(ostrs01);
VERIFY( !ostrb_it28.failed() );
for (int i = 0; i < strlen(slit01) + 1; ++i)
ostrb_it28 = 'b';
VERIFY( !ostrb_it28.failed() );
tmp = ostrs01.str();
VERIFY ( tmp != str01 );
VERIFY ( tmp == str02 );
costreambuf_iter ostrb_it28(ostrs00);
VERIFY( !ostrb_it28.failed() );
j = ostrs00.str().size();
for (int i = 0; i < j + 2; ++i)
ostrb_it28 = 'b';
VERIFY( !ostrb_it28.failed() );
tmp = ostrs00.str();
VERIFY ( tmp != str01 );
VERIFY ( tmp != str02 );
#ifdef DEBUG_ASSERT
assert(test);