Brace expansion: Difference between revisions

→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 1,674:
var sb = StringBuilder("")
var i1 = noEscape.indexOf('{')
var i2 = 0
 
outer@ while (i1 != -1) {
Line 1,682:
while (i2 < s.length && depth > 0) {
val c = noEscape[i2]
 
if (c == '{')
if (c == '{') depth++
else if (c == '}') depth--
 
depth--
if (c == ',' && depth == 1) sb[i2] = '\u0000'
else if (c == sb[i2]'}' && depth == '0 && sb.indexOf("\u0000'") != -1) break@outer
else if (c == '}' && depth == 0 && sb.indexOf("\u0000") != -1)
break@outer
i2++
}
Line 1,695 ⟶ 1,693:
}
if (i1 == -1) {
if (suf.lengthisNotEmpty()) >expandR(pre 0+ s, suf, "")
else expandRprintln("$pre + $s, $suf, "")
} else else{
for (m in sb.substring(i1 println+ 1, i2).split("$pre$s$suf"'\u0000')) {
}
else {
for (m in sb.substring(i1 + 1, i2).split('\u0000'))
expandR(pre + s.substring(0, i1), m, s.substring(i2 + 1) + suf)
if (c == '{')}
}
}