Chromium Code Reviews| 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 reserv ed. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed. |
| 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
| 5 * Copyright (C) 2011 Google Inc. All rights reserved. | 5 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 return i > pos && U16_IS_TRAIL(ch) ? i - 1 : i; | 218 return i > pos && U16_IS_TRAIL(ch) ? i - 1 : i; |
| 219 lastIsLetterOrNumber = isLetterOrNumber; | 219 lastIsLetterOrNumber = isLetterOrNumber; |
| 220 } | 220 } |
| 221 | 221 |
| 222 lastLastCh = lastCh; | 222 lastLastCh = lastCh; |
| 223 lastCh = ch; | 223 lastCh = ch; |
| 224 } | 224 } |
| 225 return len; | 225 return len; |
| 226 } | 226 } |
| 227 | 227 |
| 228 static inline bool isComplexContextDependent(UChar ch) | |
|
jungshik at Google
2015/04/23 20:34:15
Please, use either requiresContextForWordBoundary
yunsik
2015/04/24 07:01:15
Yes you're right. they seem to be better to use. I
| |
| 229 { | |
| 230 switch (ublock_getCode(ch)) { | |
| 231 case UBLOCK_THAI: | |
| 232 case UBLOCK_LAO: | |
| 233 case UBLOCK_MYANMAR: | |
| 234 case UBLOCK_KHMER: | |
| 235 case UBLOCK_TAI_LE: | |
| 236 case UBLOCK_NEW_TAI_LUE: | |
| 237 case UBLOCK_TAI_THAM: | |
| 238 case UBLOCK_MYANMAR_EXTENDED_A: | |
| 239 case UBLOCK_TAI_VIET: | |
| 240 return true; | |
| 241 default: | |
| 242 return false; | |
| 243 } | |
| 244 } | |
| 245 | |
| 246 static inline bool shouldKeepAfter(UChar lastCh, UChar ch, UChar nextCh) | |
| 247 { | |
| 248 UChar preCh = U_MASK(u_charType(ch)) & U_GC_M_MASK ? lastCh : ch; | |
| 249 return U_MASK(u_charType(preCh)) & (U_GC_L_MASK | U_GC_N_MASK) | |
| 250 && !isComplexContextDependent(preCh) | |
| 251 && U_MASK(u_charType(nextCh)) & (U_GC_L_MASK | U_GC_N_MASK) | |
| 252 && !isComplexContextDependent(nextCh); | |
| 253 } | |
| 254 | |
| 255 static inline int nextBreakablePositionKeepAllInternal(LazyLineBreakIterator& la zyBreakIterator, const UChar* str, unsigned length, int pos) | |
| 256 { | |
| 257 int len = static_cast<int>(length); | |
| 258 int nextBreak = -1; | |
| 259 | |
| 260 UChar lastLastCh = pos > 1 ? str[pos - 2] : static_cast<UChar>(lazyBreakIter ator.secondToLastCharacter()); | |
| 261 UChar lastCh = pos > 0 ? str[pos - 1] : static_cast<UChar>(lazyBreakIterator .lastCharacter()); | |
| 262 unsigned priorContextLength = lazyBreakIterator.priorContextLength(); | |
| 263 for (int i = pos; i < len; i++) { | |
| 264 UChar ch = str[i]; | |
| 265 | |
| 266 if (isBreakableSpace(ch) || shouldBreakAfter(lastLastCh, lastCh, ch)) | |
| 267 return i; | |
| 268 | |
| 269 if (!shouldKeepAfter(lastLastCh, lastCh, ch) && (needsLineBreakIterator( ch) || needsLineBreakIterator(lastCh))) { | |
| 270 if (nextBreak < i) { | |
| 271 // Don't break if positioned at start of primary context and the re is no prior context. | |
| 272 if (i || priorContextLength) { | |
| 273 TextBreakIterator* breakIterator = lazyBreakIterator.get(pri orContextLength); | |
| 274 if (breakIterator) { | |
| 275 nextBreak = breakIterator->following(i - 1 + priorContex tLength); | |
| 276 if (nextBreak >= 0) { | |
| 277 nextBreak -= priorContextLength; | |
| 278 } | |
| 279 } | |
| 280 } | |
| 281 } | |
| 282 if (i == nextBreak && !isBreakableSpace(lastCh)) | |
| 283 return i; | |
| 284 } | |
| 285 | |
| 286 lastLastCh = lastCh; | |
| 287 lastCh = ch; | |
| 288 } | |
| 289 | |
| 290 return len; | |
| 291 } | |
| 292 | |
| 228 int LazyLineBreakIterator::nextBreakablePositionIgnoringNBSP(int pos) | 293 int LazyLineBreakIterator::nextBreakablePositionIgnoringNBSP(int pos) |
| 229 { | 294 { |
| 230 if (m_string.is8Bit()) | 295 if (m_string.is8Bit()) |
| 231 return nextBreakablePosition<LChar>(*this, m_string.characters8(), m_str ing.length(), pos); | 296 return nextBreakablePosition<LChar>(*this, m_string.characters8(), m_str ing.length(), pos); |
| 232 return nextBreakablePosition<UChar>(*this, m_string.characters16(), m_string .length(), pos); | 297 return nextBreakablePosition<UChar>(*this, m_string.characters16(), m_string .length(), pos); |
| 233 } | 298 } |
| 234 | 299 |
| 235 int LazyLineBreakIterator::nextBreakablePositionBreakAll(int pos) | 300 int LazyLineBreakIterator::nextBreakablePositionBreakAll(int pos) |
| 236 { | 301 { |
| 237 if (m_string.is8Bit()) | 302 if (m_string.is8Bit()) |
| 238 return nextBreakablePositionBreakAllInternal<LChar>(*this, m_string.char acters8(), m_string.length(), pos); | 303 return nextBreakablePositionBreakAllInternal<LChar>(*this, m_string.char acters8(), m_string.length(), pos); |
| 239 return nextBreakablePositionBreakAllInternal<UChar>(*this, m_string.characte rs16(), m_string.length(), pos); | 304 return nextBreakablePositionBreakAllInternal<UChar>(*this, m_string.characte rs16(), m_string.length(), pos); |
| 240 } | 305 } |
| 241 | 306 |
| 307 int LazyLineBreakIterator::nextBreakablePositionKeepAll(int pos) | |
| 308 { | |
| 309 if (m_string.is8Bit()) | |
| 310 return nextBreakablePosition<LChar>(*this, m_string.characters8(), m_str ing.length(), pos); | |
| 311 return nextBreakablePositionKeepAllInternal(*this, m_string.characters16(), m_string.length(), pos); | |
| 312 } | |
| 242 | 313 |
| 243 } // namespace blink | 314 } // namespace blink |
| OLD | NEW |