Skip to content

Commit 5dbd281

Browse files
Renzo-OlivaresRenzo Olivares
andauthored
Use String.codeUnitAt instead of String.codeUnits[] in ParagraphBoundary (#120234)
* paragraph-boundary-opt * address comments * address comments --------- Co-authored-by: Renzo Olivares <[email protected]>
1 parent 9682359 commit 5dbd281

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

packages/flutter/lib/src/services/text_boundary.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,16 @@ class ParagraphBoundary extends TextBoundary {
150150
return 0;
151151
}
152152

153-
final List<int> codeUnits = _text.codeUnits;
154153
int index = position;
155154

156-
if (index > 1 && codeUnits[index] == 0xA && codeUnits[index - 1] == 0xD) {
155+
if (index > 1 && _text.codeUnitAt(index) == 0x0A && _text.codeUnitAt(index - 1) == 0x0D) {
157156
index -= 2;
158-
} else if (TextLayoutMetrics.isLineTerminator(codeUnits[index])) {
157+
} else if (TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) {
159158
index -= 1;
160159
}
161160

162161
while (index > 0) {
163-
if (TextLayoutMetrics.isLineTerminator(codeUnits[index])) {
162+
if (TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) {
164163
return index + 1;
165164
}
166165
index -= 1;
@@ -183,19 +182,18 @@ class ParagraphBoundary extends TextBoundary {
183182
return 0;
184183
}
185184

186-
final List<int> codeUnits = _text.codeUnits;
187185
int index = position;
188186

189-
while (!TextLayoutMetrics.isLineTerminator(codeUnits[index])) {
187+
while (!TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) {
190188
index += 1;
191-
if (index == codeUnits.length) {
189+
if (index == _text.length) {
192190
return index;
193191
}
194192
}
195193

196-
return index < codeUnits.length - 1
197-
&& codeUnits[index] == 0xD
198-
&& codeUnits[index + 1] == 0xA
194+
return index < _text.length - 1
195+
&& _text.codeUnitAt(index) == 0x0D
196+
&& _text.codeUnitAt(index + 1) == 0x0A
199197
? index + 2
200198
: index + 1;
201199
}

packages/flutter/lib/src/services/text_layout_metrics.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ abstract class TextLayoutMetrics {
6060
/// (https://www.unicode.org/standard/reports/tr13/tr13-5.html).
6161
static bool isLineTerminator(int codeUnit) {
6262
switch (codeUnit) {
63-
case 0xA: // line feed
64-
case 0xB: // vertical feed
65-
case 0xC: // form feed
66-
case 0xD: // carriage return
63+
case 0x0A: // line feed
64+
case 0x0B: // vertical feed
65+
case 0x0C: // form feed
66+
case 0x0D: // carriage return
6767
case 0x85: // new line
6868
case 0x2028: // line separator
6969
case 0x2029: // paragraph separator

0 commit comments

Comments
 (0)