Merge pull request #8268 from a3d4/lineatposition-crlf

Avoided trailing '\r' in CharStream::lineAtPosition().
This commit is contained in:
chriseth 2020-02-10 15:58:52 +01:00 committed by GitHub
commit 64bb0d55e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -93,10 +93,13 @@ string CharStream::lineAtPosition(int _position) const
lineStart = 0; lineStart = 0;
else else
lineStart++; lineStart++;
return m_source.substr( string line = m_source.substr(
lineStart, lineStart,
min(m_source.find('\n', lineStart), m_source.size()) - lineStart min(m_source.find('\n', lineStart), m_source.size()) - lineStart
); );
if (!line.empty() && line.back() == '\r')
line.pop_back();
return line;
} }
tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const