From 1d77cf8f98140ed96b009b25b39dec8b884479f2 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 24 May 2024 12:27:19 +0700 Subject: [PATCH] String.limit --- src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt index 9566b875..53de3471 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt @@ -82,3 +82,11 @@ fun Collection.valueOf(value: String): E { fun Executor.supplyAsync(block: Supplier): CompletableFuture { return CompletableFuture.supplyAsync(block, this) } + +fun String.limit(limit: Int = 40, replacer: String = "..."): String { + if (length <= limit) { + return this + } + + return substring(0, limit) + replacer +}