@@ -76,16 +76,17 @@ class Breaks {
7676 void step () {
7777 assert (cursor < end);
7878 var char = base .codeUnitAt (cursor++ );
79- if (char & 0xFC00 != 0xD800 ) {
79+ var surrogate = char ^ 0xD800 ;
80+ if (surrogate >= 0x3FF ) {
8081 state = move (state, low (char));
8182 return ;
8283 }
8384 // The category of an unpaired lead surrogate is Control.
8485 int category;
85- int nextChar ;
86+ int nextSurrogate ;
8687 if (cursor < end &&
87- (nextChar = base .codeUnitAt (cursor)) & 0xFC00 == 0xDC00 ) {
88- category = high (char, nextChar );
88+ (nextSurrogate = base .codeUnitAt (cursor) ^ 0xDC00 ) <= 0x3FF ) {
89+ category = high (surrogate, nextSurrogate );
8990 cursor++ ;
9091 } else {
9192 category = categoryControl;
@@ -112,27 +113,28 @@ class Breaks {
112113 }
113114 var cursorBefore = cursor - 1 ;
114115 var prevChar = base .codeUnitAt (cursorBefore);
116+ var prevSurrogate = prevChar ^ 0xD800 ;
115117 int prevCategory;
116- if (prevChar & 0xF800 != 0xD800 ) {
118+ if (prevSurrogate > 0x7FF ) {
117119 // Not surrogate.
118120 prevCategory = low (prevChar);
119- } else if (prevChar & 0xFC00 == 0xD800 ) {
121+ } else if (prevSurrogate <= 0x3FF ) {
120122 // Lead surrogate. Check for a following tail surrogate.
121- int tailChar ;
123+ int tailSurrogate ;
122124 if (cursor < end &&
123- (tailChar = base .codeUnitAt (cursor)) & 0xFC00 == 0xDC00 ) {
125+ (tailSurrogate = base .codeUnitAt (cursor) ^ 0xDC00 ) <= 0x3FF ) {
124126 cursor += 1 ;
125- prevCategory = high (prevChar, tailChar );
127+ prevCategory = high (prevSurrogate, tailSurrogate );
126128 } else {
127129 prevCategory = categoryControl;
128130 }
129131 } else {
130132 // Tail surrogate, check for prior lead surrogate.
131- int leadChar ;
133+ int leadSurrogate ;
132134 var leadIndex = cursorBefore - 1 ;
133135 if (leadIndex >= start &&
134- (leadChar = base .codeUnitAt (leadIndex)) & 0xFC00 == 0xD800 ) {
135- prevCategory = high (leadChar, prevChar );
136+ (leadSurrogate = base .codeUnitAt (leadIndex) ^ 0xD800 ) <= 0x3FF ) {
137+ prevCategory = high (leadSurrogate, prevSurrogate );
136138 cursorBefore = leadIndex;
137139 } else {
138140 prevCategory = categoryControl;
@@ -206,18 +208,19 @@ class BackBreaks {
206208 void step () {
207209 assert (cursor > start);
208210 var char = base .codeUnitAt (-- cursor);
209- if (char & 0xFC00 != 0xDC00 ) {
211+ var surrogate = char ^ 0xDC00 ;
212+ if (surrogate > 0x3FF ) {
210213 var category = low (char);
211214 state = moveBack (state, category);
212215 return ;
213216 }
214217 // Found tail surrogate, check for prior lead surrogate.
215218 // The category of an unpaired tail surrogate is Control.
216219 int category;
217- int prevChar ;
220+ int prevSurrogate ;
218221 if (cursor >= start &&
219- (prevChar = base .codeUnitAt (-- cursor)) & 0xFC00 == 0xD800 ) {
220- category = high (prevChar, char );
222+ (prevSurrogate = base .codeUnitAt (-- cursor) ^ 0xD800 ) <= 0x3FF ) {
223+ category = high (prevSurrogate, surrogate );
221224 } else {
222225 category = categoryControl;
223226 cursor++ ;
@@ -342,21 +345,23 @@ int previousBreak(String text, int start, int end, int index) {
342345 if (start < index && index < end) {
343346 var cursorBefore = index;
344347 var nextChar = text.codeUnitAt (index);
348+ var nextSurrogate = nextChar ^ 0xD800 ;
345349 var category = categoryControl;
346- if (nextChar & 0xF800 != 0xD800 ) {
350+ if (nextSurrogate > 0x7FF ) {
347351 category = low (nextChar);
348- } else if (nextChar & 0xFC00 == 0xD800 ) {
352+ } else if (nextSurrogate <= 0x3FF ) {
349353 var indexAfter = index + 1 ;
350354 if (indexAfter < end) {
351- var secondChar = text.codeUnitAt (indexAfter);
352- if (secondChar & 0xFC00 == 0xDC00 ) {
353- category = high (nextChar, secondChar );
355+ var secondSurrogate = text.codeUnitAt (indexAfter) ^ 0xDC00 ;
356+ if (secondSurrogate <= 0x3FF ) {
357+ category = high (nextChar, secondSurrogate );
354358 }
355359 }
356360 } else {
357- var prevChar = text.codeUnitAt (index - 1 );
358- if (prevChar & 0xFC00 == 0xD800 ) {
359- category = high (prevChar, nextChar);
361+ var prevSurrogate = text.codeUnitAt (index - 1 ) ^ 0xD800 ;
362+ nextSurrogate & = 0x3FF ;
363+ if (prevSurrogate <= 0x3FF ) {
364+ category = high (prevSurrogate, nextSurrogate);
360365 cursorBefore -= 1 ;
361366 }
362367 }
0 commit comments