-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
34 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
common-5/src/main/kotlin/taboolib/common5/util/String2TimeCycle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
common-5/src/main/kotlin/taboolib/common5/util/StringBase64.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
common-5/src/main/kotlin/taboolib/common5/util/StringOperator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters