Browse Source

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

master
Riyyi 2 years ago
parent
commit
fc3dc936fa
  1. 6
      src/util/json/job.cpp

6
src/util/json/job.cpp

@ -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()

Loading…
Cancel
Save