mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 00:30:17 +08:00
Improve PluginDependency.parseFromString
This commit is contained in:
parent
cd2ee20961
commit
debe5baae4
@ -66,7 +66,7 @@ public data class PluginDependency @JvmOverloads constructor(
|
|||||||
public override fun toString(): String = buildString {
|
public override fun toString(): String = buildString {
|
||||||
append(id)
|
append(id)
|
||||||
versionRequirement?.let {
|
versionRequirement?.let {
|
||||||
append(":")
|
append(':')
|
||||||
append(it)
|
append(it)
|
||||||
}
|
}
|
||||||
if (isOptional) {
|
if (isOptional) {
|
||||||
@ -83,10 +83,14 @@ public data class PluginDependency @JvmOverloads constructor(
|
|||||||
public fun parseFromString(string: String): PluginDependency {
|
public fun parseFromString(string: String): PluginDependency {
|
||||||
require(string.isNotEmpty()) { "string is empty." }
|
require(string.isNotEmpty()) { "string is empty." }
|
||||||
val optional = string.endsWith('?')
|
val optional = string.endsWith('?')
|
||||||
val (id, version) = string.removeSuffix("?").let {
|
val (id, version) = string.removeSuffix("?").let { rule ->
|
||||||
it.substringBeforeLast(':') to it.substringAfterLast(':', "")
|
if (rule.contains(':')) {
|
||||||
|
rule.substringBeforeLast(':') to rule.substringAfterLast(':')
|
||||||
|
} else {
|
||||||
|
rule to null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return PluginDependency(id, version.takeIf(String::isNotBlank), optional)
|
return PluginDependency(id, version, optional)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user