| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 ++prior_context_length; | 144 ++prior_context_length; |
| 145 } | 145 } |
| 146 return prior_context_length; | 146 return prior_context_length; |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Obtain text break iterator, possibly previously cached, where this iterator | 149 // Obtain text break iterator, possibly previously cached, where this iterator |
| 150 // is (or has been) initialized to use the previously stored string as the | 150 // is (or has been) initialized to use the previously stored string as the |
| 151 // primary breaking context and using previously stored prior context if | 151 // primary breaking context and using previously stored prior context if |
| 152 // non-empty. | 152 // non-empty. |
| 153 TextBreakIterator* Get(unsigned prior_context_length) { | 153 TextBreakIterator* Get(unsigned prior_context_length) { |
| 154 ASSERT(prior_context_length <= kPriorContextCapacity); | 154 DCHECK(prior_context_length <= kPriorContextCapacity); |
| 155 const UChar* prior_context = | 155 const UChar* prior_context = |
| 156 prior_context_length | 156 prior_context_length |
| 157 ? &prior_context_[kPriorContextCapacity - prior_context_length] | 157 ? &prior_context_[kPriorContextCapacity - prior_context_length] |
| 158 : 0; | 158 : 0; |
| 159 if (!iterator_) { | 159 if (!iterator_) { |
| 160 if (string_.Is8Bit()) | 160 if (string_.Is8Bit()) |
| 161 iterator_ = AcquireLineBreakIterator( | 161 iterator_ = AcquireLineBreakIterator( |
| 162 string_.Characters8(), string_.length(), locale_, prior_context, | 162 string_.Characters8(), string_.length(), locale_, prior_context, |
| 163 prior_context_length); | 163 prior_context_length); |
| 164 else | 164 else |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 bool IsBreak(int offset) const; | 240 bool IsBreak(int offset) const; |
| 241 int Preceding(int offset) const; | 241 int Preceding(int offset) const; |
| 242 int Following(int offset) const; | 242 int Following(int offset) const; |
| 243 | 243 |
| 244 bool operator!() const { return !is8_bit_ && !iterator_; } | 244 bool operator!() const { return !is8_bit_ && !iterator_; } |
| 245 | 245 |
| 246 private: | 246 private: |
| 247 void CreateIteratorForBuffer(const UChar*, unsigned length); | 247 void CreateIteratorForBuffer(const UChar*, unsigned length); |
| 248 | 248 |
| 249 unsigned ClusterLengthStartingAt(unsigned offset) const { | 249 unsigned ClusterLengthStartingAt(unsigned offset) const { |
| 250 ASSERT(is8_bit_); | 250 DCHECK(is8_bit_); |
| 251 // The only Latin-1 Extended Grapheme Cluster is CR LF | 251 // The only Latin-1 Extended Grapheme Cluster is CR LF |
| 252 return IsCRBeforeLF(offset) ? 2 : 1; | 252 return IsCRBeforeLF(offset) ? 2 : 1; |
| 253 } | 253 } |
| 254 | 254 |
| 255 bool IsCRBeforeLF(unsigned offset) const { | 255 bool IsCRBeforeLF(unsigned offset) const { |
| 256 ASSERT(is8_bit_); | 256 DCHECK(is8_bit_); |
| 257 return charaters8_[offset] == '\r' && offset + 1 < length_ && | 257 return charaters8_[offset] == '\r' && offset + 1 < length_ && |
| 258 charaters8_[offset + 1] == '\n'; | 258 charaters8_[offset + 1] == '\n'; |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool IsLFAfterCR(unsigned offset) const { | 261 bool IsLFAfterCR(unsigned offset) const { |
| 262 ASSERT(is8_bit_); | 262 DCHECK(is8_bit_); |
| 263 return charaters8_[offset] == '\n' && offset >= 1 && | 263 return charaters8_[offset] == '\n' && offset >= 1 && |
| 264 charaters8_[offset - 1] == '\r'; | 264 charaters8_[offset - 1] == '\r'; |
| 265 } | 265 } |
| 266 | 266 |
| 267 bool is8_bit_; | 267 bool is8_bit_; |
| 268 | 268 |
| 269 // For 8 bit strings, we implement the iterator ourselves. | 269 // For 8 bit strings, we implement the iterator ourselves. |
| 270 const LChar* charaters8_; | 270 const LChar* charaters8_; |
| 271 unsigned offset_; | 271 unsigned offset_; |
| 272 unsigned length_; | 272 unsigned length_; |
| 273 | 273 |
| 274 // For 16 bit strings, we use a TextBreakIterator. | 274 // For 16 bit strings, we use a TextBreakIterator. |
| 275 TextBreakIterator* iterator_; | 275 TextBreakIterator* iterator_; |
| 276 }; | 276 }; |
| 277 | 277 |
| 278 // Counts the number of grapheme clusters. A surrogate pair or a sequence | 278 // Counts the number of grapheme clusters. A surrogate pair or a sequence |
| 279 // of a non-combining character and following combining characters is | 279 // of a non-combining character and following combining characters is |
| 280 // counted as 1 grapheme cluster. | 280 // counted as 1 grapheme cluster. |
| 281 PLATFORM_EXPORT unsigned NumGraphemeClusters(const String&); | 281 PLATFORM_EXPORT unsigned NumGraphemeClusters(const String&); |
| 282 | 282 |
| 283 } // namespace blink | 283 } // namespace blink |
| 284 | 284 |
| 285 #endif | 285 #endif |
| OLD | NEW |