Read the next non-comment/whitespace line.
| 75 | |
| 76 | // Read the next non-comment/whitespace line. |
| 77 | const char* TFE_Parser::readLine(size_t& bufferPos, bool skipLeadingWhitespace, bool commentOnlyAtBeginning) |
| 78 | { |
| 79 | if (bufferPos >= m_bufferLen || m_bufferLen < 1) { return nullptr; } |
| 80 | |
| 81 | // Keep reading lines until either one has real content or we reach the end of the buffer. |
| 82 | bool lineHasContent = false; |
| 83 | s32 skip = -1; |
| 84 | while (!lineHasContent && bufferPos < m_bufferLen) |
| 85 | { |
| 86 | s_line[0] = 0; |
| 87 | size_t linePos = 0; |
| 88 | bool inComment = false; |
| 89 | for (size_t i = bufferPos; i < m_bufferLen; i++) |
| 90 | { |
| 91 | bufferPos = i + 1; |
| 92 | |
| 93 | if (m_enableBlockComments && i > 0 && m_buffer[i-1] == '*' && m_buffer[i] == '/') |
| 94 | { |
| 95 | m_blockComment = false; |
| 96 | } |
| 97 | else if (m_enableBlockComments && m_buffer[i] == '/' && m_buffer[i+1] == '*') |
| 98 | { |
| 99 | m_blockComment = true; |
| 100 | } |
| 101 | else if (m_buffer[i] == '\n' || m_buffer[i] == '\r') |
| 102 | { |
| 103 | // search for the next valid character, then end it. |
| 104 | for (size_t ii = i + 1; ii < m_bufferLen; ii++) |
| 105 | { |
| 106 | if (m_buffer[ii] != '\n' && m_buffer[ii] != '\r') |
| 107 | { |
| 108 | bufferPos = ii; |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | break; |
| 113 | } |
| 114 | else if (!inComment && !m_blockComment) |
| 115 | { |
| 116 | // is this the beginning of a comment? |
| 117 | if (!commentOnlyAtBeginning) |
| 118 | { |
| 119 | inComment = isComment(m_buffer + i); |
| 120 | } |
| 121 | |
| 122 | // if not in a comment, go ahead and add to the line. |
| 123 | if (!inComment) |
| 124 | { |
| 125 | if (m_convertToUppercase) |
| 126 | { |
| 127 | s_line[linePos++] = toupper(m_buffer[i]); |
| 128 | } |
| 129 | else |
| 130 | { |
| 131 | s_line[linePos++] = m_buffer[i]; |
| 132 | } |
| 133 | assert(linePos <= 4096); |
| 134 | } |
no test coverage detected