Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Unified Diff: third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp

Issue 1647483003: Introduce TextBuffer as Output Type of copyTextTo() for Text Iterators (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp
diff --git a/third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp b/third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp
index 3d8aeab7673cc8d8e41059adffc7ebadd6fadcd2..ff6ae8095ed46c63dc90981e9772cd44ba11869a 100644
--- a/third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp
+++ b/third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp
@@ -410,6 +410,41 @@ bool SimplifiedBackwardsTextIteratorAlgorithm<Strategy>::isBetweenSurrogatePair(
return position > 0 && position < length() && U16_IS_TRAIL(characterAt(position - 1)) && U16_IS_LEAD(characterAt(position));
}
+template <typename Strategy>
+int SimplifiedBackwardsTextIteratorAlgorithm<Strategy>::copyTextTo(BackwardsTextBuffer& output, int position, int minLength) const
+{
+ int copiedLength = isBetweenSurrogatePair(position + minLength) ? minLength + 1 : minLength;
+ copyCodeUnitsTo(output, position, copiedLength);
+ return copiedLength;
+}
+
+template <typename Strategy>
+int SimplifiedBackwardsTextIteratorAlgorithm<Strategy>::copyTextTo(BackwardsTextBuffer& output, int position) const
+{
+ return copyTextTo(output, position, m_textLength - position);
+}
+
+template <typename Strategy>
+void SimplifiedBackwardsTextIteratorAlgorithm<Strategy>::copyCodeUnitsTo(BackwardsTextBuffer& output, int position, int copyLength) const
+{
+ ASSERT(position >= 0);
+ ASSERT(copyLength >= 0);
+ ASSERT(position + copyLength <= m_textLength);
+ // Make sure there's no integer overflow.
+ ASSERT(position + copyLength >= position);
+ if (m_textLength == 0 || copyLength == 0)
+ return;
+ if (m_singleCharacterBuffer) {
+ output.pushCharacters(m_singleCharacterBuffer, 1);
+ return;
+ }
+ int offset = m_textOffset + m_textLength - position - copyLength;
+ if (m_textContainer.is8Bit())
+ output.pushRange(m_textContainer.characters8() + offset, copyLength);
+ else
+ output.pushRange(m_textContainer.characters16() + offset, copyLength);
+}
+
template class CORE_TEMPLATE_EXPORT SimplifiedBackwardsTextIteratorAlgorithm<EditingStrategy>;
template class CORE_TEMPLATE_EXPORT SimplifiedBackwardsTextIteratorAlgorithm<EditingInComposedTreeStrategy>;

Powered by Google App Engine
This is Rietveld 408576698