OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Lars Knoll <lars@trolltech.com> | 2 * Copyright (C) 2006 Lars Knoll <lars@trolltech.com> |
3 * Copyright (C) 2007, 2011, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2007, 2011, 2012 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "platform/PlatformExport.h" | 25 #include "platform/PlatformExport.h" |
26 #include "wtf/text/AtomicString.h" | 26 #include "wtf/text/AtomicString.h" |
27 #include "wtf/text/Unicode.h" | 27 #include "wtf/text/Unicode.h" |
28 | 28 |
29 #include <unicode/brkiter.h> | 29 #include <unicode/brkiter.h> |
30 | 30 |
31 namespace blink { | 31 namespace blink { |
32 | 32 |
33 typedef icu::BreakIterator TextBreakIterator; | 33 typedef icu::BreakIterator TextBreakIterator; |
34 | 34 |
35 // Note: The returned iterator is good only until you get another iterator, with
the exception of acquireLineBreakIterator. | 35 // Note: The returned iterator is good only until you get another iterator, with |
| 36 // the exception of acquireLineBreakIterator. |
36 | 37 |
37 // This is similar to character break iterator in most cases, but is subject to | 38 // This is similar to character break iterator in most cases, but is subject to |
38 // platform UI conventions. One notable example where this can be different | 39 // platform UI conventions. One notable example where this can be different |
39 // from character break iterator is Thai prepend characters, see bug 24342. | 40 // from character break iterator is Thai prepend characters, see bug 24342. |
40 // Use this for insertion point and selection manipulations. | 41 // Use this for insertion point and selection manipulations. |
41 PLATFORM_EXPORT TextBreakIterator* cursorMovementIterator(const UChar*, | 42 PLATFORM_EXPORT TextBreakIterator* cursorMovementIterator(const UChar*, |
42 int length); | 43 int length); |
43 | 44 |
44 PLATFORM_EXPORT TextBreakIterator* wordBreakIterator(const String&, | 45 PLATFORM_EXPORT TextBreakIterator* wordBreakIterator(const String&, |
45 int start, | 46 int start, |
(...skipping 15 matching lines...) Expand all Loading... |
61 PLATFORM_EXPORT TextBreakIterator* sentenceBreakIterator(const UChar*, | 62 PLATFORM_EXPORT TextBreakIterator* sentenceBreakIterator(const UChar*, |
62 int length); | 63 int length); |
63 | 64 |
64 PLATFORM_EXPORT bool isWordTextBreak(TextBreakIterator*); | 65 PLATFORM_EXPORT bool isWordTextBreak(TextBreakIterator*); |
65 | 66 |
66 const int TextBreakDone = -1; | 67 const int TextBreakDone = -1; |
67 | 68 |
68 enum class LineBreakType { | 69 enum class LineBreakType { |
69 Normal, | 70 Normal, |
70 BreakAll, // word-break:break-all allows breaks between letters/numbers | 71 BreakAll, // word-break:break-all allows breaks between letters/numbers |
71 KeepAll, // word-break:keep-all doesn't allow breaks between all kind of let
ters/numbers except some south east asians'. | 72 KeepAll, // word-break:keep-all doesn't allow breaks between all kind of |
| 73 // letters/numbers except some south east asians'. |
72 }; | 74 }; |
73 | 75 |
74 class PLATFORM_EXPORT LazyLineBreakIterator final { | 76 class PLATFORM_EXPORT LazyLineBreakIterator final { |
75 STACK_ALLOCATED(); | 77 STACK_ALLOCATED(); |
76 | 78 |
77 public: | 79 public: |
78 LazyLineBreakIterator() | 80 LazyLineBreakIterator() |
79 : m_iterator(0), m_cachedPriorContext(0), m_cachedPriorContextLength(0) { | 81 : m_iterator(0), m_cachedPriorContext(0), m_cachedPriorContextLength(0) { |
80 resetPriorContext(); | 82 resetPriorContext(); |
81 } | 83 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 static_assert(WTF_ARRAY_LENGTH(m_priorContext) == 2, | 137 static_assert(WTF_ARRAY_LENGTH(m_priorContext) == 2, |
136 "TextBreakIterator has unexpected prior context length"); | 138 "TextBreakIterator has unexpected prior context length"); |
137 if (m_priorContext[1]) { | 139 if (m_priorContext[1]) { |
138 ++priorContextLength; | 140 ++priorContextLength; |
139 if (m_priorContext[0]) | 141 if (m_priorContext[0]) |
140 ++priorContextLength; | 142 ++priorContextLength; |
141 } | 143 } |
142 return priorContextLength; | 144 return priorContextLength; |
143 } | 145 } |
144 | 146 |
145 // Obtain text break iterator, possibly previously cached, where this iterator
is (or has been) | 147 // Obtain text break iterator, possibly previously cached, where this iterator |
146 // initialized to use the previously stored string as the primary breaking con
text and using | 148 // is (or has been) initialized to use the previously stored string as the |
147 // previously stored prior context if non-empty. | 149 // primary breaking context and using previously stored prior context if |
| 150 // non-empty. |
148 TextBreakIterator* get(unsigned priorContextLength) { | 151 TextBreakIterator* get(unsigned priorContextLength) { |
149 ASSERT(priorContextLength <= priorContextCapacity); | 152 ASSERT(priorContextLength <= priorContextCapacity); |
150 const UChar* priorContext = | 153 const UChar* priorContext = |
151 priorContextLength | 154 priorContextLength |
152 ? &m_priorContext[priorContextCapacity - priorContextLength] | 155 ? &m_priorContext[priorContextCapacity - priorContextLength] |
153 : 0; | 156 : 0; |
154 if (!m_iterator) { | 157 if (!m_iterator) { |
155 if (m_string.is8Bit()) | 158 if (m_string.is8Bit()) |
156 m_iterator = acquireLineBreakIterator(m_string.characters8(), | 159 m_iterator = acquireLineBreakIterator(m_string.characters8(), |
157 m_string.length(), m_locale, | 160 m_string.length(), m_locale, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 static const unsigned priorContextCapacity = 2; | 211 static const unsigned priorContextCapacity = 2; |
209 String m_string; | 212 String m_string; |
210 AtomicString m_locale; | 213 AtomicString m_locale; |
211 TextBreakIterator* m_iterator; | 214 TextBreakIterator* m_iterator; |
212 UChar m_priorContext[priorContextCapacity]; | 215 UChar m_priorContext[priorContextCapacity]; |
213 const UChar* m_cachedPriorContext; | 216 const UChar* m_cachedPriorContext; |
214 unsigned m_cachedPriorContextLength; | 217 unsigned m_cachedPriorContextLength; |
215 }; | 218 }; |
216 | 219 |
217 // Iterates over "extended grapheme clusters", as defined in UAX #29. | 220 // Iterates over "extended grapheme clusters", as defined in UAX #29. |
218 // Note that platform implementations may be less sophisticated - e.g. ICU prior
to | 221 // Note that platform implementations may be less sophisticated - e.g. ICU prior |
219 // version 4.0 only supports "legacy grapheme clusters". | 222 // to version 4.0 only supports "legacy grapheme clusters". Use this for |
220 // Use this for general text processing, e.g. string truncation. | 223 // general text processing, e.g. string truncation. |
221 | 224 |
222 class PLATFORM_EXPORT NonSharedCharacterBreakIterator final { | 225 class PLATFORM_EXPORT NonSharedCharacterBreakIterator final { |
223 STACK_ALLOCATED(); | 226 STACK_ALLOCATED(); |
224 WTF_MAKE_NONCOPYABLE(NonSharedCharacterBreakIterator); | 227 WTF_MAKE_NONCOPYABLE(NonSharedCharacterBreakIterator); |
225 | 228 |
226 public: | 229 public: |
227 explicit NonSharedCharacterBreakIterator(const String&); | 230 explicit NonSharedCharacterBreakIterator(const String&); |
228 NonSharedCharacterBreakIterator(const UChar*, unsigned length); | 231 NonSharedCharacterBreakIterator(const UChar*, unsigned length); |
229 ~NonSharedCharacterBreakIterator(); | 232 ~NonSharedCharacterBreakIterator(); |
230 | 233 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 }; | 273 }; |
271 | 274 |
272 // Counts the number of grapheme clusters. A surrogate pair or a sequence | 275 // Counts the number of grapheme clusters. A surrogate pair or a sequence |
273 // of a non-combining character and following combining characters is | 276 // of a non-combining character and following combining characters is |
274 // counted as 1 grapheme cluster. | 277 // counted as 1 grapheme cluster. |
275 PLATFORM_EXPORT unsigned numGraphemeClusters(const String&); | 278 PLATFORM_EXPORT unsigned numGraphemeClusters(const String&); |
276 | 279 |
277 } // namespace blink | 280 } // namespace blink |
278 | 281 |
279 #endif | 282 #endif |
OLD | NEW |