diff --git a/README.md b/README.md index ecfa696..c2e2ffc 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,6 @@ repositories { } dependencies { - implementation("me.alex_s168:blitz:0.1") + implementation("me.alex_s168:blitz:0.5") } ``` \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 5517be4..7f944e7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "me.alex_s168" -version = "0.3" +version = "0.5" repositories { mavenCentral() diff --git a/src/main/kotlin/blitz/IO.kt b/src/main/kotlin/blitz/IO.kt new file mode 100644 index 0000000..41f69b1 --- /dev/null +++ b/src/main/kotlin/blitz/IO.kt @@ -0,0 +1,5 @@ +package blitz + +fun warn(msg: String) { + System.err.println(msg) +} \ No newline at end of file diff --git a/src/main/kotlin/blitz/collections/BatchedUtils.kt b/src/main/kotlin/blitz/collections/BatchedUtils.kt index f337239..5cff024 100644 --- a/src/main/kotlin/blitz/collections/BatchedUtils.kt +++ b/src/main/kotlin/blitz/collections/BatchedUtils.kt @@ -7,4 +7,12 @@ fun ByteBatchSequence.stringify(batch: Int = 64): Sequence { iter.nextBytes(batch).decodeToString() else null } +} + +fun Sequence.flatten(): String { + val out = StringBuilder() + forEach { + out.append(it) + } + return out.toString() } \ No newline at end of file diff --git a/src/main/kotlin/blitz/io/Path.kt b/src/main/kotlin/blitz/io/Path.kt index c034cc5..aea26ce 100644 --- a/src/main/kotlin/blitz/io/Path.kt +++ b/src/main/kotlin/blitz/io/Path.kt @@ -84,7 +84,7 @@ value class Path( if (path.isEmpty()) return Path(emptyArray()) val kx = kotlinx.io.files.Path(path) if (kx.isAbsolute) - return Path(path.substring(1).split(separator).toTypedArray()) + return Path(path.split(separator, '/', '\\').filterNot { it.isEmpty() }.toTypedArray()) return of(SystemFileSystem.resolve(kx).toString()) } } diff --git a/src/main/kotlin/blitz/str/SplitWithNesting.kt b/src/main/kotlin/blitz/str/SplitWithNesting.kt new file mode 100644 index 0000000..0b8748b --- /dev/null +++ b/src/main/kotlin/blitz/str/SplitWithNesting.kt @@ -0,0 +1,33 @@ +package blitz.str + +fun String.splitWithNesting( + delim: Char, + nestUp: Char, + nestDown: Char, + dest: MutableList = mutableListOf() +): MutableList { + val last = StringBuilder() + val iter = iterator() + var nesting = 0 + while (iter.hasNext()) { + val c = iter.next() + if (nesting == 0 && c == delim) { + dest.add(last.toString()) + last.clear() + } else if (c == nestUp) { + nesting ++ + last.append(c) + } else if (c == nestDown) { + if (nesting == 0) + throw Exception("Unmatched $nestDown") + nesting -- + last.append(c) + } else { + last.append(c) + } + } + dest.add(last.toString()) + if (nesting != 0) + throw Exception("Unmatched $nestUp") + return dest +} \ No newline at end of file