MCPcopy Create free account
hub / github.com/argotorg/solidity / lineAtPosition

Method lineAtPosition

liblangutil/CharStream.cpp:81–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81std::string CharStream::lineAtPosition(int _position) const
82{
83 // if _position points to \n, it returns the line before the \n
84 using size_type = std::string::size_type;
85 size_type searchStart = std::min<size_type>(m_source.size(), size_type(_position));
86 if (searchStart > 0)
87 searchStart--;
88 size_type lineStart = m_source.rfind('\n', searchStart);
89 if (lineStart == std::string::npos)
90 lineStart = 0;
91 else
92 lineStart++;
93 std::string line = m_source.substr(
94 lineStart,
95 std::min(m_source.find('\n', lineStart), m_source.size()) - lineStart
96 );
97 if (!line.empty() && line.back() == '\r')
98 line.pop_back();
99 return line;
100}
101
102LineColumn CharStream::translatePositionToLineColumn(int _position) const
103{

Callers 1

extractMethod · 0.80

Calls 3

sizeMethod · 0.45
findMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected