Skip to content

Instantly share code, notes, and snippets.

@automationhacks
Created June 16, 2019 12:28
Show Gist options
  • Save automationhacks/749a37e569b83e47d8470bdcf3fbf9c1 to your computer and use it in GitHub Desktop.
Save automationhacks/749a37e569b83e47d8470bdcf3fbf9c1 to your computer and use it in GitHub Desktop.
Moving function as a local func.
fun Element.extractText(): String {
val sb = StringBuilder()
fun extractText(e: Element): StringBuilder {
if (e is Text) {
val text = e
sb.append(text.text)
} else if (e is Container) {
val container = e
for (child in container.children) {
extractText(child)
}
} else {
error("Unrecognized element : $e")
}
return sb
}
return extractText(this).toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment