| Index: third_party/WebKit/Source/wtf/text/TextPosition.cpp
|
| diff --git a/third_party/WebKit/Source/wtf/text/TextPosition.cpp b/third_party/WebKit/Source/wtf/text/TextPosition.cpp
|
| index 27e79f8d5fca42c7418318940319d1b6e9b7ebb8..2f2e1430f3f4d232bfc07c68d44ee6bd701eb9f2 100644
|
| --- a/third_party/WebKit/Source/wtf/text/TextPosition.cpp
|
| +++ b/third_party/WebKit/Source/wtf/text/TextPosition.cpp
|
| @@ -30,37 +30,42 @@
|
|
|
| namespace WTF {
|
|
|
| -PassOwnPtr<Vector<unsigned>> lineEndings(const String& text)
|
| -{
|
| - OwnPtr<Vector<unsigned>> result(adoptPtr(new Vector<unsigned>()));
|
| +PassOwnPtr<Vector<unsigned>> lineEndings(const String& text) {
|
| + OwnPtr<Vector<unsigned>> result(adoptPtr(new Vector<unsigned>()));
|
|
|
| - unsigned start = 0;
|
| - while (start < text.length()) {
|
| - size_t lineEnd = text.find('\n', start);
|
| - if (lineEnd == kNotFound)
|
| - break;
|
| + unsigned start = 0;
|
| + while (start < text.length()) {
|
| + size_t lineEnd = text.find('\n', start);
|
| + if (lineEnd == kNotFound)
|
| + break;
|
|
|
| - result->append(static_cast<unsigned>(lineEnd));
|
| - start = lineEnd + 1;
|
| - }
|
| - result->append(text.length());
|
| + result->append(static_cast<unsigned>(lineEnd));
|
| + start = lineEnd + 1;
|
| + }
|
| + result->append(text.length());
|
|
|
| - return result.release();
|
| + return result.release();
|
| }
|
|
|
| -OrdinalNumber TextPosition::toOffset(const Vector<unsigned>& lineEndings)
|
| -{
|
| - unsigned lineStartOffset = m_line != OrdinalNumber::first() ? lineEndings.at(m_line.zeroBasedInt() - 1) + 1 : 0;
|
| - return OrdinalNumber::fromZeroBasedInt(lineStartOffset + m_column.zeroBasedInt());
|
| +OrdinalNumber TextPosition::toOffset(const Vector<unsigned>& lineEndings) {
|
| + unsigned lineStartOffset = m_line != OrdinalNumber::first()
|
| + ? lineEndings.at(m_line.zeroBasedInt() - 1) + 1
|
| + : 0;
|
| + return OrdinalNumber::fromZeroBasedInt(lineStartOffset +
|
| + m_column.zeroBasedInt());
|
| }
|
|
|
| -TextPosition TextPosition::fromOffsetAndLineEndings(unsigned offset, const Vector<unsigned>& lineEndings)
|
| -{
|
| - const unsigned* foundLineEnding = std::lower_bound(lineEndings.begin(), lineEndings.end(), offset);
|
| - int lineIndex = foundLineEnding - &lineEndings.at(0);
|
| - unsigned lineStartOffset = lineIndex > 0 ? lineEndings.at(lineIndex - 1) + 1 : 0;
|
| - int column = offset - lineStartOffset;
|
| - return TextPosition(OrdinalNumber::fromZeroBasedInt(lineIndex), OrdinalNumber::fromZeroBasedInt(column));
|
| +TextPosition TextPosition::fromOffsetAndLineEndings(
|
| + unsigned offset,
|
| + const Vector<unsigned>& lineEndings) {
|
| + const unsigned* foundLineEnding =
|
| + std::lower_bound(lineEndings.begin(), lineEndings.end(), offset);
|
| + int lineIndex = foundLineEnding - &lineEndings.at(0);
|
| + unsigned lineStartOffset =
|
| + lineIndex > 0 ? lineEndings.at(lineIndex - 1) + 1 : 0;
|
| + int column = offset - lineStartOffset;
|
| + return TextPosition(OrdinalNumber::fromZeroBasedInt(lineIndex),
|
| + OrdinalNumber::fromZeroBasedInt(column));
|
| }
|
|
|
| -} // namespace WTF
|
| +} // namespace WTF
|
|
|