diff options
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/NumberUtil.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/NumberUtil.kt | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/NumberUtil.kt b/src/main/kotlin/moe/nea/ledger/NumberUtil.kt index 008cfbf..438f342 100644 --- a/src/main/kotlin/moe/nea/ledger/NumberUtil.kt +++ b/src/main/kotlin/moe/nea/ledger/NumberUtil.kt @@ -75,9 +75,17 @@ fun parseShortNumber(string: String): Double { return k.toDouble() * scalarMultiplier } +fun Pattern.matches(string: String): Boolean = matcher(string).matches() inline fun <T> Pattern.useMatcher(string: String, block: Matcher.() -> T): T? = matcher(string).takeIf { it.matches() }?.let(block) +fun <T> String.ifDropLast(suffix: String, block: (String) -> T): T? { + if (endsWith(suffix)) { + return block(dropLast(suffix.length)) + } + return null +} + fun String.unformattedString(): String = replace("ยง.".toRegex(), "") val timeFormat: DateTimeFormatter = DateTimeFormatterBuilder() |