add support of ranges in strings

This commit is contained in:
2020-07-24 13:16:56 +06:00
parent 5c452d58b7
commit 5358bfdb47
4 changed files with 36 additions and 2 deletions

View File

@@ -81,6 +81,16 @@ sealed class TimeBuilder (
*/
@Suppress("unused")
infix fun upTo(endIncluding: Int): Array<Int> = this from 0 upTo endIncluding
/**
* Will fill up this timeline from [this] up to [endIncluding]
*/
@Suppress("MemberVisibilityCanBePrivate")
infix operator fun Int.rangeTo(endIncluding: Int) = upTo(endIncluding)
/**
* Shortcut for "[from] 0 [rangeTo] [endIncluding]"
*/
@Suppress("MemberVisibilityCanBePrivate")
infix operator fun rangeTo(endIncluding: Int) = (this from 0) rangeTo endIncluding
internal fun build() = result ?.map { it.toByte() } ?.toTypedArray()
}

View File

@@ -7,6 +7,10 @@ private fun createSimpleScheduler(from: String, dataRange: IntRange): Array<Byte
val results = things.flatMap {
when {
it.contains("-") -> {
val splitted = it.split("-")
(splitted.first().toInt().clamp(dataRange) .. splitted[1].toInt().clamp(dataRange)).toList()
}
it.contains("/") -> {
val (start, step) = it.split("/")
val startNum = (if (start.isEmpty() || start == "*") {