splitWithNesting, Sequence<String>.flatten(), path fix on win
This commit is contained in:
@@ -24,6 +24,6 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("me.alex_s168:blitz:0.1")
|
implementation("me.alex_s168:blitz:0.5")
|
||||||
}
|
}
|
||||||
```
|
```
|
@@ -5,7 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "me.alex_s168"
|
group = "me.alex_s168"
|
||||||
version = "0.3"
|
version = "0.5"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
5
src/main/kotlin/blitz/IO.kt
Normal file
5
src/main/kotlin/blitz/IO.kt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package blitz
|
||||||
|
|
||||||
|
fun warn(msg: String) {
|
||||||
|
System.err.println(msg)
|
||||||
|
}
|
@@ -7,4 +7,12 @@ fun ByteBatchSequence.stringify(batch: Int = 64): Sequence<String> {
|
|||||||
iter.nextBytes(batch).decodeToString()
|
iter.nextBytes(batch).decodeToString()
|
||||||
else null
|
else null
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Sequence<String>.flatten(): String {
|
||||||
|
val out = StringBuilder()
|
||||||
|
forEach {
|
||||||
|
out.append(it)
|
||||||
|
}
|
||||||
|
return out.toString()
|
||||||
}
|
}
|
@@ -84,7 +84,7 @@ value class Path(
|
|||||||
if (path.isEmpty()) return Path(emptyArray())
|
if (path.isEmpty()) return Path(emptyArray())
|
||||||
val kx = kotlinx.io.files.Path(path)
|
val kx = kotlinx.io.files.Path(path)
|
||||||
if (kx.isAbsolute)
|
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())
|
return of(SystemFileSystem.resolve(kx).toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
src/main/kotlin/blitz/str/SplitWithNesting.kt
Normal file
33
src/main/kotlin/blitz/str/SplitWithNesting.kt
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package blitz.str
|
||||||
|
|
||||||
|
fun String.splitWithNesting(
|
||||||
|
delim: Char,
|
||||||
|
nestUp: Char,
|
||||||
|
nestDown: Char,
|
||||||
|
dest: MutableList<String> = mutableListOf()
|
||||||
|
): MutableList<String> {
|
||||||
|
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
|
||||||
|
}
|
Reference in New Issue
Block a user