Skip to content

Instantly share code, notes, and snippets.

@todokr
Created October 9, 2016 03:54
Show Gist options
  • Save todokr/ed7974bd5ff8366d457f3bf39f6c27a0 to your computer and use it in GitHub Desktop.
Save todokr/ed7974bd5ff8366d457f3bf39f6c27a0 to your computer and use it in GitHub Desktop.
import java.io.File
import com.github.tototoshi.csv.CSVWriter
object Mojibake extends App {
val f = new File("./mojibake-patterns.csv")
val writer = CSVWriter.open(f)
val targetString = "入れ替わってる〜!?"
val encodings = List("UTF-8", "EUC_JP", "Shift-JIS", "ISO-2022-JP")
writer.writeRow(List("変換元", "変換先", "結果"))
encodings.map(x => (x, encodings)).toMap.foreach { case (from, to) =>
to.foreach { _to =>
val row = List(from, _to, new String(targetString.getBytes(from), _to))
writer.writeRow(row)
}
}
writer.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment