7 #include "packager/media/formats/webvtt/text_readers.h" 9 #include "packager/base/logging.h" 10 #include "packager/file/file.h" 16 std::unique_ptr<FileReader>* out) {
17 const char* kReadOnly =
"r";
19 std::unique_ptr<File, FileCloser> file(
23 return Status(error::INVALID_ARGUMENT,
24 "Could not open input file " + filename);
27 *out = std::unique_ptr<FileReader>(
new FileReader(std::move(file)));
35 return file_->Read(out, 1) == 1;
38 FileReader::FileReader(std::unique_ptr<File, FileCloser> file)
39 : file_(std::move(file)) {
43 PeekingReader::PeekingReader(std::unique_ptr<FileReader> source)
44 : source_(std::move(source)) {}
46 bool PeekingReader::Next(
char* out) {
49 has_cached_next_ =
false;
55 bool PeekingReader::Peek(
char* out) {
57 if (!has_cached_next_ && source_->Next(&cached_next_)) {
58 has_cached_next_ =
true;
60 if (has_cached_next_) {
67 LineReader::LineReader(std::unique_ptr<FileReader> source)
68 : source_(std::move(source)) {}
71 bool LineReader::Next(std::string* out) {
74 bool read_something =
false;
76 while (source_.Next(&now)) {
77 read_something =
true;
85 if (source_.Peek(&next) && next ==
'\n') {
92 return read_something;
95 BlockReader::BlockReader(std::unique_ptr<FileReader> source)
96 : source_(std::move(source)) {}
98 bool BlockReader::Next(std::vector<std::string>* out) {
103 bool in_block =
false;
109 while (source_.Next(&line)) {
110 if (in_block && line.empty()) {
113 if (in_block || !line.empty()) {
114 out->push_back(line);
All the methods that are virtual are virtual for mocking.
virtual bool Open()=0
Internal open. Should not be used directly.