Skip to content

Instantly share code, notes, and snippets.

@swankjesse
Created December 16, 2020 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swankjesse/0ca615560230db405234fc275f3cfad0 to your computer and use it in GitHub Desktop.
Save swankjesse/0ca615560230db405234fc275f3cfad0 to your computer and use it in GitHub Desktop.
import okio.buffer
import okio.source
/**
* Converts a Kotlin file with `backtick method names` to camelCaseMethodNames.
*/
fun main() {
val source = System.`in`.source().buffer()
while (true) {
val line = source.readUtf8Line() ?: break
val prefix = " fun `"
val suffix = "`() {"
if (!line.startsWith(prefix) || !line.endsWith(suffix)) {
System.out.println(line)
continue
}
val words = line.substring(prefix.length, line.length - suffix.length).split(" ")
val camelWords = words[0] + (words.subList(1, words.size).joinToString(separator = "") { word ->
word.substring(0, 1).toUpperCase() + word.substring(1)
})
System.out.println(" fun ${camelWords}() {")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment