diff options
Diffstat (limited to 'src/main/kotlin/util/StringUtil.kt')
-rw-r--r-- | src/main/kotlin/util/StringUtil.kt | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/main/kotlin/util/StringUtil.kt b/src/main/kotlin/util/StringUtil.kt index f080d5a..68e161a 100644 --- a/src/main/kotlin/util/StringUtil.kt +++ b/src/main/kotlin/util/StringUtil.kt @@ -10,4 +10,13 @@ object StringUtil { } fun Iterable<String>.unwords() = joinToString(" ") + fun nextLexicographicStringOfSameLength(string: String): String { + val next = StringBuilder(string) + while (next.lastOrNull() == Character.MAX_VALUE) next.setLength(next.length - 1) + if (next.isEmpty()) return "" // There is no upper bound. Fall back to the empty string + val lastIdx = next.indices.last + next[lastIdx] = (next[lastIdx] + 1) + return next.toString() + } + } |