Add Dumper support for outputting multiline strings
PiperOrigin-RevId: 570348425
This commit is contained in:
parent
c8aac24ffd
commit
b83f12c4ba
@ -1029,7 +1029,7 @@ public final class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits a string using {@code value.split(regex, -1}). Note: this is is similar to {@link
|
* Splits a string using {@code value.split(regex, -1}). Note: this is similar to {@link
|
||||||
* String#split(String)} but empty matches at the end of the string will not be omitted from the
|
* String#split(String)} but empty matches at the end of the string will not be omitted from the
|
||||||
* returned array.
|
* returned array.
|
||||||
*
|
*
|
||||||
|
@ -15,9 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package androidx.media3.test.utils;
|
package androidx.media3.test.utils;
|
||||||
|
|
||||||
|
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
|
import androidx.media3.common.util.Util;
|
||||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -47,7 +50,16 @@ public final class Dumper {
|
|||||||
|
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
public Dumper add(String field, @Nullable Object value) {
|
public Dumper add(String field, @Nullable Object value) {
|
||||||
return addString(field + " = " + value + '\n');
|
checkNotNull(value);
|
||||||
|
String[] lines = Util.split(value.toString(), "\n");
|
||||||
|
addLine(field + " = " + lines[0]);
|
||||||
|
int fieldValueAdditionalIndent = field.length() + 3;
|
||||||
|
indent += fieldValueAdditionalIndent;
|
||||||
|
for (int i = 1; i < lines.length; i++) {
|
||||||
|
addLine(lines[i]);
|
||||||
|
}
|
||||||
|
indent -= fieldValueAdditionalIndent;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
@ -61,11 +73,11 @@ public final class Dumper {
|
|||||||
String string =
|
String string =
|
||||||
String.format(
|
String.format(
|
||||||
Locale.US,
|
Locale.US,
|
||||||
"%s = length %d, hash %X\n",
|
"%s = length %d, hash %X",
|
||||||
field,
|
field,
|
||||||
value == null ? 0 : value.length,
|
value == null ? 0 : value.length,
|
||||||
Arrays.hashCode(value));
|
Arrays.hashCode(value));
|
||||||
return addString(string);
|
return addLine(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
@ -75,7 +87,7 @@ public final class Dumper {
|
|||||||
|
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
public Dumper startBlock(String name) {
|
public Dumper startBlock(String name) {
|
||||||
addString(name + ":\n");
|
addLine(name + ":");
|
||||||
indent += INDENT_SIZE_IN_SPACES;
|
indent += INDENT_SIZE_IN_SPACES;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -92,11 +104,12 @@ public final class Dumper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
private Dumper addString(String string) {
|
private Dumper addLine(String string) {
|
||||||
for (int i = 0; i < indent; i++) {
|
for (int i = 0; i < indent; i++) {
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
}
|
}
|
||||||
sb.append(string);
|
sb.append(string);
|
||||||
|
sb.append('\n');
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user