summaryrefslogtreecommitdiff
path: root/scala/censor.scala
blob: ed9bf0dc4144fb800e86517374b41e81a6c0f5d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import scala.collection.mutable.HashMap

trait Censor {
    var curses = new HashMap[String, String]

    def loadCurses(s: String) = {
        val lines = scala.io.Source.fromFile(s).getLines
        lines.foreach(line => {val kv = line.split('='); curses(kv(0)) = kv(1)})
    }

    def nice(s: String) = {
        var clean = s
        curses.foreach(m => clean = clean.replaceAll(m._1, m._2))
        clean
    }
}

class Repeater extends Censor {
    def repeatForever = {
        while (true)
          println(nice(readLine))
    }
}

val myRepeater = new Repeater
myRepeater.loadCurses("censor.txt")
myRepeater.repeatForever