From: David ‘Bombe’ Roden Date: Fri, 2 Sep 2022 14:42:41 +0000 (+0200) Subject: ♻️ Move extension methods out of classes X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a72774c302cdb2c35508380fb2ec445be2705efe;p=Sone.git ♻️ Move extension methods out of classes --- diff --git a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt index 409d18c..2849029 100644 --- a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt +++ b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt @@ -58,29 +58,6 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke } } - private val String?.emptyToNull get() = if (this == "") null else this - - private val Document.metaDescription: String? - get() = head().getElementsByTag("meta") - .map { it.attr("name") to it.attr("content") } - .firstOrNull { it.first == "description" } - ?.second - - private val Document.firstNonHeadingParagraph: String? - get() = body().children() - .filter { it.children().all { it is TextNode } } - .map { it to it.text() } - .filterNot { it.second == "" } - .firstOrNull { !it.first.tagName().startsWith("h", ignoreCase = true) } - ?.second - - private val Int.human get() = when (this) { - in 0..1023 -> "$this B" - in 1024..1048575 -> "${this / 1024} KiB" - in 1048576..1073741823 -> "${this / 1048576} MiB" - else -> "${this / 1073741824} GiB" - } - override fun failed(uri: FreenetURI) { failureCache.put(uri.toString().decode().normalize(), true) removeLoadingLink(uri) @@ -110,7 +87,29 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke return LinkedElement(link, loading = true) } - private fun String.decode() = URLDecoder.decode(this, "UTF-8")!! - private fun String.normalize() = Normalizer.normalize(this, Normalizer.Form.NFC)!! +} + +private fun String.decode() = URLDecoder.decode(this, "UTF-8")!! +private fun String.normalize() = Normalizer.normalize(this, Normalizer.Form.NFC)!! +private val String?.emptyToNull get() = if (this == "") null else this + +private val Document.metaDescription: String? + get() = head().getElementsByTag("meta") + .map { it.attr("name") to it.attr("content") } + .firstOrNull { it.first == "description" } + ?.second + +private val Document.firstNonHeadingParagraph: String? + get() = body().children() + .filter { it.children().all { it is TextNode } } + .map { it to it.text() } + .filterNot { it.second == "" } + .firstOrNull { !it.first.tagName().startsWith("h", ignoreCase = true) } + ?.second +private val Int.human get() = when (this) { + in 0..1023 -> "$this B" + in 1024..1048575 -> "${this / 1024} KiB" + in 1048576..1073741823 -> "${this / 1048576} MiB" + else -> "${this / 1073741824} GiB" }