@@ -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++ ;
@@ -339,21 +342,23 @@ int previousBreak(String text, int start, int end, int index) {
339342  if  (start <  index &&  index <  end) {
340343    var  cursorBefore =  index;
341344    var  nextChar =  text.codeUnitAt (index);
345+     var  nextSurrogate =  nextChar ^  0xD800 ;
342346    var  category =  categoryControl;
343-     if  (nextChar  &   0xF800   !=   0xD800 ) {
347+     if  (nextSurrogate  >   0x7FF ) {
344348      category =  low (nextChar);
345-     } else  if  (nextChar  &   0xFC00   ==   0xD800 ) {
349+     } else  if  (nextSurrogate  <=   0x3FF ) {
346350      var  indexAfter =  index +  1 ;
347351      if  (indexAfter <  end) {
348-         var  secondChar  =  text.codeUnitAt (indexAfter);
349-         if  (secondChar  &   0xFC00   ==   0xDC00 ) {
350-           category =  high (nextChar, secondChar );
352+         var  secondSurrogate  =  text.codeUnitAt (indexAfter)  ^   0xDC00 ;
353+         if  (secondSurrogate  <=   0x3FF ) {
354+           category =  high (nextChar, secondSurrogate );
351355        }
352356      }
353357    } else  {
354-       var  prevChar =  text.codeUnitAt (index -  1 );
355-       if  (prevChar &  0xFC00  ==  0xD800 ) {
356-         category =  high (prevChar, nextChar);
358+       var  prevSurrogate =  text.codeUnitAt (index -  1 ) ^  0xD800 ;
359+       nextSurrogate & =  0x3FF ;
360+       if  (prevSurrogate <=  0x3FF ) {
361+         category =  high (prevSurrogate, nextSurrogate);
357362        cursorBefore -=  1 ;
358363      }
359364    }
0 commit comments