mirror of
https://github.com/NoelFB/blah.git
synced 2025-06-29 19:25:26 +08:00
stream.h cleanup & commenting
This commit is contained in:
@ -26,4 +26,45 @@ int64_t Stream::pipe(Stream& stream, int64_t length)
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// reads a string. if length < 0, assumes null-terminated
|
||||
String Stream::read_string(int length)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (length < 0)
|
||||
{
|
||||
char next;
|
||||
while (read(&next, 1) && next != '\0')
|
||||
result.append(next);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.set_length(length);
|
||||
read_into(result.cstr(), length);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
String Stream::read_line()
|
||||
{
|
||||
String result;
|
||||
|
||||
char next;
|
||||
while (read(&next, 1) && next != '\n' && next != '\0')
|
||||
result.append(next);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int64_t Stream::write(const void* buffer, int64_t length)
|
||||
{
|
||||
return write_from(buffer, length);
|
||||
}
|
||||
|
||||
int64_t Stream::write(const String& string)
|
||||
{
|
||||
return write_from(string.begin(), string.length());
|
||||
}
|
||||
|
Reference in New Issue
Block a user