package kotlin.text; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import kotlin.collections.CollectionsKt__CollectionsKt; import kotlin.collections.CollectionsKt__IterablesKt; import kotlin.collections.CollectionsKt___CollectionsKt; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.Intrinsics; /* loaded from: classes5.dex */ public abstract class StringsKt__IndentKt extends StringsKt__AppendableKt { public static String trimIndent(String str) { Intrinsics.checkNotNullParameter(str, ""); return replaceIndent(str, ""); } public static final String replaceIndent(String str, String newIndent) { String str2; Intrinsics.checkNotNullParameter(str, ""); Intrinsics.checkNotNullParameter(newIndent, "newIndent"); List lines = StringsKt__StringsKt.lines(str); ArrayList arrayList = new ArrayList(); for (Object obj : lines) { if (!StringsKt__StringsJVMKt.isBlank((String) obj)) { arrayList.add(obj); } } ArrayList arrayList2 = new ArrayList(CollectionsKt__IterablesKt.collectionSizeOrDefault(arrayList, 10)); Iterator it = arrayList.iterator(); while (it.hasNext()) { arrayList2.add(Integer.valueOf(indentWidth$StringsKt__IndentKt((String) it.next()))); } Integer num = (Integer) CollectionsKt___CollectionsKt.minOrNull(arrayList2); int i = 0; int intValue = num != null ? num.intValue() : 0; int length = str.length() + (newIndent.length() * lines.size()); Function1 indentFunction$StringsKt__IndentKt = getIndentFunction$StringsKt__IndentKt(newIndent); int lastIndex = CollectionsKt__CollectionsKt.getLastIndex(lines); ArrayList arrayList3 = new ArrayList(); for (Object obj2 : lines) { int i2 = i + 1; if (i < 0) { CollectionsKt__CollectionsKt.throwIndexOverflow(); } String str3 = (String) obj2; if ((i == 0 || i == lastIndex) && StringsKt__StringsJVMKt.isBlank(str3)) { str3 = null; } else { String drop = StringsKt___StringsKt.drop(str3, intValue); if (drop != null && (str2 = (String) indentFunction$StringsKt__IndentKt.invoke(drop)) != null) { str3 = str2; } } if (str3 != null) { arrayList3.add(str3); } i = i2; } String sb = ((StringBuilder) CollectionsKt___CollectionsKt.joinTo$default(arrayList3, new StringBuilder(length), "\n", null, null, 0, null, null, 124, null)).toString(); Intrinsics.checkNotNullExpressionValue(sb, "toString(...)"); return sb; } public static final Function1 getIndentFunction$StringsKt__IndentKt(final String str) { return str.length() == 0 ? new Function1() { // from class: kotlin.text.StringsKt__IndentKt$getIndentFunction$1 @Override // kotlin.jvm.functions.Function1 public final String invoke(String line) { Intrinsics.checkNotNullParameter(line, "line"); return line; } } : new Function1() { // from class: kotlin.text.StringsKt__IndentKt$getIndentFunction$2 /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ { super(1); } @Override // kotlin.jvm.functions.Function1 public final String invoke(String line) { Intrinsics.checkNotNullParameter(line, "line"); return str + line; } }; } public static final int indentWidth$StringsKt__IndentKt(String str) { int length = str.length(); int i = 0; while (true) { if (i >= length) { i = -1; break; } if (!CharsKt__CharJVMKt.isWhitespace(str.charAt(i))) { break; } i++; } return i == -1 ? str.length() : i; } }