mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +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 {
|
||||
append(id)
|
||||
versionRequirement?.let {
|
||||
append(":")
|
||||
append(':')
|
||||
append(it)
|
||||
}
|
||||
if (isOptional) {
|
||||
@ -83,10 +83,14 @@ public data class PluginDependency @JvmOverloads constructor(
|
||||
public fun parseFromString(string: String): PluginDependency {
|
||||
require(string.isNotEmpty()) { "string is empty." }
|
||||
val optional = string.endsWith('?')
|
||||
val (id, version) = string.removeSuffix("?").let {
|
||||
it.substringBeforeLast(':') to it.substringAfterLast(':', "")
|
||||
val (id, version) = string.removeSuffix("?").let { rule ->
|
||||
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