7 #include "packager/media/formats/webvtt/text_readers.h"
11 #include "packager/base/logging.h"
16 LineReader::LineReader() : should_flush_(false) {}
18 void LineReader::PushData(
const uint8_t* data,
size_t data_size) {
19 buffer_.Push(data,
static_cast<int>(data_size));
20 should_flush_ =
false;
24 bool LineReader::Next(std::string* out) {
31 buffer_.Peek(&data, &data_size);
32 for (i = 0; i < data_size; i++) {
34 if (data[i] ==
'\n') {
40 if (data[i] ==
'\r') {
43 if (i + 1 == data_size) {
48 if (data[i + 1] ==
'\n')
57 if (i == data_size && (!should_flush_ || i == 0)) {
62 out->assign(data, data + i);
63 buffer_.Pop(i + skip);
67 void LineReader::Flush() {
71 BlockReader::BlockReader() : should_flush_(false) {}
75 should_flush_ =
false;
81 bool end_block =
false;
86 while (source_.
Next(&line)) {
87 if (!temp_.empty() && line.empty()) {
92 temp_.emplace_back(std::move(line));
96 if (!end_block && (!should_flush_ || temp_.empty()))
99 *out = std::move(temp_);
105 should_flush_ =
true;
All the methods that are virtual are virtual for mocking.