diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/stream.cpp | 15 | ||||
| -rw-r--r-- | src/stream.h | 8 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/stream.cpp b/src/stream.cpp index 290afb3..01edb38 100644 --- a/src/stream.cpp +++ b/src/stream.cpp | |||
| @@ -15,6 +15,21 @@ Bu::Stream::~Stream() | |||
| 15 | { | 15 | { |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | Bu::FString Bu::Stream::readLine() | ||
| 19 | { | ||
| 20 | Bu::FString sRet; | ||
| 21 | |||
| 22 | for(;;) | ||
| 23 | { | ||
| 24 | char s; | ||
| 25 | if( read( &s, 1 ) == 0 ) | ||
| 26 | return sRet; | ||
| 27 | if( s == '\n' || s == '\r' ) | ||
| 28 | return sRet; | ||
| 29 | sRet.append( s ); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 18 | size_t Bu::Stream::write( const Bu::FString &sBuf ) | 33 | size_t Bu::Stream::write( const Bu::FString &sBuf ) |
| 19 | { | 34 | { |
| 20 | return write( sBuf.getStr(), sBuf.getSize() ); | 35 | return write( sBuf.getStr(), sBuf.getSize() ); |
diff --git a/src/stream.h b/src/stream.h index f0f1af3..527dc20 100644 --- a/src/stream.h +++ b/src/stream.h | |||
| @@ -46,6 +46,14 @@ namespace Bu | |||
| 46 | virtual size_t read( void *pBuf, size_t nBytes ) = 0; | 46 | virtual size_t read( void *pBuf, size_t nBytes ) = 0; |
| 47 | 47 | ||
| 48 | /** | 48 | /** |
| 49 | * Attempts to read a complete line from the stream. This will stop | ||
| 50 | * reading when it has reached the end of the stream, or runs out of | ||
| 51 | * data in a non-blocking stream. | ||
| 52 | *@returns The line read, not including newline character. | ||
| 53 | */ | ||
| 54 | virtual Bu::FString readLine(); | ||
| 55 | |||
| 56 | /** | ||
| 49 | * Write data to the stream. | 57 | * Write data to the stream. |
| 50 | *@param pBuf (const void *) The data to be written. | 58 | *@param pBuf (const void *) The data to be written. |
| 51 | *@param nBytes (size_t) Amount of data to write from pBuf. | 59 | *@param nBytes (size_t) Amount of data to write from pBuf. |
