Util: Fix line count detection for non-trailing newline in Job

This commit is contained in:
Riyyi
2022-07-10 15:58:50 +02:00
parent f2ea84be0f
commit fc3dc936fa
+4 -2
View File
@@ -17,9 +17,11 @@ namespace Json {
Job::Job(const std::string& input) Job::Job(const std::string& input)
: m_input(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() Job::~Job()