Fix caret position for errors with utf source

This commit is contained in:
Mathias Baumann
2020-05-25 14:27:03 +02:00
parent 7a6ad61583
commit 7f3d437ffe
7 changed files with 31 additions and 4 deletions
@@ -21,6 +21,7 @@
#include <liblangutil/SourceReferenceFormatterHuman.h>
#include <liblangutil/Scanner.h>
#include <liblangutil/Exceptions.h>
#include <libsolutil/UTF8.h>
#include <iomanip>
using namespace std;
@@ -103,12 +104,13 @@ void SourceReferenceFormatterHuman::printSourceLocation(SourceReference const& _
m_stream << leftpad << ' ';
frameColored() << '|';
m_stream << ' ';
for_each(
_ref.text.cbegin(),
_ref.text.cbegin() + _ref.startColumn,
_ref.text.cbegin() + numCodepoints(_ref.text.substr(0, _ref.startColumn)),
[this](char ch) { m_stream << (ch == '\t' ? '\t' : ' '); }
);
diagColored() << string(locationLength, '^');
diagColored() << string(numCodepoints(_ref.text.substr(_ref.startColumn, locationLength)), '^');
m_stream << '\n';
}
else