Use String.codeUnitAt instead of String.codeUnits[] in ParagraphBoundary (#120234)
* paragraph-boundary-opt * address comments * address comments --------- Co-authored-by: Renzo Olivares <roliv@google.com>
This commit is contained in:
parent
96823590ec
commit
5dbd281012
@ -150,17 +150,16 @@ class ParagraphBoundary extends TextBoundary {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final List<int> codeUnits = _text.codeUnits;
|
||||
int index = position;
|
||||
|
||||
if (index > 1 && codeUnits[index] == 0xA && codeUnits[index - 1] == 0xD) {
|
||||
if (index > 1 && _text.codeUnitAt(index) == 0x0A && _text.codeUnitAt(index - 1) == 0x0D) {
|
||||
index -= 2;
|
||||
} else if (TextLayoutMetrics.isLineTerminator(codeUnits[index])) {
|
||||
} else if (TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) {
|
||||
index -= 1;
|
||||
}
|
||||
|
||||
while (index > 0) {
|
||||
if (TextLayoutMetrics.isLineTerminator(codeUnits[index])) {
|
||||
if (TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) {
|
||||
return index + 1;
|
||||
}
|
||||
index -= 1;
|
||||
@ -183,19 +182,18 @@ class ParagraphBoundary extends TextBoundary {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final List<int> codeUnits = _text.codeUnits;
|
||||
int index = position;
|
||||
|
||||
while (!TextLayoutMetrics.isLineTerminator(codeUnits[index])) {
|
||||
while (!TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) {
|
||||
index += 1;
|
||||
if (index == codeUnits.length) {
|
||||
if (index == _text.length) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return index < codeUnits.length - 1
|
||||
&& codeUnits[index] == 0xD
|
||||
&& codeUnits[index + 1] == 0xA
|
||||
return index < _text.length - 1
|
||||
&& _text.codeUnitAt(index) == 0x0D
|
||||
&& _text.codeUnitAt(index + 1) == 0x0A
|
||||
? index + 2
|
||||
: index + 1;
|
||||
}
|
||||
|
@ -60,10 +60,10 @@ abstract class TextLayoutMetrics {
|
||||
/// (https://www.unicode.org/standard/reports/tr13/tr13-5.html).
|
||||
static bool isLineTerminator(int codeUnit) {
|
||||
switch (codeUnit) {
|
||||
case 0xA: // line feed
|
||||
case 0xB: // vertical feed
|
||||
case 0xC: // form feed
|
||||
case 0xD: // carriage return
|
||||
case 0x0A: // line feed
|
||||
case 0x0B: // vertical feed
|
||||
case 0x0C: // form feed
|
||||
case 0x0D: // carriage return
|
||||
case 0x85: // new line
|
||||
case 0x2028: // line separator
|
||||
case 0x2029: // paragraph separator
|
||||
|
Loading…
x
Reference in New Issue
Block a user