SourceLocation::singleLineSnippet(): Handle \r\n line endings correctly

This commit is contained in:
Kamil Śliwak 2021-08-31 16:01:52 +02:00
parent a7612ce873
commit 98ab6d91ed

View File

@ -138,7 +138,7 @@ string CharStream::singleLineSnippet(string const& _sourceCode, SourceLocation c
return {}; return {};
string cut = _sourceCode.substr(static_cast<size_t>(_location.start), static_cast<size_t>(_location.end - _location.start)); string cut = _sourceCode.substr(static_cast<size_t>(_location.start), static_cast<size_t>(_location.end - _location.start));
auto newLinePos = cut.find_first_of("\n"); auto newLinePos = cut.find_first_of("\n\r");
if (newLinePos != string::npos) if (newLinePos != string::npos)
cut = cut.substr(0, newLinePos) + "..."; cut = cut.substr(0, newLinePos) + "...";