OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r
ights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r
ights reserved. |
3 * Copyright (C) 2005 Alexey Proskuryakov. | 3 * Copyright (C) 2005 Alexey Proskuryakov. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 ASSERT_WITH_SECURITY_IMPLICATION(index < static_cast<unsigned>(length())); | 563 ASSERT_WITH_SECURITY_IMPLICATION(index < static_cast<unsigned>(length())); |
564 if (!(index < static_cast<unsigned>(length()))) | 564 if (!(index < static_cast<unsigned>(length()))) |
565 return 0; | 565 return 0; |
566 | 566 |
567 if (m_singleCharacterBuffer) { | 567 if (m_singleCharacterBuffer) { |
568 ASSERT(!index); | 568 ASSERT(!index); |
569 ASSERT(length() == 1); | 569 ASSERT(length() == 1); |
570 return m_singleCharacterBuffer; | 570 return m_singleCharacterBuffer; |
571 } | 571 } |
572 | 572 |
573 return string()[startOffset() + index]; | 573 return string()[positionStartOffset() + index]; |
574 } | 574 } |
575 | 575 |
576 String TextIterator::substring(unsigned position, unsigned length) const | 576 String TextIterator::substring(unsigned position, unsigned length) const |
577 { | 577 { |
578 ASSERT_WITH_SECURITY_IMPLICATION(position <= static_cast<unsigned>(this->len
gth())); | 578 ASSERT_WITH_SECURITY_IMPLICATION(position <= static_cast<unsigned>(this->len
gth())); |
579 ASSERT_WITH_SECURITY_IMPLICATION(position + length <= static_cast<unsigned>(
this->length())); | 579 ASSERT_WITH_SECURITY_IMPLICATION(position + length <= static_cast<unsigned>(
this->length())); |
580 if (!length) | 580 if (!length) |
581 return emptyString(); | 581 return emptyString(); |
582 if (m_singleCharacterBuffer) { | 582 if (m_singleCharacterBuffer) { |
583 ASSERT(!position); | 583 ASSERT(!position); |
584 ASSERT(length == 1); | 584 ASSERT(length == 1); |
585 return String(&m_singleCharacterBuffer, 1); | 585 return String(&m_singleCharacterBuffer, 1); |
586 } | 586 } |
587 return string().substring(startOffset() + position, length); | 587 return string().substring(positionStartOffset() + position, length); |
588 } | 588 } |
589 | 589 |
590 void TextIterator::appendTextToStringBuilder(StringBuilder& builder, unsigned po
sition, unsigned maxLength) const | 590 void TextIterator::appendTextToStringBuilder(StringBuilder& builder, unsigned po
sition, unsigned maxLength) const |
591 { | 591 { |
592 unsigned lengthToAppend = std::min(static_cast<unsigned>(length()) - positio
n, maxLength); | 592 unsigned lengthToAppend = std::min(static_cast<unsigned>(length()) - positio
n, maxLength); |
593 if (!lengthToAppend) | 593 if (!lengthToAppend) |
594 return; | 594 return; |
595 if (m_singleCharacterBuffer) { | 595 if (m_singleCharacterBuffer) { |
596 ASSERT(!position); | 596 ASSERT(!position); |
597 builder.append(m_singleCharacterBuffer); | 597 builder.append(m_singleCharacterBuffer); |
598 } else { | 598 } else { |
599 builder.append(string(), startOffset() + position, lengthToAppend); | 599 builder.append(string(), positionStartOffset() + position, lengthToAppen
d); |
600 } | 600 } |
601 } | 601 } |
602 | 602 |
603 bool TextIterator::handleTextNode() | 603 bool TextIterator::handleTextNode() |
604 { | 604 { |
605 if (m_fullyClippedStack.top() && !m_ignoresStyleVisibility) | 605 if (m_fullyClippedStack.top() && !m_ignoresStyleVisibility) |
606 return false; | 606 return false; |
607 | 607 |
608 Text* textNode = toText(m_node); | 608 Text* textNode = toText(m_node); |
609 RenderText* renderer = textNode->renderer(); | 609 RenderText* renderer = textNode->renderer(); |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 if (shouldEmitNewlineForNode(m_node, m_emitsOriginalText)) | 1089 if (shouldEmitNewlineForNode(m_node, m_emitsOriginalText)) |
1090 emitCharacter('\n', m_node->parentNode(), m_node, 0, 1); | 1090 emitCharacter('\n', m_node->parentNode(), m_node, 0, 1); |
1091 else if (m_emitsCharactersBetweenAllVisiblePositions && m_node->renderer() &
& m_node->renderer()->isHR()) | 1091 else if (m_emitsCharactersBetweenAllVisiblePositions && m_node->renderer() &
& m_node->renderer()->isHR()) |
1092 emitCharacter(space, m_node->parentNode(), m_node, 0, 1); | 1092 emitCharacter(space, m_node->parentNode(), m_node, 0, 1); |
1093 else | 1093 else |
1094 representNodeOffsetZero(); | 1094 representNodeOffsetZero(); |
1095 | 1095 |
1096 return true; | 1096 return true; |
1097 } | 1097 } |
1098 | 1098 |
| 1099 void TextIterator::flushPositionOffsets() const |
| 1100 { |
| 1101 if (!m_positionOffsetBaseNode) |
| 1102 return; |
| 1103 int index = m_positionOffsetBaseNode->nodeIndex(); |
| 1104 m_positionStartOffset += index; |
| 1105 m_positionEndOffset += index; |
| 1106 m_positionOffsetBaseNode = nullptr; |
| 1107 } |
| 1108 |
1099 void TextIterator::exitNode() | 1109 void TextIterator::exitNode() |
1100 { | 1110 { |
1101 // prevent emitting a newline when exiting a collapsed block at beginning of
the range | 1111 // prevent emitting a newline when exiting a collapsed block at beginning of
the range |
1102 // FIXME: !m_hasEmitted does not necessarily mean there was a collapsed bloc
k... it could | 1112 // FIXME: !m_hasEmitted does not necessarily mean there was a collapsed bloc
k... it could |
1103 // have been an hr (e.g.). Also, a collapsed block could have height (e.g. a
table) and | 1113 // have been an hr (e.g.). Also, a collapsed block could have height (e.g. a
table) and |
1104 // therefore look like a blank line. | 1114 // therefore look like a blank line. |
1105 if (!m_hasEmitted) | 1115 if (!m_hasEmitted) |
1106 return; | 1116 return; |
1107 | 1117 |
1108 // Emit with a position *inside* m_node, after m_node's contents, in | 1118 // Emit with a position *inside* m_node, after m_node's contents, in |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 m_lastCharacter = m_text[textEndOffset - 1]; | 1184 m_lastCharacter = m_text[textEndOffset - 1]; |
1175 | 1185 |
1176 m_lastTextNodeEndedWithCollapsedSpace = false; | 1186 m_lastTextNodeEndedWithCollapsedSpace = false; |
1177 m_hasEmitted = true; | 1187 m_hasEmitted = true; |
1178 } | 1188 } |
1179 | 1189 |
1180 PassRefPtrWillBeRawPtr<Range> TextIterator::range() const | 1190 PassRefPtrWillBeRawPtr<Range> TextIterator::range() const |
1181 { | 1191 { |
1182 // use the current run information, if we have it | 1192 // use the current run information, if we have it |
1183 if (m_positionNode) { | 1193 if (m_positionNode) { |
1184 if (m_positionOffsetBaseNode) { | 1194 flushPositionOffsets(); |
1185 int index = m_positionOffsetBaseNode->nodeIndex(); | |
1186 m_positionStartOffset += index; | |
1187 m_positionEndOffset += index; | |
1188 m_positionOffsetBaseNode = nullptr; | |
1189 } | |
1190 return Range::create(m_positionNode->document(), m_positionNode, m_posit
ionStartOffset, m_positionNode, m_positionEndOffset); | 1195 return Range::create(m_positionNode->document(), m_positionNode, m_posit
ionStartOffset, m_positionNode, m_positionEndOffset); |
1191 } | 1196 } |
1192 | 1197 |
1193 // otherwise, return the end of the overall range we were given | 1198 // otherwise, return the end of the overall range we were given |
1194 if (m_endContainer) | 1199 if (m_endContainer) |
1195 return Range::create(m_endContainer->document(), m_endContainer, m_endOf
fset, m_endContainer, m_endOffset); | 1200 return Range::create(m_endContainer->document(), m_endContainer, m_endOf
fset, m_endContainer, m_endOffset); |
1196 | 1201 |
1197 return nullptr; | 1202 return nullptr; |
1198 } | 1203 } |
1199 | 1204 |
1200 Node* TextIterator::node() const | 1205 Node* TextIterator::node() const |
1201 { | 1206 { |
1202 RefPtrWillBeRawPtr<Range> textRange = range(); | 1207 if (m_positionNode || m_endContainer) { |
1203 if (!textRange) | 1208 Node* node = startContainer(); |
1204 return 0; | 1209 if (node->offsetInCharacters()) |
| 1210 return node; |
| 1211 return NodeTraversal::childAt(*node, startOffset()); |
| 1212 } |
| 1213 return 0; |
| 1214 } |
1205 | 1215 |
1206 Node* node = textRange->startContainer(); | 1216 int TextIterator::startOffset() const |
1207 if (!node) | 1217 { |
1208 return 0; | 1218 if (m_positionNode) { |
1209 if (node->offsetInCharacters()) | 1219 flushPositionOffsets(); |
1210 return node; | 1220 return m_positionStartOffset; |
| 1221 } |
| 1222 ASSERT(m_endContainer); |
| 1223 return m_endOffset; |
| 1224 } |
1211 | 1225 |
1212 return NodeTraversal::childAt(*node, textRange->startOffset()); | 1226 int TextIterator::endOffset() const |
| 1227 { |
| 1228 if (m_positionNode) { |
| 1229 flushPositionOffsets(); |
| 1230 return m_positionEndOffset; |
| 1231 } |
| 1232 ASSERT(m_endContainer); |
| 1233 return m_endOffset; |
| 1234 } |
| 1235 |
| 1236 Node* TextIterator::startContainer() const |
| 1237 { |
| 1238 if (m_positionNode) { |
| 1239 return m_positionNode; |
| 1240 } |
| 1241 ASSERT(m_endContainer); |
| 1242 return m_endContainer; |
| 1243 } |
| 1244 |
| 1245 Position TextIterator::startPosition() const |
| 1246 { |
| 1247 return createLegacyEditingPosition(startContainer(), startOffset()); |
| 1248 } |
| 1249 |
| 1250 Position TextIterator::endPosition() const |
| 1251 { |
| 1252 return createLegacyEditingPosition(startContainer(), endOffset()); |
1213 } | 1253 } |
1214 | 1254 |
1215 // -------- | 1255 // -------- |
1216 | 1256 |
1217 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range* r,
TextIteratorBehaviorFlags behavior) | 1257 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range* r,
TextIteratorBehaviorFlags behavior) |
1218 : m_node(nullptr) | 1258 : m_node(nullptr) |
1219 , m_offset(0) | 1259 , m_offset(0) |
1220 , m_handledNode(false) | 1260 , m_handledNode(false) |
1221 , m_handledChildren(false) | 1261 , m_handledChildren(false) |
1222 , m_startNode(nullptr) | 1262 , m_startNode(nullptr) |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 } | 1536 } |
1497 | 1537 |
1498 PassRefPtrWillBeRawPtr<Range> SimplifiedBackwardsTextIterator::range() const | 1538 PassRefPtrWillBeRawPtr<Range> SimplifiedBackwardsTextIterator::range() const |
1499 { | 1539 { |
1500 if (m_positionNode) | 1540 if (m_positionNode) |
1501 return Range::create(m_positionNode->document(), m_positionNode, m_posit
ionStartOffset, m_positionNode, m_positionEndOffset); | 1541 return Range::create(m_positionNode->document(), m_positionNode, m_posit
ionStartOffset, m_positionNode, m_positionEndOffset); |
1502 | 1542 |
1503 return Range::create(m_startNode->document(), m_startNode, m_startOffset, m_
startNode, m_startOffset); | 1543 return Range::create(m_startNode->document(), m_startNode, m_startOffset, m_
startNode, m_startOffset); |
1504 } | 1544 } |
1505 | 1545 |
| 1546 Node* SimplifiedBackwardsTextIterator::startContainer() const |
| 1547 { |
| 1548 if (m_positionNode) |
| 1549 return m_positionNode; |
| 1550 return m_startNode; |
| 1551 } |
| 1552 |
| 1553 int SimplifiedBackwardsTextIterator::endOffset() const |
| 1554 { |
| 1555 if (m_positionNode) |
| 1556 return m_positionEndOffset; |
| 1557 return m_startOffset; |
| 1558 } |
| 1559 |
| 1560 Position SimplifiedBackwardsTextIterator::startPosition() const |
| 1561 { |
| 1562 if (m_positionNode) |
| 1563 return createLegacyEditingPosition(m_positionNode, m_positionStartOffset
); |
| 1564 return createLegacyEditingPosition(m_startNode, m_startOffset); |
| 1565 } |
| 1566 |
1506 // -------- | 1567 // -------- |
1507 | 1568 |
1508 CharacterIterator::CharacterIterator(const Range* range, TextIteratorBehaviorFla
gs behavior) | 1569 CharacterIterator::CharacterIterator(const Range* range, TextIteratorBehaviorFla
gs behavior) |
1509 : m_offset(0) | 1570 : m_offset(0) |
1510 , m_runOffset(0) | 1571 , m_runOffset(0) |
1511 , m_atBreak(true) | 1572 , m_atBreak(true) |
1512 , m_textIterator(range, behavior) | 1573 , m_textIterator(range, behavior) |
1513 { | 1574 { |
1514 initialize(); | 1575 initialize(); |
1515 } | 1576 } |
(...skipping 23 matching lines...) Expand all Loading... |
1539 Node* n = r->startContainer(); | 1600 Node* n = r->startContainer(); |
1540 ASSERT(n == r->endContainer()); | 1601 ASSERT(n == r->endContainer()); |
1541 int offset = r->startOffset() + m_runOffset; | 1602 int offset = r->startOffset() + m_runOffset; |
1542 r->setStart(n, offset, ASSERT_NO_EXCEPTION); | 1603 r->setStart(n, offset, ASSERT_NO_EXCEPTION); |
1543 r->setEnd(n, offset + 1, ASSERT_NO_EXCEPTION); | 1604 r->setEnd(n, offset + 1, ASSERT_NO_EXCEPTION); |
1544 } | 1605 } |
1545 } | 1606 } |
1546 return r.release(); | 1607 return r.release(); |
1547 } | 1608 } |
1548 | 1609 |
| 1610 Node* CharacterIterator::startContainer() const |
| 1611 { |
| 1612 return m_textIterator.startContainer(); |
| 1613 } |
| 1614 |
| 1615 int CharacterIterator::startOffset() const |
| 1616 { |
| 1617 if (!m_textIterator.atEnd()) { |
| 1618 if (m_textIterator.length() > 1) |
| 1619 return m_textIterator.startOffset() + m_runOffset; |
| 1620 ASSERT(!m_runOffset); |
| 1621 } |
| 1622 return m_textIterator.startOffset(); |
| 1623 } |
| 1624 |
| 1625 Position CharacterIterator::startPosition() const |
| 1626 { |
| 1627 if (!m_textIterator.atEnd()) { |
| 1628 if (m_textIterator.length() > 1) { |
| 1629 Node* n = m_textIterator.startContainer(); |
| 1630 int offset = m_textIterator.startOffset() + m_runOffset; |
| 1631 return createLegacyEditingPosition(n, offset); |
| 1632 } |
| 1633 ASSERT(!m_runOffset); |
| 1634 } |
| 1635 return m_textIterator.startPosition(); |
| 1636 } |
| 1637 |
| 1638 Position CharacterIterator::endPosition() const |
| 1639 { |
| 1640 if (!m_textIterator.atEnd()) { |
| 1641 if (m_textIterator.length() > 1) { |
| 1642 Node* n = m_textIterator.startContainer(); |
| 1643 int offset = m_textIterator.startOffset() + m_runOffset; |
| 1644 return createLegacyEditingPosition(n, offset + 1); |
| 1645 } |
| 1646 ASSERT(!m_runOffset); |
| 1647 } |
| 1648 return m_textIterator.endPosition(); |
| 1649 } |
| 1650 |
1549 void CharacterIterator::advance(int count) | 1651 void CharacterIterator::advance(int count) |
1550 { | 1652 { |
1551 if (count <= 0) { | 1653 if (count <= 0) { |
1552 ASSERT(!count); | 1654 ASSERT(!count); |
1553 return; | 1655 return; |
1554 } | 1656 } |
1555 | 1657 |
1556 m_atBreak = false; | 1658 m_atBreak = false; |
1557 | 1659 |
1558 // easy if there is enough left in the current m_textIterator run | 1660 // easy if there is enough left in the current m_textIterator run |
(...skipping 28 matching lines...) Expand all Loading... |
1587 } | 1689 } |
1588 | 1690 |
1589 // ran to the end of the m_textIterator... no more runs left | 1691 // ran to the end of the m_textIterator... no more runs left |
1590 m_atBreak = true; | 1692 m_atBreak = true; |
1591 m_runOffset = 0; | 1693 m_runOffset = 0; |
1592 } | 1694 } |
1593 | 1695 |
1594 static void calculateCharacterSubrange(CharacterIterator& it, int offset, int le
ngth, Position& startPosition, Position& endPosition) | 1696 static void calculateCharacterSubrange(CharacterIterator& it, int offset, int le
ngth, Position& startPosition, Position& endPosition) |
1595 { | 1697 { |
1596 it.advance(offset); | 1698 it.advance(offset); |
1597 RefPtrWillBeRawPtr<Range> start = it.range(); | 1699 startPosition = it.startPosition(); |
1598 startPosition = start->startPosition(); | |
1599 | 1700 |
1600 if (length > 1) | 1701 if (length > 1) |
1601 it.advance(length - 1); | 1702 it.advance(length - 1); |
1602 RefPtrWillBeRawPtr<Range> end = it.range(); | 1703 endPosition = it.endPosition(); |
1603 endPosition = end->endPosition(); | |
1604 } | 1704 } |
1605 | 1705 |
1606 BackwardsCharacterIterator::BackwardsCharacterIterator(const Range* range, TextI
teratorBehaviorFlags behavior) | 1706 BackwardsCharacterIterator::BackwardsCharacterIterator(const Range* range, TextI
teratorBehaviorFlags behavior) |
1607 : m_offset(0) | 1707 : m_offset(0) |
1608 , m_runOffset(0) | 1708 , m_runOffset(0) |
1609 , m_atBreak(true) | 1709 , m_atBreak(true) |
1610 , m_textIterator(range, behavior) | 1710 , m_textIterator(range, behavior) |
1611 { | 1711 { |
1612 while (!atEnd() && !m_textIterator.length()) | 1712 while (!atEnd() && !m_textIterator.length()) |
1613 m_textIterator.advance(); | 1713 m_textIterator.advance(); |
1614 } | 1714 } |
1615 | 1715 |
1616 PassRefPtrWillBeRawPtr<Range> BackwardsCharacterIterator::range() const | 1716 PassRefPtrWillBeRawPtr<Range> BackwardsCharacterIterator::range() const |
1617 { | 1717 { |
1618 RefPtrWillBeRawPtr<Range> r = m_textIterator.range(); | 1718 RefPtrWillBeRawPtr<Range> r = m_textIterator.range(); |
1619 if (!m_textIterator.atEnd()) { | 1719 if (!m_textIterator.atEnd()) { |
1620 if (m_textIterator.length() <= 1) { | 1720 if (m_textIterator.length() <= 1) { |
1621 ASSERT(!m_runOffset); | 1721 ASSERT(!m_runOffset); |
1622 } else { | 1722 } else { |
1623 Node* n = r->startContainer(); | 1723 Node* n = r->startContainer(); |
1624 ASSERT(n == r->endContainer()); | 1724 ASSERT(n == r->endContainer()); |
1625 int offset = r->endOffset() - m_runOffset; | 1725 int offset = r->endOffset() - m_runOffset; |
1626 r->setStart(n, offset - 1, ASSERT_NO_EXCEPTION); | 1726 r->setStart(n, offset - 1, ASSERT_NO_EXCEPTION); |
1627 r->setEnd(n, offset, ASSERT_NO_EXCEPTION); | 1727 r->setEnd(n, offset, ASSERT_NO_EXCEPTION); |
1628 } | 1728 } |
1629 } | 1729 } |
1630 return r.release(); | 1730 return r.release(); |
1631 } | 1731 } |
1632 | 1732 |
| 1733 Position BackwardsCharacterIterator::endPosition() const |
| 1734 { |
| 1735 Node* n = m_textIterator.startContainer(); |
| 1736 if (m_textIterator.atEnd()) { |
| 1737 if (m_textIterator.length() > 1) |
| 1738 return createLegacyEditingPosition(n, m_textIterator.endOffset() - m
_runOffset); |
| 1739 ASSERT(!m_runOffset); |
| 1740 } |
| 1741 return createLegacyEditingPosition(n, m_textIterator.endOffset()); |
| 1742 } |
| 1743 |
1633 void BackwardsCharacterIterator::advance(int count) | 1744 void BackwardsCharacterIterator::advance(int count) |
1634 { | 1745 { |
1635 if (count <= 0) { | 1746 if (count <= 0) { |
1636 ASSERT(!count); | 1747 ASSERT(!count); |
1637 return; | 1748 return; |
1638 } | 1749 } |
1639 | 1750 |
1640 m_atBreak = false; | 1751 m_atBreak = false; |
1641 | 1752 |
1642 int remaining = m_textIterator.length() - m_runOffset; | 1753 int remaining = m_textIterator.length() - m_runOffset; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1692 if (!m_didLookAhead) { | 1803 if (!m_didLookAhead) { |
1693 ASSERT(!m_textIterator.atEnd()); | 1804 ASSERT(!m_textIterator.atEnd()); |
1694 m_textIterator.advance(); | 1805 m_textIterator.advance(); |
1695 } | 1806 } |
1696 m_didLookAhead = false; | 1807 m_didLookAhead = false; |
1697 | 1808 |
1698 // Go to next non-empty chunk. | 1809 // Go to next non-empty chunk. |
1699 while (!m_textIterator.atEnd() && !m_textIterator.length()) | 1810 while (!m_textIterator.atEnd() && !m_textIterator.length()) |
1700 m_textIterator.advance(); | 1811 m_textIterator.advance(); |
1701 | 1812 |
1702 m_range = m_textIterator.range(); | |
1703 | |
1704 if (m_textIterator.atEnd()) | 1813 if (m_textIterator.atEnd()) |
1705 return; | 1814 return; |
1706 | 1815 |
1707 while (1) { | 1816 while (1) { |
1708 // If this chunk ends in whitespace we can just use it as our chunk. | 1817 // If this chunk ends in whitespace we can just use it as our chunk. |
1709 if (isSpaceOrNewline(m_textIterator.characterAt(m_textIterator.length()
- 1))) | 1818 if (isSpaceOrNewline(m_textIterator.characterAt(m_textIterator.length()
- 1))) |
1710 return; | 1819 return; |
1711 | 1820 |
1712 // If this is the first chunk that failed, save it in m_buffer before lo
ok ahead. | 1821 // If this is the first chunk that failed, save it in m_buffer before lo
ok ahead. |
1713 if (m_buffer.isEmpty()) | 1822 if (m_buffer.isEmpty()) |
1714 m_textIterator.appendTextTo(m_buffer); | 1823 m_textIterator.appendTextTo(m_buffer); |
1715 | 1824 |
1716 // Look ahead to next chunk. If it is whitespace or a break, we can use
the previous stuff | 1825 // Look ahead to next chunk. If it is whitespace or a break, we can use
the previous stuff |
1717 m_textIterator.advance(); | 1826 m_textIterator.advance(); |
1718 if (m_textIterator.atEnd() || !m_textIterator.length() || isSpaceOrNewli
ne(m_textIterator.characterAt(0))) { | 1827 if (m_textIterator.atEnd() || !m_textIterator.length() || isSpaceOrNewli
ne(m_textIterator.characterAt(0))) { |
1719 m_didLookAhead = true; | 1828 m_didLookAhead = true; |
1720 return; | 1829 return; |
1721 } | 1830 } |
1722 | 1831 |
1723 // Start gobbling chunks until we get to a suitable stopping point | 1832 // Start gobbling chunks until we get to a suitable stopping point |
1724 m_textIterator.appendTextTo(m_buffer); | 1833 m_textIterator.appendTextTo(m_buffer); |
1725 m_range->setEnd(m_textIterator.range()->endContainer(), m_textIterator.r
ange()->endOffset(), IGNORE_EXCEPTION); | |
1726 } | 1834 } |
1727 } | 1835 } |
1728 | 1836 |
1729 int WordAwareIterator::length() const | 1837 int WordAwareIterator::length() const |
1730 { | 1838 { |
1731 if (!m_buffer.isEmpty()) | 1839 if (!m_buffer.isEmpty()) |
1732 return m_buffer.size(); | 1840 return m_buffer.size(); |
1733 return m_textIterator.length(); | 1841 return m_textIterator.length(); |
1734 } | 1842 } |
1735 | 1843 |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 resultEnd = collapseTo; | 2323 resultEnd = collapseTo; |
2216 return; | 2324 return; |
2217 } | 2325 } |
2218 } | 2326 } |
2219 | 2327 |
2220 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo
rFindPlainText); | 2328 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo
rFindPlainText); |
2221 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re
sultStart, resultEnd); | 2329 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re
sultStart, resultEnd); |
2222 } | 2330 } |
2223 | 2331 |
2224 } | 2332 } |
OLD | NEW |