Index: Source/platform/text/TextBreakIterator.cpp |
diff --git a/Source/platform/text/TextBreakIterator.cpp b/Source/platform/text/TextBreakIterator.cpp |
index 53615486152a0635817b2a9629fc559783d8165a..61275eb358b70821ac11ab6b2f114e28b28bc9e6 100644 |
--- a/Source/platform/text/TextBreakIterator.cpp |
+++ b/Source/platform/text/TextBreakIterator.cpp |
@@ -225,6 +225,71 @@ static inline int nextBreakablePositionBreakAllInternal(LazyLineBreakIterator& l |
return len; |
} |
+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
|
+{ |
+ switch (ublock_getCode(ch)) { |
+ case UBLOCK_THAI: |
+ case UBLOCK_LAO: |
+ case UBLOCK_MYANMAR: |
+ case UBLOCK_KHMER: |
+ case UBLOCK_TAI_LE: |
+ case UBLOCK_NEW_TAI_LUE: |
+ case UBLOCK_TAI_THAM: |
+ case UBLOCK_MYANMAR_EXTENDED_A: |
+ case UBLOCK_TAI_VIET: |
+ return true; |
+ default: |
+ return false; |
+ } |
+} |
+ |
+static inline bool shouldKeepAfter(UChar lastCh, UChar ch, UChar nextCh) |
+{ |
+ UChar preCh = U_MASK(u_charType(ch)) & U_GC_M_MASK ? lastCh : ch; |
+ return U_MASK(u_charType(preCh)) & (U_GC_L_MASK | U_GC_N_MASK) |
+ && !isComplexContextDependent(preCh) |
+ && U_MASK(u_charType(nextCh)) & (U_GC_L_MASK | U_GC_N_MASK) |
+ && !isComplexContextDependent(nextCh); |
+} |
+ |
+static inline int nextBreakablePositionKeepAllInternal(LazyLineBreakIterator& lazyBreakIterator, const UChar* str, unsigned length, int pos) |
+{ |
+ int len = static_cast<int>(length); |
+ int nextBreak = -1; |
+ |
+ UChar lastLastCh = pos > 1 ? str[pos - 2] : static_cast<UChar>(lazyBreakIterator.secondToLastCharacter()); |
+ UChar lastCh = pos > 0 ? str[pos - 1] : static_cast<UChar>(lazyBreakIterator.lastCharacter()); |
+ unsigned priorContextLength = lazyBreakIterator.priorContextLength(); |
+ for (int i = pos; i < len; i++) { |
+ UChar ch = str[i]; |
+ |
+ if (isBreakableSpace(ch) || shouldBreakAfter(lastLastCh, lastCh, ch)) |
+ return i; |
+ |
+ if (!shouldKeepAfter(lastLastCh, lastCh, ch) && (needsLineBreakIterator(ch) || needsLineBreakIterator(lastCh))) { |
+ if (nextBreak < i) { |
+ // Don't break if positioned at start of primary context and there is no prior context. |
+ if (i || priorContextLength) { |
+ TextBreakIterator* breakIterator = lazyBreakIterator.get(priorContextLength); |
+ if (breakIterator) { |
+ nextBreak = breakIterator->following(i - 1 + priorContextLength); |
+ if (nextBreak >= 0) { |
+ nextBreak -= priorContextLength; |
+ } |
+ } |
+ } |
+ } |
+ if (i == nextBreak && !isBreakableSpace(lastCh)) |
+ return i; |
+ } |
+ |
+ lastLastCh = lastCh; |
+ lastCh = ch; |
+ } |
+ |
+ return len; |
+} |
+ |
int LazyLineBreakIterator::nextBreakablePositionIgnoringNBSP(int pos) |
{ |
if (m_string.is8Bit()) |
@@ -239,5 +304,11 @@ int LazyLineBreakIterator::nextBreakablePositionBreakAll(int pos) |
return nextBreakablePositionBreakAllInternal<UChar>(*this, m_string.characters16(), m_string.length(), pos); |
} |
+int LazyLineBreakIterator::nextBreakablePositionKeepAll(int pos) |
+{ |
+ if (m_string.is8Bit()) |
+ return nextBreakablePosition<LChar>(*this, m_string.characters8(), m_string.length(), pos); |
+ return nextBreakablePositionKeepAllInternal(*this, m_string.characters16(), m_string.length(), pos); |
+} |
} // namespace blink |