Skip to content

Instantly share code, notes, and snippets.

@xrrocha
Created December 16, 2020 17:26
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 xrrocha/d6af00bab954210e27110f56f04e4dac to your computer and use it in GitHub Desktop.
Save xrrocha/d6af00bab954210e27110f56f04e4dac to your computer and use it in GitHub Desktop.
code block for README-26
package wscrambler
object WordScrambler {
// Regex compiled only once:
// at object initialization.
// Inaccessible to others,
// even in the same package.
private val WORD_REGEX =
"""\p{IsLatin}(\p{IsLatin})\1*(?!\1)\p{IsLatin}\p{IsLatin}+"""
.toRegex()
fun scrambleWords(text: String):String {
// scrambling logic goes here...
}
} // object WordScrambler
// more package stuff ...
fun main() {
// Function called w/qualified name
println(WordScrambler.scrambleWords(
"I'm two with nature ― Woody Allen"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment