@@ -76,16 +76,17 @@ class Breaks {
76
76
void step () {
77
77
assert (cursor < end);
78
78
var char = base .codeUnitAt (cursor++ );
79
- if (char & 0xFC00 != 0xD800 ) {
79
+ var surrogate = char ^ 0xD800 ;
80
+ if (surrogate >= 0x3FF ) {
80
81
state = move (state, low (char));
81
82
return ;
82
83
}
83
84
// The category of an unpaired lead surrogate is Control.
84
85
int category;
85
- int nextChar ;
86
+ int nextSurrogate ;
86
87
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 );
89
90
cursor++ ;
90
91
} else {
91
92
category = categoryControl;
@@ -112,27 +113,28 @@ class Breaks {
112
113
}
113
114
var cursorBefore = cursor - 1 ;
114
115
var prevChar = base .codeUnitAt (cursorBefore);
116
+ var prevSurrogate = prevChar ^ 0xD800 ;
115
117
int prevCategory;
116
- if (prevChar & 0xF800 != 0xD800 ) {
118
+ if (prevSurrogate > 0x7FF ) {
117
119
// Not surrogate.
118
120
prevCategory = low (prevChar);
119
- } else if (prevChar & 0xFC00 == 0xD800 ) {
121
+ } else if (prevSurrogate <= 0x3FF ) {
120
122
// Lead surrogate. Check for a following tail surrogate.
121
- int tailChar ;
123
+ int tailSurrogate ;
122
124
if (cursor < end &&
123
- (tailChar = base .codeUnitAt (cursor)) & 0xFC00 == 0xDC00 ) {
125
+ (tailSurrogate = base .codeUnitAt (cursor) ^ 0xDC00 ) <= 0x3FF ) {
124
126
cursor += 1 ;
125
- prevCategory = high (prevChar, tailChar );
127
+ prevCategory = high (prevSurrogate, tailSurrogate );
126
128
} else {
127
129
prevCategory = categoryControl;
128
130
}
129
131
} else {
130
132
// Tail surrogate, check for prior lead surrogate.
131
- int leadChar ;
133
+ int leadSurrogate ;
132
134
var leadIndex = cursorBefore - 1 ;
133
135
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 );
136
138
cursorBefore = leadIndex;
137
139
} else {
138
140
prevCategory = categoryControl;
@@ -206,18 +208,19 @@ class BackBreaks {
206
208
void step () {
207
209
assert (cursor > start);
208
210
var char = base .codeUnitAt (-- cursor);
209
- if (char & 0xFC00 != 0xDC00 ) {
211
+ var surrogate = char ^ 0xDC00 ;
212
+ if (surrogate > 0x3FF ) {
210
213
var category = low (char);
211
214
state = moveBack (state, category);
212
215
return ;
213
216
}
214
217
// Found tail surrogate, check for prior lead surrogate.
215
218
// The category of an unpaired tail surrogate is Control.
216
219
int category;
217
- int prevChar ;
220
+ int prevSurrogate ;
218
221
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 );
221
224
} else {
222
225
category = categoryControl;
223
226
cursor++ ;
@@ -339,21 +342,23 @@ int previousBreak(String text, int start, int end, int index) {
339
342
if (start < index && index < end) {
340
343
var cursorBefore = index;
341
344
var nextChar = text.codeUnitAt (index);
345
+ var nextSurrogate = nextChar ^ 0xD800 ;
342
346
var category = categoryControl;
343
- if (nextChar & 0xF800 != 0xD800 ) {
347
+ if (nextSurrogate > 0x7FF ) {
344
348
category = low (nextChar);
345
- } else if (nextChar & 0xFC00 == 0xD800 ) {
349
+ } else if (nextSurrogate <= 0x3FF ) {
346
350
var indexAfter = index + 1 ;
347
351
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 );
351
355
}
352
356
}
353
357
} 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);
357
362
cursorBefore -= 1 ;
358
363
}
359
364
}
0 commit comments