Unverified Commit 5dbd2810 authored by Renzo Olivares's avatar Renzo Olivares Committed by GitHub

Use String.codeUnitAt instead of String.codeUnits[] in ParagraphBoundary (#120234)

* paragraph-boundary-opt

* address comments

* address comments

---------
Co-authored-by: 's avatarRenzo Olivares <roliv@google.com>
parent 96823590
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment