| 78 | } |
| 79 | |
| 80 | StreamReadStatus Stream::ReadLine(String *line, StreamReadContext& context, bool may_wait) |
| 81 | { |
| 82 | if (context.Eof) |
| 83 | return StatusEof; |
| 84 | |
| 85 | if (context.MustRead) { |
| 86 | if (!context.FillFromStream(this, may_wait)) { |
| 87 | context.Eof = true; |
| 88 | |
| 89 | *line = String(context.Buffer, &(context.Buffer[context.Size])); |
| 90 | boost::algorithm::trim_right(*line); |
| 91 | |
| 92 | return StatusNewItem; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | for (size_t i = 0; i < context.Size; i++) { |
| 97 | if (context.Buffer[i] == '\n') { |
| 98 | *line = String(context.Buffer, context.Buffer + i); |
| 99 | boost::algorithm::trim_right(*line); |
| 100 | |
| 101 | context.DropData(i + 1u); |
| 102 | |
| 103 | context.MustRead = !context.Size; |
| 104 | return StatusNewItem; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | context.MustRead = true; |
| 109 | return StatusNeedData; |
| 110 | } |
| 111 | |
| 112 | bool StreamReadContext::FillFromStream(const Stream::Ptr& stream, bool may_wait) |
| 113 | { |
no test coverage detected