diff --git a/src/util/json/job.cpp b/src/util/json/job.cpp index f196f5f..acf1e60 100644 --- a/src/util/json/job.cpp +++ b/src/util/json/job.cpp @@ -60,17 +60,15 @@ void Job::printErrorLine(Token token, const char* message) "%s" "\n"; printf(errorFormat.c_str(), - token.line, - token.column, + token.line + 1, + token.column + 1, message); // Get the JSON line that caused the error std::istringstream input(m_input); std::string line; - size_t count = 0; - while (std::getline(input, line)) { - count++; - if (count == token.line) { + for (size_t i = 0; std::getline(input, line); ++i) { + if (i == token.line) { break; } } @@ -92,9 +90,9 @@ void Job::printErrorLine(Token token, const char* message) "\033[0m" // Reset "\n"; printf(lineFormat.c_str(), - token.line, - line.substr(0, token.column - 1).c_str(), - line.substr(token.column - 1).c_str()); + token.line + 1, + line.substr(0, token.column).c_str(), + line.substr(token.column).c_str()); // Arrow pointer std::string arrowFormat = " %s | " @@ -104,7 +102,7 @@ void Job::printErrorLine(Token token, const char* message) "\n"; printf(arrowFormat.c_str(), std::string(m_lineNumbersWidth, ' ').c_str(), - std::string(token.column - 1, ' ').c_str(), + std::string(token.column, ' ').c_str(), std::string(line.length() - token.column, '~').c_str()); } diff --git a/src/util/json/lexer.cpp b/src/util/json/lexer.cpp index 703da2f..abe8361 100644 --- a/src/util/json/lexer.cpp +++ b/src/util/json/lexer.cpp @@ -103,11 +103,11 @@ void Lexer::analyze() if (peekNext() == '\n') { // CRLF \r\n break; } - m_column = 0; + m_column = -1; m_line++; break; case '\n': - m_column = 0; + m_column = -1; m_line++; break; default: diff --git a/src/util/json/lexer.h b/src/util/json/lexer.h index 07de395..f33812d 100644 --- a/src/util/json/lexer.h +++ b/src/util/json/lexer.h @@ -63,8 +63,8 @@ private: Job* m_job { nullptr }; size_t m_index { 0 }; - size_t m_column { 1 }; - size_t m_line { 1 }; + size_t m_column { 0 }; + size_t m_line { 0 }; std::vector* m_tokens { nullptr }; };