Created
June 16, 2019 12:28
-
-
Save automationhacks/749a37e569b83e47d8470bdcf3fbf9c1 to your computer and use it in GitHub Desktop.
Moving function as a local func.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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