package kotlin.text; import java.util.Collection; import java.util.Iterator; import kotlin.collections.IntIterator; import kotlin.jvm.internal.Intrinsics; import kotlin.ranges.RangesKt___RangesKt; /* loaded from: classes5.dex */ public abstract class StringsKt__StringsJVMKt extends StringsKt__StringNumberConversionsKt { public static boolean equals(String str, String str2, boolean z) { if (str == null) { return str2 == null; } if (!z) { return str.equals(str2); } return str.equalsIgnoreCase(str2); } public static /* synthetic */ String replace$default(String str, char c, char c2, boolean z, int i, Object obj) { if ((i & 4) != 0) { z = false; } return replace(str, c, c2, z); } public static final String replace(String str, char c, char c2, boolean z) { Intrinsics.checkNotNullParameter(str, ""); if (!z) { String replace = str.replace(c, c2); Intrinsics.checkNotNullExpressionValue(replace, "replace(...)"); return replace; } StringBuilder sb = new StringBuilder(str.length()); for (int i = 0; i < str.length(); i++) { char charAt = str.charAt(i); if (CharsKt__CharKt.equals(charAt, c, z)) { charAt = c2; } sb.append(charAt); } String sb2 = sb.toString(); Intrinsics.checkNotNullExpressionValue(sb2, "toString(...)"); return sb2; } public static /* synthetic */ String replace$default(String str, String str2, String str3, boolean z, int i, Object obj) { if ((i & 4) != 0) { z = false; } return replace(str, str2, str3, z); } public static final String replace(String str, String oldValue, String newValue, boolean z) { int coerceAtLeast; Intrinsics.checkNotNullParameter(str, ""); Intrinsics.checkNotNullParameter(oldValue, "oldValue"); Intrinsics.checkNotNullParameter(newValue, "newValue"); int i = 0; int indexOf = StringsKt__StringsKt.indexOf(str, oldValue, 0, z); if (indexOf < 0) { return str; } int length = oldValue.length(); coerceAtLeast = RangesKt___RangesKt.coerceAtLeast(length, 1); int length2 = (str.length() - length) + newValue.length(); if (length2 < 0) { throw new OutOfMemoryError(); } StringBuilder sb = new StringBuilder(length2); do { sb.append((CharSequence) str, i, indexOf); sb.append(newValue); i = indexOf + length; if (indexOf >= str.length()) { break; } indexOf = StringsKt__StringsKt.indexOf(str, oldValue, indexOf + coerceAtLeast, z); } while (indexOf > 0); sb.append((CharSequence) str, i, str.length()); String sb2 = sb.toString(); Intrinsics.checkNotNullExpressionValue(sb2, "toString(...)"); return sb2; } public static byte[] encodeToByteArray(String str) { Intrinsics.checkNotNullParameter(str, ""); byte[] bytes = str.getBytes(Charsets.UTF_8); Intrinsics.checkNotNullExpressionValue(bytes, "getBytes(...)"); return bytes; } public static /* synthetic */ boolean startsWith$default(String str, String str2, boolean z, int i, Object obj) { if ((i & 2) != 0) { z = false; } return startsWith(str, str2, z); } public static final boolean startsWith(String str, String prefix, boolean z) { Intrinsics.checkNotNullParameter(str, ""); Intrinsics.checkNotNullParameter(prefix, "prefix"); if (!z) { return str.startsWith(prefix); } return regionMatches(str, 0, prefix, 0, prefix.length(), z); } public static /* synthetic */ boolean endsWith$default(String str, String str2, boolean z, int i, Object obj) { if ((i & 2) != 0) { z = false; } return endsWith(str, str2, z); } public static final boolean endsWith(String str, String suffix, boolean z) { Intrinsics.checkNotNullParameter(str, ""); Intrinsics.checkNotNullParameter(suffix, "suffix"); if (!z) { return str.endsWith(suffix); } return regionMatches(str, str.length() - suffix.length(), suffix, 0, suffix.length(), true); } public static boolean isBlank(CharSequence charSequence) { Intrinsics.checkNotNullParameter(charSequence, ""); if (charSequence.length() != 0) { Iterable indices = StringsKt__StringsKt.getIndices(charSequence); if (!(indices instanceof Collection) || !((Collection) indices).isEmpty()) { Iterator it = indices.iterator(); while (it.hasNext()) { if (!CharsKt__CharJVMKt.isWhitespace(charSequence.charAt(((IntIterator) it).nextInt()))) { return false; } } } } return true; } public static final boolean regionMatches(String str, int i, String other, int i2, int i3, boolean z) { Intrinsics.checkNotNullParameter(str, ""); Intrinsics.checkNotNullParameter(other, "other"); if (!z) { return str.regionMatches(i, other, i2, i3); } return str.regionMatches(z, i, other, i2, i3); } }