Exemplo n.º 1
0
static EphemeralRangeTemplate<Strategy> findPlainTextAlgorithm(
    const EphemeralRangeTemplate<Strategy>& inputRange,
    const String& target,
    FindOptions options) {
  // CharacterIterator requires layoutObjects to be up to date.
  if (!inputRange.startPosition().isConnected())
    return EphemeralRangeTemplate<Strategy>();
  DCHECK_EQ(inputRange.startPosition().document(),
            inputRange.endPosition().document());

  // FIXME: Reduce the code duplication with above (but how?).
  size_t matchStart;
  size_t matchLength;
  {
    TextIteratorBehaviorFlags behavior = iteratorFlagsForFindPlainText;
    if (options & FindAPICall)
      behavior |= TextIteratorForWindowFind;
    CharacterIteratorAlgorithm<Strategy> findIterator(inputRange, behavior);
    matchLength =
        findPlainTextInternal(findIterator, target, options, matchStart);
    if (!matchLength)
      return EphemeralRangeTemplate<Strategy>(options & Backwards
                                                  ? inputRange.startPosition()
                                                  : inputRange.endPosition());
  }

  CharacterIteratorAlgorithm<Strategy> computeRangeIterator(
      inputRange, iteratorFlagsForFindPlainText);
  return computeRangeIterator.calculateCharacterSubrange(matchStart,
                                                         matchLength);
}
static String extractString(const Element& element)
{
    const EphemeralRangeTemplate<Strategy> range = EphemeralRangeTemplate<Strategy>::rangeOfContents(element);
    Vector<UChar> buffer;
    for (SimplifiedBackwardsTextIteratorAlgorithm<Strategy> it(range.startPosition(), range.endPosition()); !it.atEnd(); it.advance()) {
        it.prependTextTo(buffer);
    }
    return String(buffer);
}
static String extractString(const Element& element) {
  const EphemeralRangeTemplate<Strategy> range =
      EphemeralRangeTemplate<Strategy>::rangeOfContents(element);
  BackwardsTextBuffer buffer;
  for (SimplifiedBackwardsTextIteratorAlgorithm<Strategy> it(
           range.startPosition(), range.endPosition());
       !it.atEnd(); it.advance()) {
    it.copyTextTo(&buffer);
  }
  return String(buffer.data(), buffer.size());
}
EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate(const EphemeralRangeTemplate<Strategy>& other)
    : EphemeralRangeTemplate(other.m_startPosition, other.m_endPosition)
{
    ASSERT(other.isValid());
}
CharacterIteratorAlgorithm<Strategy>::CharacterIteratorAlgorithm(const EphemeralRangeTemplate<Strategy>& range, TextIteratorBehaviorFlags behavior)
    : CharacterIteratorAlgorithm(range.startPosition(), range.endPosition(), behavior)
{
}