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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 540 |
541 size_t newSize = size - (matchStart + 1); | 541 size_t newSize = size - (matchStart + 1); |
542 memmove(m_buffer.data(), m_buffer.data() + matchStart + 1, newSize * sizeof(
UChar)); | 542 memmove(m_buffer.data(), m_buffer.data() + matchStart + 1, newSize * sizeof(
UChar)); |
543 m_prefixLength -= std::min<size_t>(m_prefixLength, matchStart + 1); | 543 m_prefixLength -= std::min<size_t>(m_prefixLength, matchStart + 1); |
544 m_buffer.shrink(newSize); | 544 m_buffer.shrink(newSize); |
545 | 545 |
546 start = size - matchStart; | 546 start = size - matchStart; |
547 return matchedLength; | 547 return matchedLength; |
548 } | 548 } |
549 | 549 |
550 static PassRefPtrWillBeRawPtr<Range> collapsedToBoundary(const Range* range, boo
l forward) | |
551 { | |
552 RefPtrWillBeRawPtr<Range> result = range->cloneRange(); | |
553 result->collapse(!forward); | |
554 return result.release(); | |
555 } | |
556 | |
557 // Check if there's any unpaird surrogate code point. | 550 // Check if there's any unpaird surrogate code point. |
558 // Non-character code points are not checked. | 551 // Non-character code points are not checked. |
559 static bool isValidUTF16(const String& s) | 552 static bool isValidUTF16(const String& s) |
560 { | 553 { |
561 if (s.is8Bit()) | 554 if (s.is8Bit()) |
562 return true; | 555 return true; |
563 const UChar* ustr = s.characters16(); | 556 const UChar* ustr = s.characters16(); |
564 size_t length = s.length(); | 557 size_t length = s.length(); |
565 size_t position = 0; | 558 size_t position = 0; |
566 while (position < length) { | 559 while (position < length) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 buffer.reachedBreak(); | 608 buffer.reachedBreak(); |
616 goto tryAgain; | 609 goto tryAgain; |
617 } | 610 } |
618 } | 611 } |
619 | 612 |
620 return matchLength; | 613 return matchLength; |
621 } | 614 } |
622 | 615 |
623 static const TextIteratorBehaviorFlags iteratorFlagsForFindPlainText = TextItera
torEntersTextControls | TextIteratorEntersOpenShadowRoots | TextIteratorDoesNotB
reakAtReplacedElement; | 616 static const TextIteratorBehaviorFlags iteratorFlagsForFindPlainText = TextItera
torEntersTextControls | TextIteratorEntersOpenShadowRoots | TextIteratorDoesNotB
reakAtReplacedElement; |
624 | 617 |
625 PassRefPtrWillBeRawPtr<Range> findPlainText(const Range* range, const String& ta
rget, FindOptions options) | |
626 { | |
627 // First, find the text. | |
628 size_t matchStart; | |
629 size_t matchLength; | |
630 { | |
631 CharacterIterator findIterator(range, iteratorFlagsForFindPlainText); | |
632 matchLength = findPlainTextInternal(findIterator, target, options, match
Start); | |
633 if (!matchLength) | |
634 return collapsedToBoundary(range, !(options & Backwards)); | |
635 } | |
636 | |
637 // Then, find the document position of the start and the end of the text. | |
638 CharacterIterator computeRangeIterator(range, iteratorFlagsForFindPlainText)
; | |
639 Position resultStart; | |
640 Position resultEnd; | |
641 computeRangeIterator.calculateCharacterSubrange(matchStart, matchLength, res
ultStart, resultEnd); | |
642 return Range::create(range->ownerDocument(), resultStart, resultEnd); | |
643 } | |
644 | |
645 void findPlainText(const Position& inputStart, const Position& inputEnd, const S
tring& target, FindOptions options, Position& resultStart, Position& resultEnd) | 618 void findPlainText(const Position& inputStart, const Position& inputEnd, const S
tring& target, FindOptions options, Position& resultStart, Position& resultEnd) |
646 { | 619 { |
647 resultStart.clear(); | 620 resultStart.clear(); |
648 resultEnd.clear(); | 621 resultEnd.clear(); |
649 // CharacterIterator requires layoutObjects to be up-to-date. | 622 // CharacterIterator requires layoutObjects to be up-to-date. |
650 if (!inputStart.inDocument()) | 623 if (!inputStart.inDocument()) |
651 return; | 624 return; |
652 ASSERT(inputStart.document() == inputEnd.document()); | 625 ASSERT(inputStart.document() == inputEnd.document()); |
653 | 626 |
654 // FIXME: Reduce the code duplication with above (but how?). | 627 // FIXME: Reduce the code duplication with above (but how?). |
655 size_t matchStart; | 628 size_t matchStart; |
656 size_t matchLength; | 629 size_t matchLength; |
657 { | 630 { |
658 CharacterIterator findIterator(inputStart, inputEnd, iteratorFlagsForFin
dPlainText); | 631 CharacterIterator findIterator(inputStart, inputEnd, iteratorFlagsForFin
dPlainText); |
659 matchLength = findPlainTextInternal(findIterator, target, options, match
Start); | 632 matchLength = findPlainTextInternal(findIterator, target, options, match
Start); |
660 if (!matchLength) { | 633 if (!matchLength) { |
661 const Position& collapseTo = options & Backwards ? inputStart : inpu
tEnd; | 634 const Position& collapseTo = options & Backwards ? inputStart : inpu
tEnd; |
662 resultStart = collapseTo; | 635 resultStart = collapseTo; |
663 resultEnd = collapseTo; | 636 resultEnd = collapseTo; |
664 return; | 637 return; |
665 } | 638 } |
666 } | 639 } |
667 | 640 |
668 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo
rFindPlainText); | 641 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo
rFindPlainText); |
669 computeRangeIterator.calculateCharacterSubrange(matchStart, matchLength, res
ultStart, resultEnd); | 642 computeRangeIterator.calculateCharacterSubrange(matchStart, matchLength, res
ultStart, resultEnd); |
670 } | 643 } |
671 | 644 |
672 } // namespace blink | 645 } // namespace blink |
OLD | NEW |