Last active
May 5, 2023 09:56
-
-
Save mike-neck/d813b54513a99881eeffeff34c382f3f to your computer and use it in GitHub Desktop.
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.nio.charset.StandardCharsets | |
import java.nio.charset.Charset | |
def string = 'おっぱい - うほ' | |
def bytes = string.getBytes(StandardCharsets.UTF_8) | |
def toString = {byte[] bs, Charset cs -> new String(bs, cs) } | |
def toBytes = {String s, Charset cs -> s.getBytes(cs) } | |
def charsets = [StandardCharsets.UTF_8, StandardCharsets.UTF_16, StandardCharsets.ISO_8859_1, Charset.forName('Shift-JIS'), Charset.forName('EUC-JP'), Charset.forName('ISO-2022-JP')] | |
def iso8859_1 = [StandardCharsets.ISO_8859_1] | |
charsets.collect {c1 -> | |
iso8859_1.collect {c2 -> | |
def result = c1 == c2 ? '--' : toString(toBytes(string, c1), c2) | |
[from : c1.displayName(), to: c2.displayName(), result: result] | |
}.collect { "${it.from} -> ${it.to} : ${it.result}" }.join(' | ') | |
}.each { println it } |
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
UTF-8 -> ISO-8859-1 : ãã£ã±ã - ãã» | |
UTF-16 -> ISO-8859-1 : þÿ0J0c0q0D - 0F0{ | |
ISO-8859-1 -> ISO-8859-1 : -- | |
Shift_JIS -> ISO-8859-1 : ¨ÁÏ¢ - ¤Ù | |
EUC-JP -> ISO-8859-1 : ¤ª¤Ã¤Ñ¤¤ - ¤¦¤Û | |
ISO-2022-JP -> ISO-8859-1 : $B$*$C$Q$$(B - $B$&$[(B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment