This source file includes following definitions.
- ptr_end_
- GetByte
- UngetByte
- ParseLine
#include "media/formats/webm/webm_webvtt_parser.h"
namespace media {
void WebMWebVTTParser::Parse(const uint8* payload, int payload_size,
std::string* id,
std::string* settings,
std::string* content) {
WebMWebVTTParser parser(payload, payload_size);
parser.Parse(id, settings, content);
}
WebMWebVTTParser::WebMWebVTTParser(const uint8* payload, int payload_size)
: ptr_(payload),
ptr_end_(payload + payload_size) {
}
void WebMWebVTTParser::Parse(std::string* id,
std::string* settings,
std::string* content) {
ParseLine(id);
ParseLine(settings);
content->assign(ptr_, ptr_end_);
}
bool WebMWebVTTParser::GetByte(uint8* byte) {
if (ptr_ >= ptr_end_)
return false;
*byte = *ptr_++;
return true;
}
void WebMWebVTTParser::UngetByte() {
--ptr_;
}
void WebMWebVTTParser::ParseLine(std::string* line) {
line->clear();
enum {
kLF = '\x0A',
kCR = '\x0D'
};
for (;;) {
uint8 byte;
if (!GetByte(&byte) || byte == kLF)
return;
if (byte == kCR) {
if (GetByte(&byte) && byte != kLF)
UngetByte();
return;
}
line->push_back(byte);
}
}
}