void Parser::SearchForEpisodeTitle() { auto token_begin = tokens_.begin(); auto token_end = tokens_.begin(); do { // Find the first non-enclosed unknown token token_begin = FindToken(token_end, tokens_.end(), kFlagNotEnclosed | kFlagUnknown); if (token_begin == tokens_.end()) return; // Continue until a bracket or identifier is found token_end = FindToken(token_begin, tokens_.end(), kFlagBracket | kFlagIdentifier); // Ignore if it's only a dash if (std::distance(token_begin, token_end) <= 2 && IsDashCharacter(token_begin->content)) { continue; } // Build episode title BuildElement(kElementEpisodeTitle, false, token_begin, token_end); return; } while (token_begin != tokens_.end()); }
bool Parser::SearchForSeparatedNumbers(std::vector<size_t>& tokens) { for (auto token_index = tokens.begin(); token_index != tokens.end(); ++token_index) { auto token = tokens_.begin() + *token_index; auto previous_token = FindPreviousToken(tokens_, token, kFlagNotDelimiter); // See if the number has a preceding "-" separator if (previous_token != tokens_.end() && previous_token->category == kUnknown && IsDashCharacter(previous_token->content)) { if (SetEpisodeNumber(token->content, *token, true)) { previous_token->category = kIdentifier; return true; } } } return false; }