clang-format on webvttparser.(cc|h)
Conformance of webvttparser.(cc|h) to Google C++ style guide. Change-Id: I19610c5795c0bd2446c07a6c2abde58c3286b2ea
This commit is contained in:
@@ -11,19 +11,19 @@
|
|||||||
|
|
||||||
namespace libwebvtt {
|
namespace libwebvtt {
|
||||||
|
|
||||||
|
// NOLINT'ing this enum because clang-format puts it in a single line which
|
||||||
|
// makes it look really unreadable.
|
||||||
enum {
|
enum {
|
||||||
kNUL = '\x00',
|
kNUL = '\x00',
|
||||||
kSPACE = ' ',
|
kSPACE = ' ',
|
||||||
kTAB = '\x09',
|
kTAB = '\x09',
|
||||||
kLF = '\x0A',
|
kLF = '\x0A',
|
||||||
kCR = '\x0D'
|
kCR = '\x0D'
|
||||||
};
|
}; // NOLINT
|
||||||
|
|
||||||
Reader::~Reader() {
|
Reader::~Reader() {}
|
||||||
}
|
|
||||||
|
|
||||||
LineReader::~LineReader() {
|
LineReader::~LineReader() {}
|
||||||
}
|
|
||||||
|
|
||||||
int LineReader::GetLine(std::string* line_ptr) {
|
int LineReader::GetLine(std::string* line_ptr) {
|
||||||
if (line_ptr == NULL)
|
if (line_ptr == NULL)
|
||||||
@@ -101,11 +101,9 @@ int LineReader::GetLine(std::string* line_ptr) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Parser::Parser(Reader* r) : reader_(r), unget_(-1) {
|
Parser::Parser(Reader* r) : reader_(r), unget_(-1) {}
|
||||||
}
|
|
||||||
|
|
||||||
Parser::~Parser() {
|
Parser::~Parser() {}
|
||||||
}
|
|
||||||
|
|
||||||
int Parser::Init() {
|
int Parser::Init() {
|
||||||
int e = ParseBOM();
|
int e = ParseBOM();
|
||||||
@@ -143,7 +141,7 @@ int Parser::Init() {
|
|||||||
if (e < 0) // error
|
if (e < 0) // error
|
||||||
return e;
|
return e;
|
||||||
|
|
||||||
if (e > 0) // EOF
|
if (e > 0) // EOF
|
||||||
return 0; // weird but valid
|
return 0; // weird but valid
|
||||||
|
|
||||||
if (!line.empty()) {
|
if (!line.empty()) {
|
||||||
@@ -164,7 +162,7 @@ int Parser::Init() {
|
|||||||
if (e < 0) // error
|
if (e < 0) // error
|
||||||
return e;
|
return e;
|
||||||
|
|
||||||
if (e > 0) // EOF
|
if (e > 0) // EOF
|
||||||
return 0; // weird but we allow it
|
return 0; // weird but we allow it
|
||||||
|
|
||||||
if (!line.empty())
|
if (!line.empty())
|
||||||
@@ -226,10 +224,7 @@ int Parser::Parse(Cue* cue) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
e = ParseTimingsLine(&line,
|
e = ParseTimingsLine(&line, arrow_pos, &cue->start_time, &cue->stop_time,
|
||||||
arrow_pos,
|
|
||||||
&cue->start_time,
|
|
||||||
&cue->stop_time,
|
|
||||||
&cue->settings);
|
&cue->settings);
|
||||||
|
|
||||||
if (e) // error
|
if (e) // error
|
||||||
@@ -269,9 +264,7 @@ int Parser::GetChar(char* c) {
|
|||||||
return reader_->GetChar(c);
|
return reader_->GetChar(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::UngetChar(char c) {
|
void Parser::UngetChar(char c) { unget_ = static_cast<unsigned char>(c); }
|
||||||
unget_ = static_cast<unsigned char>(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Parser::ParseBOM() {
|
int Parser::ParseBOM() {
|
||||||
// Explanation of UTF-8 BOM:
|
// Explanation of UTF-8 BOM:
|
||||||
@@ -303,12 +296,9 @@ int Parser::ParseBOM() {
|
|||||||
return 0; // success
|
return 0; // success
|
||||||
}
|
}
|
||||||
|
|
||||||
int Parser::ParseTimingsLine(
|
int Parser::ParseTimingsLine(std::string* line_ptr,
|
||||||
std::string* line_ptr,
|
std::string::size_type arrow_pos, Time* start_time,
|
||||||
std::string::size_type arrow_pos,
|
Time* stop_time, Cue::settings_t* settings) {
|
||||||
Time* start_time,
|
|
||||||
Time* stop_time,
|
|
||||||
Cue::settings_t* settings) {
|
|
||||||
if (line_ptr == NULL)
|
if (line_ptr == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -353,10 +343,8 @@ int Parser::ParseTimingsLine(
|
|||||||
return 0; // success
|
return 0; // success
|
||||||
}
|
}
|
||||||
|
|
||||||
int Parser::ParseTime(
|
int Parser::ParseTime(const std::string& line, std::string::size_type* idx_ptr,
|
||||||
const std::string& line,
|
Time* time) {
|
||||||
std::string::size_type* idx_ptr,
|
|
||||||
Time* time) {
|
|
||||||
if (idx_ptr == NULL)
|
if (idx_ptr == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -511,10 +499,8 @@ int Parser::ParseTime(
|
|||||||
return 0; // success
|
return 0; // success
|
||||||
}
|
}
|
||||||
|
|
||||||
int Parser::ParseSettings(
|
int Parser::ParseSettings(const std::string& line, std::string::size_type idx,
|
||||||
const std::string& line,
|
Cue::settings_t* settings) {
|
||||||
std::string::size_type idx,
|
|
||||||
Cue::settings_t* settings) {
|
|
||||||
settings->clear();
|
settings->clear();
|
||||||
|
|
||||||
if (idx == std::string::npos || idx >= line.length())
|
if (idx == std::string::npos || idx >= line.length())
|
||||||
@@ -529,7 +515,7 @@ int Parser::ParseSettings(
|
|||||||
const char c = line[idx];
|
const char c = line[idx];
|
||||||
|
|
||||||
if (c == kNUL) // end-of-line
|
if (c == kNUL) // end-of-line
|
||||||
return 0; // success
|
return 0; // success
|
||||||
|
|
||||||
if (c != kSPACE && c != kTAB)
|
if (c != kSPACE && c != kTAB)
|
||||||
break;
|
break;
|
||||||
@@ -585,9 +571,8 @@ int Parser::ParseSettings(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Parser::ParseNumber(
|
int Parser::ParseNumber(const std::string& line,
|
||||||
const std::string& line,
|
std::string::size_type* idx_ptr) {
|
||||||
std::string::size_type* idx_ptr) {
|
|
||||||
if (idx_ptr == NULL)
|
if (idx_ptr == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -656,17 +641,11 @@ bool Time::operator<(const Time& rhs) const {
|
|||||||
return (milliseconds < rhs.milliseconds);
|
return (milliseconds < rhs.milliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Time::operator>(const Time& rhs) const {
|
bool Time::operator>(const Time& rhs) const { return rhs.operator<(*this); }
|
||||||
return rhs.operator<(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Time::operator<=(const Time& rhs) const {
|
bool Time::operator<=(const Time& rhs) const { return !this->operator>(rhs); }
|
||||||
return !this->operator>(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Time::operator>=(const Time& rhs) const {
|
bool Time::operator>=(const Time& rhs) const { return !this->operator<(rhs); }
|
||||||
return !this->operator<(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
presentation_t Time::presentation() const {
|
presentation_t Time::presentation() const {
|
||||||
const presentation_t h = 1000LL * 3600LL * presentation_t(hours);
|
const presentation_t h = 1000LL * 3600LL * presentation_t(hours);
|
||||||
@@ -711,9 +690,7 @@ Time Time::operator+(presentation_t d) const {
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
Time& Time::operator-=(presentation_t d) {
|
Time& Time::operator-=(presentation_t d) { return this->operator+=(-d); }
|
||||||
return this->operator+=(-d);
|
|
||||||
}
|
|
||||||
|
|
||||||
presentation_t Time::operator-(const Time& t) const {
|
presentation_t Time::operator-(const Time& t) const {
|
||||||
const presentation_t rhs = t.presentation();
|
const presentation_t rhs = t.presentation();
|
||||||
|
|||||||
@@ -120,8 +120,7 @@ class Parser : private LineReader {
|
|||||||
//
|
//
|
||||||
static int ParseTimingsLine(std::string* line,
|
static int ParseTimingsLine(std::string* line,
|
||||||
std::string::size_type arrow_pos,
|
std::string::size_type arrow_pos,
|
||||||
Time* start_time,
|
Time* start_time, Time* stop_time,
|
||||||
Time* stop_time,
|
|
||||||
Cue::settings_t* settings);
|
Cue::settings_t* settings);
|
||||||
|
|
||||||
// Parse a single time specifier (from the timings line), starting
|
// Parse a single time specifier (from the timings line), starting
|
||||||
@@ -129,23 +128,20 @@ class Parser : private LineReader {
|
|||||||
// is detected. The function modifies offset |off| by the number of
|
// is detected. The function modifies offset |off| by the number of
|
||||||
// characters consumed. Returns negative if error, 0 on success.
|
// characters consumed. Returns negative if error, 0 on success.
|
||||||
//
|
//
|
||||||
static int ParseTime(const std::string& line,
|
static int ParseTime(const std::string& line, std::string::size_type* off,
|
||||||
std::string::size_type* off,
|
|
||||||
Time* time);
|
Time* time);
|
||||||
|
|
||||||
// Parse the cue settings from the timings line, starting at the
|
// Parse the cue settings from the timings line, starting at the
|
||||||
// given offset. Returns negative if error, 0 on success.
|
// given offset. Returns negative if error, 0 on success.
|
||||||
//
|
//
|
||||||
static int ParseSettings(const std::string& line,
|
static int ParseSettings(const std::string& line, std::string::size_type off,
|
||||||
std::string::size_type off,
|
|
||||||
Cue::settings_t* settings);
|
Cue::settings_t* settings);
|
||||||
|
|
||||||
// Parse a non-negative integer from the characters in |line| beginning
|
// Parse a non-negative integer from the characters in |line| beginning
|
||||||
// at offset |off|. The function increments |off| by the number
|
// at offset |off|. The function increments |off| by the number
|
||||||
// of characters consumed. Returns the value, or negative if error.
|
// of characters consumed. Returns the value, or negative if error.
|
||||||
//
|
//
|
||||||
static int ParseNumber(const std::string& line,
|
static int ParseNumber(const std::string& line, std::string::size_type* off);
|
||||||
std::string::size_type* off);
|
|
||||||
|
|
||||||
Reader* const reader_;
|
Reader* const reader_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user