diff options
Diffstat (limited to 'Source/WebCore/platform/text/TextBreakIterator.h')
-rw-r--r-- | Source/WebCore/platform/text/TextBreakIterator.h | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/Source/WebCore/platform/text/TextBreakIterator.h b/Source/WebCore/platform/text/TextBreakIterator.h index 17cf5f0..e4cba77 100644 --- a/Source/WebCore/platform/text/TextBreakIterator.h +++ b/Source/WebCore/platform/text/TextBreakIterator.h @@ -28,7 +28,7 @@ namespace WebCore { class TextBreakIterator; - // Note: The returned iterator is good only until you get another iterator. + // Note: The returned iterator is good only until you get another iterator, with the exception of acquireLineBreakIterator. // Iterates over "extended grapheme clusters", as defined in UAX #29. // Note that platform implementations may be less sophisticated - e.g. ICU prior to @@ -43,7 +43,8 @@ namespace WebCore { TextBreakIterator* cursorMovementIterator(const UChar*, int length); TextBreakIterator* wordBreakIterator(const UChar*, int length); - TextBreakIterator* lineBreakIterator(const UChar*, int length); + TextBreakIterator* acquireLineBreakIterator(const UChar*, int length); + void releaseLineBreakIterator(TextBreakIterator*); TextBreakIterator* sentenceBreakIterator(const UChar*, int length); int textBreakFirst(TextBreakIterator*); @@ -57,6 +58,47 @@ namespace WebCore { const int TextBreakDone = -1; +class LazyLineBreakIterator { +public: + LazyLineBreakIterator(const UChar* string = 0, int length = 0) + : m_string(string) + , m_length(length) + , m_iterator(0) + { + } + + ~LazyLineBreakIterator() + { + if (m_iterator) + releaseLineBreakIterator(m_iterator); + } + + const UChar* string() const { return m_string; } + int length() const { return m_length; } + + TextBreakIterator* get() + { + if (!m_iterator) + m_iterator = acquireLineBreakIterator(m_string, m_length); + return m_iterator; + } + + void reset(const UChar* string, int length) + { + if (m_iterator) + releaseLineBreakIterator(m_iterator); + + m_string = string; + m_length = length; + m_iterator = 0; + } + +private: + const UChar* m_string; + int m_length; + TextBreakIterator* m_iterator; +}; + } #endif |