From 7ba3fada7a1e0e73a758d37447a42ef7f54d338f Mon Sep 17 00:00:00 2001 From: Pavlo Stavytskyi Date: Wed, 6 Mar 2024 18:12:17 -0800 Subject: [PATCH] fix string path utils --- .../src/jvmMain/kotlin/io/morfly/airin/PathExtensions.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/airin-core/src/jvmMain/kotlin/io/morfly/airin/PathExtensions.kt b/airin-core/src/jvmMain/kotlin/io/morfly/airin/PathExtensions.kt index ccd25934..9c6d8c20 100644 --- a/airin-core/src/jvmMain/kotlin/io/morfly/airin/PathExtensions.kt +++ b/airin-core/src/jvmMain/kotlin/io/morfly/airin/PathExtensions.kt @@ -23,15 +23,15 @@ fun String.fixPath(): String = fun String.fixPathPrefix(): String { val path = trimStart() var i = 0 - while (path.startsWith('/')) i++ + while (i <= path.lastIndex && path[i] == '/') i++ return path.removePrefix("/".repeat(i)) } fun String.fixPathSuffix(): String { val path = trimEnd() - var i = 0 - while (path.endsWith('/')) i++ + var i = path.lastIndex + while (i >= 0 && path[i] == '/') i-- - return path.removeSuffix("/".repeat(i)) + return path.removeSuffix("/".repeat(path.lastIndex - i)) }