7 #include <packager/media/formats/webvtt/text_readers.h>
11 #include <absl/log/check.h>
12 #include <absl/log/log.h>
17 LineReader::LineReader() : should_flush_(false) {}
19 void LineReader::PushData(
const uint8_t* data,
size_t data_size) {
20 buffer_.Push(data,
static_cast<int>(data_size));
21 should_flush_ =
false;
25 bool LineReader::Next(std::string* out) {
32 buffer_.Peek(&data, &data_size);
33 for (i = 0; i < data_size; i++) {
35 if (data[i] ==
'\n') {
41 if (data[i] ==
'\r') {
44 if (i + 1 == data_size) {
49 if (data[i + 1] ==
'\n')
58 if (i == data_size && (!should_flush_ || i == 0)) {
63 out->assign(data, data + i);
64 buffer_.Pop(i + skip);
68 void LineReader::Flush() {
72 BlockReader::BlockReader() : should_flush_(false) {}
76 should_flush_ =
false;
82 bool end_block =
false;
87 while (source_.
Next(&line)) {
88 if (!temp_.empty() && line.empty()) {
93 temp_.emplace_back(std::move(line));
97 if (!end_block && (!should_flush_ || temp_.empty()))
100 *out = std::move(temp_);
106 should_flush_ =
true;
All the methods that are virtual are virtual for mocking.