mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
In-line calls to SpannableStringBuilder.length() in TtmlNode
This avoids keeping a redundant (and potentially out of sync) copy of the same info in builderLength. PiperOrigin-RevId: 290709360
This commit is contained in:
parent
3aa52c2317
commit
4da0d0a4b5
1 changed files with 8 additions and 15 deletions
|
|
@ -364,8 +364,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
private static void cleanUpText(SpannableStringBuilder builder) {
|
private static void cleanUpText(SpannableStringBuilder builder) {
|
||||||
// Having joined the text elements, we need to do some final cleanup on the result.
|
// Having joined the text elements, we need to do some final cleanup on the result.
|
||||||
// 1. Collapse multiple consecutive spaces into a single space.
|
// 1. Collapse multiple consecutive spaces into a single space.
|
||||||
int builderLength = builder.length();
|
for (int i = 0; i < builder.length(); i++) {
|
||||||
for (int i = 0; i < builderLength; i++) {
|
|
||||||
if (builder.charAt(i) == ' ') {
|
if (builder.charAt(i) == ' ') {
|
||||||
int j = i + 1;
|
int j = i + 1;
|
||||||
while (j < builder.length() && builder.charAt(j) == ' ') {
|
while (j < builder.length() && builder.charAt(j) == ' ') {
|
||||||
|
|
@ -374,36 +373,30 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
int spacesToDelete = j - (i + 1);
|
int spacesToDelete = j - (i + 1);
|
||||||
if (spacesToDelete > 0) {
|
if (spacesToDelete > 0) {
|
||||||
builder.delete(i, i + spacesToDelete);
|
builder.delete(i, i + spacesToDelete);
|
||||||
builderLength -= spacesToDelete;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 2. Remove any spaces from the start of each line.
|
// 2. Remove any spaces from the start of each line.
|
||||||
if (builderLength > 0 && builder.charAt(0) == ' ') {
|
if (builder.length() > 0 && builder.charAt(0) == ' ') {
|
||||||
builder.delete(0, 1);
|
builder.delete(0, 1);
|
||||||
builderLength--;
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < builderLength - 1; i++) {
|
for (int i = 0; i < builder.length() - 1; i++) {
|
||||||
if (builder.charAt(i) == '\n' && builder.charAt(i + 1) == ' ') {
|
if (builder.charAt(i) == '\n' && builder.charAt(i + 1) == ' ') {
|
||||||
builder.delete(i + 1, i + 2);
|
builder.delete(i + 1, i + 2);
|
||||||
builderLength--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 3. Remove any spaces from the end of each line.
|
// 3. Remove any spaces from the end of each line.
|
||||||
if (builderLength > 0 && builder.charAt(builderLength - 1) == ' ') {
|
if (builder.length() > 0 && builder.charAt(builder.length() - 1) == ' ') {
|
||||||
builder.delete(builderLength - 1, builderLength);
|
builder.delete(builder.length() - 1, builder.length());
|
||||||
builderLength--;
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < builderLength - 1; i++) {
|
for (int i = 0; i < builder.length() - 1; i++) {
|
||||||
if (builder.charAt(i) == ' ' && builder.charAt(i + 1) == '\n') {
|
if (builder.charAt(i) == ' ' && builder.charAt(i + 1) == '\n') {
|
||||||
builder.delete(i, i + 1);
|
builder.delete(i, i + 1);
|
||||||
builderLength--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 4. Trim a trailing newline, if there is one.
|
// 4. Trim a trailing newline, if there is one.
|
||||||
if (builderLength > 0 && builder.charAt(builderLength - 1) == '\n') {
|
if (builder.length() > 0 && builder.charAt(builder.length() - 1) == '\n') {
|
||||||
builder.delete(builderLength - 1, builderLength);
|
builder.delete(builder.length() - 1, builder.length());
|
||||||
/*builderLength--;*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue