aboutsummaryrefslogtreecommitdiff
path: root/dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFixtures/kotlin/stringUtils.kt
blob: eb8777e75fcfc6d9851bfe9e688331e919e0753c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package org.jetbrains.dokka.dokkatoo.utils


fun String.splitToPair(delimiter: String): Pair<String, String> =
  substringBefore(delimiter) to substringAfter(delimiter)


/** Title case the first char of a string */
fun String.uppercaseFirstChar(): String = mapFirstChar(Character::toTitleCase)


private inline fun String.mapFirstChar(
  transform: (Char) -> Char
): String = if (isNotEmpty()) transform(this[0]) + substring(1) else this


/** Split a string into lines, sort the lines, and re-join them (using [separator]). */
fun String.sortLines(separator: String = "\n") =
  lines()
    .sorted()
    .joinToString(separator)