1 // Copyright (C) 2013 Google Inc. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google Inc. nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 #ifndef TextRunIterator_h 30 #define TextRunIterator_h 31 32 #include "platform/text/TextRun.h" 33 34 namespace WebCore { 35 36 class TextRunIterator { 37 public: TextRunIterator()38 TextRunIterator() 39 : m_textRun(0) 40 , m_offset(0) 41 { 42 } 43 TextRunIterator(const TextRun * textRun,unsigned offset)44 TextRunIterator(const TextRun* textRun, unsigned offset) 45 : m_textRun(textRun) 46 , m_offset(offset) 47 { 48 } 49 TextRunIterator(const TextRunIterator & other)50 TextRunIterator(const TextRunIterator& other) 51 : m_textRun(other.m_textRun) 52 , m_offset(other.m_offset) 53 { 54 } 55 offset()56 unsigned offset() const { return m_offset; } increment()57 void increment() { m_offset++; } atEnd()58 bool atEnd() const { return !m_textRun || m_offset >= m_textRun->length(); } current()59 UChar current() const { return (*m_textRun)[m_offset]; } direction()60 WTF::Unicode::Direction direction() const { return atEnd() ? WTF::Unicode::OtherNeutral : WTF::Unicode::direction(current()); } atParagraphSeparator()61 bool atParagraphSeparator() const { return current() == '\n'; } 62 63 bool operator==(const TextRunIterator& other) 64 { 65 return m_offset == other.m_offset && m_textRun == other.m_textRun; 66 } 67 68 bool operator!=(const TextRunIterator& other) { return !operator==(other); } 69 70 private: 71 const TextRun* m_textRun; 72 int m_offset; 73 }; 74 75 76 } // namespace WebCore 77 78 #endif // TextRunIterator_h 79