package com.peachpasswords.shared import okhttp3.internal.publicsuffix.PublicSuffixDatabase fun extractDomain(url: String): String? { return try { val normalized = if (url.startsWith("http")) url else "https://$url" val host = java.net.URL(normalized).host.lowercase() PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) } catch (_: Exception) { null } } fun getDisplayDomain(url: String): String { return try { val normalized = if (url.startsWith("http")) url else "https://$url" java.net.URL(normalized).host } catch (_: Exception) { url } } /** * Browser parity with `shared/domain.ts::detectHomograph`: true when the host * contains non-ASCII characters or a punycode `xn--` label. This is warning-only; * matching/keying remains handled by [extractDomain]. */ fun detectHomograph(url: String): Boolean { return try { val normalized = if (url.contains("://")) url else "https://$url" val host = java.net.URL(normalized).host host.any { it.code > 0x7F } || host.split('.').any { it.startsWith("xn--", ignoreCase = true) } } catch (_: Exception) { false } }