void ContainerFormatParser::advance (void)
{
	if (m_element != CONTAINERELEMENT_INCOMPLETE)
	{
		m_buf.popBack(m_elementLen);

		m_element		= CONTAINERELEMENT_INCOMPLETE;
		m_elementLen	= 0;
		m_attribute.clear();
		m_value.clear();
	}

	for (;;)
	{
		int curChar = getChar(m_elementLen);

		if (curChar != (int)END_OF_BUFFER)
			m_elementLen += 1;

		if (curChar == END_OF_STRING)
		{
			if (m_elementLen == 1)
				m_element = CONTAINERELEMENT_END_OF_STRING;
			else if (m_state == STATE_CONTAINER_LINE)
				parseContainerLine();
			else
				m_element = CONTAINERELEMENT_TEST_LOG_DATA;

			break;
		}
		else if (curChar == (int)END_OF_BUFFER)
		{
			if (m_elementLen > 0 && m_state == STATE_DATA)
				m_element = CONTAINERELEMENT_TEST_LOG_DATA;

			break;
		}
		else if (curChar == '\r' || curChar == '\n')
		{
			// Check for \r\n
			int nextChar = getChar(m_elementLen);
			if (curChar == '\n' || (nextChar != (int)END_OF_BUFFER && nextChar != '\n'))
			{
				if (m_state == STATE_CONTAINER_LINE)
					parseContainerLine();
				else
					m_element = CONTAINERELEMENT_TEST_LOG_DATA;

				m_state = STATE_AT_LINE_START;
				break;
			}
			// else handle following end or \n in next iteration.
		}
		else if (m_state == STATE_AT_LINE_START)
		{
			DE_ASSERT(m_elementLen == 1);
			m_state = (curChar == '#') ? STATE_CONTAINER_LINE : STATE_DATA;
		}
	}
}
Exemplo n.º 2
0
bool
FileIdentifier::parseOutput() {
  m_file = std::make_shared<SourceFile>(m_fileName);

  for (auto &line : m_output) {
    if (line.startsWith("File"))
      parseContainerLine(line);

    else if (line.startsWith("Track"))
      parseTrackLine(line);

    else if (line.startsWith("Attachment"))
      parseAttachmentLine(line);

    else if (line.startsWith("Chapters"))
      parseChaptersLine(line);

    else if (line.startsWith("Global tags"))
      parseGlobalTagsLine(line);

    else if (line.startsWith("Tags"))
      parseTagsLine(line);

    else if (line.startsWith("Track"))
      parseTrackLine(line);
  }

  return m_file->isValid();
}