From fc3dc936fa5b55b72a7098fbc14f4ea485d4a786 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sun, 10 Jul 2022 15:58:50 +0200 Subject: [PATCH] Util: Fix line count detection for non-trailing newline in Job --- src/util/json/job.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/util/json/job.cpp b/src/util/json/job.cpp index acf1e60..5e1a60b 100644 --- a/src/util/json/job.cpp +++ b/src/util/json/job.cpp @@ -17,9 +17,11 @@ namespace Json { Job::Job(const std::string& input) : m_input(input) - // FIXME: handle case where the file doenst have a trailing newline - , m_lineNumbersWidth(std::to_string(std::count(m_input.begin(), m_input.end(), '\n') - 1).length()) { + // FIXME: Make this work for all newline types: \n, \r, \r\n + m_lineNumbersWidth = std::count(m_input.begin(), m_input.end(), '\n'); + m_lineNumbersWidth += m_input.back() == '\n' ? 0 : 1; + m_lineNumbersWidth = std::to_string(m_lineNumbersWidth).length(); } Job::~Job()