Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2381)

Unified Diff: Source/platform/text/BidiResolver.h

Issue 83443002: Handle surrogates in BidiResolver::determineParagraphDirectionality (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix scoping of String in unittest; rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/platform/text/BidiResolverTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/text/BidiResolver.h
diff --git a/Source/platform/text/BidiResolver.h b/Source/platform/text/BidiResolver.h
index 97d3ad496f3362ce5ad5805fc17bb2b91e2be225..64c7bb1f4c9a007898b44445523619111818df41 100644
--- a/Source/platform/text/BidiResolver.h
+++ b/Source/platform/text/BidiResolver.h
@@ -548,18 +548,31 @@ TextDirection BidiResolver<Iterator, Run>::determineParagraphDirectionality(bool
}
if (m_current.atParagraphSeparator())
break;
- if (UChar current = m_current.current()) {
- WTF::Unicode::Direction charDirection = WTF::Unicode::direction(current);
- if (charDirection == WTF::Unicode::LeftToRight) {
- if (hasStrongDirectionality)
- *hasStrongDirectionality = true;
- return LTR;
- }
- if (charDirection == WTF::Unicode::RightToLeft || charDirection == WTF::Unicode::RightToLeftArabic) {
- if (hasStrongDirectionality)
- *hasStrongDirectionality = true;
- return RTL;
- }
+ UChar32 current = m_current.current();
+ if (UNLIKELY(U16_IS_SURROGATE(current))) {
+ increment();
+ // If this not the high part of the surrogate pair, then drop it and move to the next.
+ if (!U16_IS_SURROGATE_LEAD(current))
+ continue;
+ UChar high = static_cast<UChar>(current);
+ if (m_current.atEnd())
+ continue;
+ UChar low = m_current.current();
+ // Verify the low part. If invalid, then assume an invalid surrogate pair and retry.
+ if (!U16_IS_TRAIL(low))
+ continue;
+ current = U16_GET_SUPPLEMENTARY(high, low);
+ }
+ WTF::Unicode::Direction charDirection = WTF::Unicode::direction(current);
+ if (charDirection == WTF::Unicode::LeftToRight) {
+ if (hasStrongDirectionality)
+ *hasStrongDirectionality = true;
+ return LTR;
+ }
+ if (charDirection == WTF::Unicode::RightToLeft || charDirection == WTF::Unicode::RightToLeftArabic) {
+ if (hasStrongDirectionality)
+ *hasStrongDirectionality = true;
+ return RTL;
}
increment();
}
« no previous file with comments | « no previous file | Source/platform/text/BidiResolverTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698