Skip to content
Snippets Groups Projects
Commit ea6795af authored by hcasse's avatar hcasse
Browse files

io: various bug fixes.

parent b19cc7d1
Branches
No related tags found
No related merge requests found
......@@ -136,10 +136,12 @@ int BlockInStream::read(void *buffer, int size) {
/**
*/
int BlockInStream::read(void) {
int res;
if(off >= _size)
return ENDED;
res = ENDED;
else
return (unsigned char)_block[off++];
res = static_cast<t::uint8>(_block[off++]);
return res;
}
} } // elm::io
......
......@@ -99,10 +99,10 @@ int BufferedInStream::read(void) {
if(pos >= top) {
int nsize = refill();
if(nsize <= 0)
return nsize;
return ENDED;
}
pos++;
return buf[pos - 1];
return static_cast<t::uint8>(buf[pos - 1]);
}
......
......@@ -20,6 +20,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <elm/types.h>
#include <elm/io/InStream.h>
#if defined(__LINUX)
#include <elm/io/UnixInStream.h>
......@@ -62,7 +63,7 @@ int InStream::read(void) {
char buf;
int size = read(&buf, 1);
if(size == 1)
return (unsigned char)buf;
return static_cast<t::uint8>(buf);
else if(size == 0)
return ENDED;
else
......
......@@ -526,11 +526,15 @@ String Input::scanLine(void) {
StringBuffer buf;
int chr = get();
while(chr >= 0) {
buf << (char)chr;
buf << static_cast<char>(chr);
if(chr == '\n')
break;
chr = get();
}
if(chr == InStream::FAILED) {
state |= IO_ERROR;
return "";
}
return buf.toString();
}
......
......@@ -134,7 +134,14 @@ TEST_BEGIN(io)
CHECK_EQUAL(io::scan("false").scanBool(), false);
CHECK_EQUAL(io::scan("1").scanBool(), true);
CHECK_EQUAL(io::scan("0").scanBool(), false);
}
{
auto x = io::scan("1\n2\n3");
CHECK_EQUAL(x.scanLine(), string("1\n"));
CHECK_EQUAL(x.scanLine(), string("2\n"));
CHECK_EQUAL(x.scanLine(), string("3"));
CHECK_EQUAL(x.scanLine(), string(""));
}
TEST_END
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment