| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights |
| 4 * reserved. | 4 * reserved. |
| 5 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 5 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
| 6 * Copyright (C) 2011 Google Inc. All rights reserved. | 6 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 243 } |
| 244 return false; | 244 return false; |
| 245 } | 245 } |
| 246 | 246 |
| 247 inline bool NeedsLineBreakIterator(UChar ch) { | 247 inline bool NeedsLineBreakIterator(UChar ch) { |
| 248 return ch > kAsciiLineBreakTableLastChar && ch != kNoBreakSpaceCharacter; | 248 return ch > kAsciiLineBreakTableLastChar && ch != kNoBreakSpaceCharacter; |
| 249 } | 249 } |
| 250 | 250 |
| 251 template <typename CharacterType, LineBreakType lineBreakType> | 251 template <typename CharacterType, LineBreakType lineBreakType> |
| 252 static inline int NextBreakablePosition( | 252 static inline int NextBreakablePosition( |
| 253 LazyLineBreakIterator& lazy_break_iterator, | 253 const LazyLineBreakIterator& lazy_break_iterator, |
| 254 const CharacterType* str, | 254 const CharacterType* str, |
| 255 unsigned length, | 255 unsigned length, |
| 256 int pos) { | 256 int pos) { |
| 257 int len = static_cast<int>(length); | 257 int len = static_cast<int>(length); |
| 258 int next_break = -1; | 258 int next_break = -1; |
| 259 | 259 |
| 260 UChar last_last_ch = | 260 UChar last_last_ch = |
| 261 pos > 1 ? str[pos - 2] : lazy_break_iterator.SecondToLastCharacter(); | 261 pos > 1 ? str[pos - 2] : lazy_break_iterator.SecondToLastCharacter(); |
| 262 UChar last_ch = pos > 0 ? str[pos - 1] : lazy_break_iterator.LastCharacter(); | 262 UChar last_ch = pos > 0 ? str[pos - 1] : lazy_break_iterator.LastCharacter(); |
| 263 ULineBreak last_line_break; | 263 ULineBreak last_line_break; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 307 |
| 308 static inline bool ShouldKeepAfter(UChar last_ch, UChar ch, UChar next_ch) { | 308 static inline bool ShouldKeepAfter(UChar last_ch, UChar ch, UChar next_ch) { |
| 309 UChar pre_ch = U_MASK(u_charType(ch)) & U_GC_M_MASK ? last_ch : ch; | 309 UChar pre_ch = U_MASK(u_charType(ch)) & U_GC_M_MASK ? last_ch : ch; |
| 310 return U_MASK(u_charType(pre_ch)) & (U_GC_L_MASK | U_GC_N_MASK) && | 310 return U_MASK(u_charType(pre_ch)) & (U_GC_L_MASK | U_GC_N_MASK) && |
| 311 !WTF::Unicode::HasLineBreakingPropertyComplexContext(pre_ch) && | 311 !WTF::Unicode::HasLineBreakingPropertyComplexContext(pre_ch) && |
| 312 U_MASK(u_charType(next_ch)) & (U_GC_L_MASK | U_GC_N_MASK) && | 312 U_MASK(u_charType(next_ch)) & (U_GC_L_MASK | U_GC_N_MASK) && |
| 313 !WTF::Unicode::HasLineBreakingPropertyComplexContext(next_ch); | 313 !WTF::Unicode::HasLineBreakingPropertyComplexContext(next_ch); |
| 314 } | 314 } |
| 315 | 315 |
| 316 static inline int NextBreakablePositionKeepAllInternal( | 316 static inline int NextBreakablePositionKeepAllInternal( |
| 317 LazyLineBreakIterator& lazy_break_iterator, | 317 const LazyLineBreakIterator& lazy_break_iterator, |
| 318 const UChar* str, | 318 const UChar* str, |
| 319 unsigned length, | 319 unsigned length, |
| 320 int pos) { | 320 int pos) { |
| 321 int len = static_cast<int>(length); | 321 int len = static_cast<int>(length); |
| 322 int next_break = -1; | 322 int next_break = -1; |
| 323 | 323 |
| 324 UChar last_last_ch = | 324 UChar last_last_ch = |
| 325 pos > 1 ? str[pos - 2] | 325 pos > 1 ? str[pos - 2] |
| 326 : static_cast<UChar>(lazy_break_iterator.SecondToLastCharacter()); | 326 : static_cast<UChar>(lazy_break_iterator.SecondToLastCharacter()); |
| 327 UChar last_ch = pos > 0 | 327 UChar last_ch = pos > 0 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 357 | 357 |
| 358 last_last_ch = last_ch; | 358 last_last_ch = last_ch; |
| 359 last_ch = ch; | 359 last_ch = ch; |
| 360 } | 360 } |
| 361 | 361 |
| 362 return len; | 362 return len; |
| 363 } | 363 } |
| 364 | 364 |
| 365 template <LineBreakType lineBreakType> | 365 template <LineBreakType lineBreakType> |
| 366 static inline int NextBreakablePosition( | 366 static inline int NextBreakablePosition( |
| 367 LazyLineBreakIterator& lazy_break_iterator, | 367 const LazyLineBreakIterator& lazy_break_iterator, |
| 368 const String& string, | 368 const String& string, |
| 369 int pos) { | 369 int pos) { |
| 370 if (string.Is8Bit()) | 370 if (string.Is8Bit()) |
| 371 return NextBreakablePosition<LChar, lineBreakType>( | 371 return NextBreakablePosition<LChar, lineBreakType>( |
| 372 lazy_break_iterator, string.Characters8(), string.length(), pos); | 372 lazy_break_iterator, string.Characters8(), string.length(), pos); |
| 373 return NextBreakablePosition<UChar, lineBreakType>( | 373 return NextBreakablePosition<UChar, lineBreakType>( |
| 374 lazy_break_iterator, string.Characters16(), string.length(), pos); | 374 lazy_break_iterator, string.Characters16(), string.length(), pos); |
| 375 } | 375 } |
| 376 | 376 |
| 377 int LazyLineBreakIterator::NextBreakablePositionIgnoringNBSP(int pos) { | 377 int LazyLineBreakIterator::NextBreakablePositionIgnoringNBSP(int pos) const { |
| 378 return NextBreakablePosition<LineBreakType::kNormal>(*this, string_, pos); | 378 return NextBreakablePosition<LineBreakType::kNormal>(*this, string_, pos); |
| 379 } | 379 } |
| 380 | 380 |
| 381 int LazyLineBreakIterator::NextBreakablePositionBreakAll(int pos) { | 381 int LazyLineBreakIterator::NextBreakablePositionBreakAll(int pos) const { |
| 382 return NextBreakablePosition<LineBreakType::kBreakAll>(*this, string_, pos); | 382 return NextBreakablePosition<LineBreakType::kBreakAll>(*this, string_, pos); |
| 383 } | 383 } |
| 384 | 384 |
| 385 int LazyLineBreakIterator::NextBreakablePositionKeepAll(int pos) { | 385 int LazyLineBreakIterator::NextBreakablePositionKeepAll(int pos) const { |
| 386 if (string_.Is8Bit()) | 386 if (string_.Is8Bit()) |
| 387 return NextBreakablePosition<LChar, LineBreakType::kNormal>( | 387 return NextBreakablePosition<LChar, LineBreakType::kNormal>( |
| 388 *this, string_.Characters8(), string_.length(), pos); | 388 *this, string_.Characters8(), string_.length(), pos); |
| 389 return NextBreakablePositionKeepAllInternal(*this, string_.Characters16(), | 389 return NextBreakablePositionKeepAllInternal(*this, string_.Characters16(), |
| 390 string_.length(), pos); | 390 string_.length(), pos); |
| 391 } | 391 } |
| 392 | 392 |
| 393 unsigned LazyLineBreakIterator::NextBreakOpportunity(unsigned offset) const { |
| 394 int next_break = 0; |
| 395 IsBreakable(offset, next_break); |
| 396 return next_break; |
| 397 } |
| 398 |
| 399 unsigned LazyLineBreakIterator::PreviousBreakOpportunity(unsigned offset, |
| 400 unsigned min) const { |
| 401 unsigned pos = std::min(offset, string_.length()); |
| 402 for (; pos > min; pos--) { |
| 403 int next_break = 0; |
| 404 if (IsBreakable(pos, next_break)) |
| 405 return pos; |
| 406 } |
| 407 return min; |
| 408 } |
| 409 |
| 393 } // namespace blink | 410 } // namespace blink |
| OLD | NEW |