Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun String.unpack(): String {
- val builder = StringBuilder()
- var i = 0
- while (i < length) {
- if (this[i].isDigit()) {
- val repeatCount = this[i].digitToInt()
- i += 2
- val subStringStartIndex = i
- var openedBraces = 1
- while (openedBraces > 0) {
- when (this[i]) {
- '[' -> ++openedBraces
- ']' -> --openedBraces
- }
- ++i
- }
- val stringToRepeat = substring(subStringStartIndex until i - 1).unpack()
- builder.append(stringToRepeat.repeat(repeatCount))
- } else {
- builder.append(this[i])
- ++i
- }
- }
- return builder.toString()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement