This file contains 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
public class WordScrambler { | |
// 4+ letters, 2+ distinct inners | |
// \p{IsLatin} equals [a-zA-ZÀ-ÿ] | |
// Range [À-ÿ]: accented letters | |
private static final Pattern WORD_REGEX = | |
Pattern.compile("\\p{IsLatin}(\\p{IsLatin})\\1*(?!\\1)\\p{IsLatin}\\p{IsLatin}+"); | |
// Scramble words within text |
This file contains 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
package wscrambler | |
import java.io.File | |
// 4+ Latin letters, 2+ distinct inners | |
private val WORD_REGEX = | |
"""\p{IsLatin}(\p{IsLatin})\1*(?!\1)\p{IsLatin}\p{IsLatin}+""" | |
.toRegex() |
This file contains 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
val reader = File(filename).reader() |
This file contains 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
val reader: java.io.InputStreamReader = | |
/*new*/ java.io.File(filename).reader() |
This file contains 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
final var reader = | |
new InputStreamReader( | |
new FileInputStream( | |
new File(filename))); |
This file contains 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
// Collect readers from args/stdin | |
val readers = | |
if (args.isNotEmpty()) | |
args.map { File(it).reader() } | |
else | |
listOf(System.`in`.reader()) | |
// Swallow all readers into one string | |
val content = |
This file contains 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
// Collect readers from args/stdin | |
final Stream<BufferedReader> readers; | |
if (args.length > 0) { | |
readers = Arrays.stream(args) | |
.map(filename -> { | |
try { | |
return new BufferedReader( | |
new FileReader(filename)); | |
} catch (Exception e) { |
This file contains 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
import java.io.*; | |
import java.util.*; | |
import java.util.regex.*; | |
import java.util.stream.*; |
This file contains 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
final var wordRegex = | |
Pattern.compile("\\p{InLatin}{4,}") |
This file contains 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
val wordRegex = | |
"""\p{InLatin}{4,}""".toRegex() |
OlderNewer