Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.uchuhimo.collections.BiMap
- import com.uchuhimo.collections.toBiMap
- val eng = "~!@#$%^&*()QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?`qwertyuiop[]asdfghjkl;'zxcvbnm,./"
- val ru = "Ё!\"№;%:?*()ЙЦУКЕНГШЩЗХЪ/ФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,ёйцукенгшщзхъфывапролджэячсмитьбю."
- val biMap: BiMap<Char, Char> by lazy {
- eng.zip(ru).toMap().toBiMap()
- }
- fun engToRus(string: String) = string.map { biMap[it] ?: it }.joinToString("")
- fun rusToEng(string: String): String {
- val inv = biMap.inverse
- return string.map { inv[it] ?: it }.joinToString("")
- }
Add Comment
Please, Sign In to add comment