From 94d9a6d5197294d17423180ad051474f62166821 Mon Sep 17 00:00:00 2001 From: Bkm016 Date: Mon, 1 Jan 2024 22:31:08 +0800 Subject: [PATCH] [publish] 6.0.12 Update common --- .../kotlin/taboolib/common5/util/String2Time.kt | 3 ++- .../taboolib/common5/util/String2TimeCycle.kt | 3 ++- .../kotlin/taboolib/common5/util/String2UUID.kt | 4 +++- .../taboolib/common5/util/StringBase64.kt | 12 +++++++----- .../taboolib/common5/util/StringOperator.kt | 17 +++++++++++------ .../taboolib/common5/util/StringQualify.kt | 5 +++-- .../kotlin/taboolib/common5/util/Throwable.kt | 8 ++++++-- 7 files changed, 34 insertions(+), 18 deletions(-) diff --git a/common-5/src/main/kotlin/taboolib/common5/util/String2Time.kt b/common-5/src/main/kotlin/taboolib/common5/util/String2Time.kt index 94fdbcbb1..11ba56f8d 100644 --- a/common-5/src/main/kotlin/taboolib/common5/util/String2Time.kt +++ b/common-5/src/main/kotlin/taboolib/common5/util/String2Time.kt @@ -1,4 +1,5 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") package taboolib.common5.util @@ -10,7 +11,7 @@ import java.util.* * * @return 时间跨度(单位:毫秒) */ -fun String.parseMillis(): Long { +inline fun String.parseMillis(): Long { var time = 0L var num = "" lowercase(Locale.getDefault()).forEach { diff --git a/common-5/src/main/kotlin/taboolib/common5/util/String2TimeCycle.kt b/common-5/src/main/kotlin/taboolib/common5/util/String2TimeCycle.kt index 7fe4a2400..47e483b81 100644 --- a/common-5/src/main/kotlin/taboolib/common5/util/String2TimeCycle.kt +++ b/common-5/src/main/kotlin/taboolib/common5/util/String2TimeCycle.kt @@ -1,4 +1,5 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") package taboolib.common5.util @@ -6,7 +7,7 @@ import taboolib.common.Isolated import taboolib.common5.Coerce import taboolib.common5.TimeCycle -fun String.parseTimeCycle(): TimeCycle { +inline fun String.parseTimeCycle(): TimeCycle { val args = split(" ") return when (args[0]) { "day" -> TimeCycle( diff --git a/common-5/src/main/kotlin/taboolib/common5/util/String2UUID.kt b/common-5/src/main/kotlin/taboolib/common5/util/String2UUID.kt index 37feda0f2..7e6b3c6cd 100644 --- a/common-5/src/main/kotlin/taboolib/common5/util/String2UUID.kt +++ b/common-5/src/main/kotlin/taboolib/common5/util/String2UUID.kt @@ -1,9 +1,11 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common5.util import taboolib.common.Isolated import java.util.* -fun String.parseUUID(): UUID? { +inline fun String.parseUUID(): UUID? { return kotlin.runCatching { UUID.fromString(this) }.getOrNull() } \ No newline at end of file diff --git a/common-5/src/main/kotlin/taboolib/common5/util/StringBase64.kt b/common-5/src/main/kotlin/taboolib/common5/util/StringBase64.kt index d1a4e879e..72ffb1732 100644 --- a/common-5/src/main/kotlin/taboolib/common5/util/StringBase64.kt +++ b/common-5/src/main/kotlin/taboolib/common5/util/StringBase64.kt @@ -1,20 +1,22 @@ -package taboolib.common5.util +@file:Isolated +@file:Suppress("NOTHING_TO_INLINE") +import taboolib.common.Isolated import java.nio.charset.StandardCharsets import java.util.* -fun ByteArray.encodeBase64(): String { +inline fun ByteArray.encodeBase64(): String { return Base64.getEncoder().encode(this).toString(StandardCharsets.UTF_8) } -fun String.encodeBase64(): String { +inline fun String.encodeBase64(): String { return Base64.getEncoder().encode(toByteArray()).toString(StandardCharsets.UTF_8) } -fun ByteArray.decodeBase64(): ByteArray { +inline fun ByteArray.decodeBase64(): ByteArray { return Base64.getDecoder().decode(this) } -fun String.decodeBase64(): ByteArray { +inline fun String.decodeBase64(): ByteArray { return Base64.getDecoder().decode(this) } \ No newline at end of file diff --git a/common-5/src/main/kotlin/taboolib/common5/util/StringOperator.kt b/common-5/src/main/kotlin/taboolib/common5/util/StringOperator.kt index f340ffac0..30e62b9cf 100644 --- a/common-5/src/main/kotlin/taboolib/common5/util/StringOperator.kt +++ b/common-5/src/main/kotlin/taboolib/common5/util/StringOperator.kt @@ -1,22 +1,27 @@ +@file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common5.util -fun String.startsWithAny(vararg prefix: String): Boolean { +import taboolib.common.Isolated + +inline fun String.startsWithAny(vararg prefix: String): Boolean { return prefix.any { startsWith(it) } } -fun String.endsWithAny(vararg suffix: String): Boolean { +inline fun String.endsWithAny(vararg suffix: String): Boolean { return suffix.any { endsWith(it) } } -fun String.substringAfterAny(vararg morePrefix: String): String { +inline fun String.substringAfterAny(vararg morePrefix: String): String { return substringAfter(morePrefix.firstOrNull { startsWith(it) } ?: return this) } -fun String.substringBeforeAny(vararg moreSuffix: String): String { +inline fun String.substringBeforeAny(vararg moreSuffix: String): String { return substringBefore(moreSuffix.firstOrNull { endsWith(it) } ?: return this) } -fun String.replace(vararg pairs: Pair): String { +inline fun String.replace(vararg pairs: Pair): String { var text = this pairs.forEach { pair -> text = text.replace(pair.first, pair.second.toString()) @@ -24,6 +29,6 @@ fun String.replace(vararg pairs: Pair): String { return text } -fun List.replace(vararg pairs: Pair): List { +inline fun List.replace(vararg pairs: Pair): List { return map { it.replace(*pairs) } } \ No newline at end of file diff --git a/common-5/src/main/kotlin/taboolib/common5/util/StringQualify.kt b/common-5/src/main/kotlin/taboolib/common5/util/StringQualify.kt index 25cdd84ed..bd837f1a0 100644 --- a/common-5/src/main/kotlin/taboolib/common5/util/StringQualify.kt +++ b/common-5/src/main/kotlin/taboolib/common5/util/StringQualify.kt @@ -1,4 +1,5 @@ @file:Isolated +@file:Suppress("NOTHING_TO_INLINE") package taboolib.common5.util @@ -7,7 +8,7 @@ import taboolib.common.Isolated /** * 将文字转换为打印机特效 */ -fun String.printed(separator: String = ""): List { +inline fun String.printed(separator: String = ""): List { val result = ArrayList() var i = 0 while (i < length) { @@ -32,7 +33,7 @@ fun String.printed(separator: String = ""): List { * @param length 长度 * @param percent 百分比 */ -fun createBar(empty: String, fill: String, length: Int, percent: Double): String { +inline fun createBar(empty: String, fill: String, length: Int, percent: Double): String { return (1..length).joinToString("") { if (percent.isNaN() || percent == 0.0) empty else if (percent >= it.toDouble() / length) fill else empty } diff --git a/common-5/src/main/kotlin/taboolib/common5/util/Throwable.kt b/common-5/src/main/kotlin/taboolib/common5/util/Throwable.kt index 55d0f18a1..75d94c214 100644 --- a/common-5/src/main/kotlin/taboolib/common5/util/Throwable.kt +++ b/common-5/src/main/kotlin/taboolib/common5/util/Throwable.kt @@ -1,15 +1,19 @@ +@file:Isolated +@file:Suppress("NOTHING_TO_INLINE") + package taboolib.common5.util +import taboolib.common.Isolated import java.io.PrintWriter import java.io.StringWriter -fun Throwable.getStackTraceString(): String { +inline fun Throwable.getStackTraceString(): String { val sw = StringWriter() printStackTrace(PrintWriter(sw)) return sw.toString() } -fun Throwable.getStackTraceStringList(): List { +inline fun Throwable.getStackTraceStringList(): List { val sw = StringWriter() printStackTrace(PrintWriter(sw)) return sw.toString().lines()