Skip to content

Commit

Permalink
[publish] 6.0.12 Update common
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed Jan 1, 2024
1 parent a3079a6 commit 94d9a6d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:Isolated
@file:Suppress("NOTHING_TO_INLINE")

package taboolib.common5.util

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
@file:Isolated
@file:Suppress("NOTHING_TO_INLINE")

package taboolib.common5.util

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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
12 changes: 7 additions & 5 deletions common-5/src/main/kotlin/taboolib/common5/util/StringBase64.kt
Original file line number Diff line number Diff line change
@@ -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)
}
17 changes: 11 additions & 6 deletions common-5/src/main/kotlin/taboolib/common5/util/StringOperator.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
@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, Any>): String {
inline fun String.replace(vararg pairs: Pair<String, Any>): String {
var text = this
pairs.forEach { pair ->
text = text.replace(pair.first, pair.second.toString())
}
return text
}

fun List<String>.replace(vararg pairs: Pair<String, Any>): List<String> {
inline fun List<String>.replace(vararg pairs: Pair<String, Any>): List<String> {
return map { it.replace(*pairs) }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:Isolated
@file:Suppress("NOTHING_TO_INLINE")

package taboolib.common5.util

Expand All @@ -7,7 +8,7 @@ import taboolib.common.Isolated
/**
* 将文字转换为打印机特效
*/
fun String.printed(separator: String = ""): List<String> {
inline fun String.printed(separator: String = ""): List<String> {
val result = ArrayList<String>()
var i = 0
while (i < length) {
Expand All @@ -32,7 +33,7 @@ fun String.printed(separator: String = ""): List<String> {
* @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
}
Expand Down
8 changes: 6 additions & 2 deletions common-5/src/main/kotlin/taboolib/common5/util/Throwable.kt
Original file line number Diff line number Diff line change
@@ -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<String> {
inline fun Throwable.getStackTraceStringList(): List<String> {
val sw = StringWriter()
printStackTrace(PrintWriter(sw))
return sw.toString().lines()
Expand Down

0 comments on commit 94d9a6d

Please sign in to comment.