diff options
author | Linnea Gräf <nea@nea.moe> | 2024-11-18 20:53:20 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-11-18 20:53:20 +0100 |
commit | 139fa705b36b845759cff9318191ff1cca526f2a (patch) | |
tree | a8e297627a078ac97abe03f0e56ea7e3744db042 /src/main/kotlin/util/StringUtil.kt | |
parent | d37d13dacad45af717e1f97488e739ef617fd89d (diff) | |
download | Firmament-139fa705b36b845759cff9318191ff1cca526f2a.tar.gz Firmament-139fa705b36b845759cff9318191ff1cca526f2a.tar.bz2 Firmament-139fa705b36b845759cff9318191ff1cca526f2a.zip |
feat: Add Storage overlay search
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() + } + } |