![]() |
麻雀は点数計算をマスターするのが結構面倒だったりします。
特に符計算とか細かい条件がありすぎて出来る人に任せっきりだったりします。
しかし、誰もが一度は点数計算覚えてみようかな、と思ったことがあるはず。
そんな時にはぜひこのアプリを使って点数計算をマスターしてください。
![]() |
<html> <head></head> <body onload="startDrawing()"> <canvas id = "canvas1" width="50px" height="60px"></canvas> </body>ライブラリを呼び出すサンプル用のjavascript
function startDrawing(){
tileDrawing.drawCharactor1("canvas1");
}
Charset cs = Charset.forName("Shift-JIS")
cs.encode(new String("エンコードしたい文字"));
public static void sampleEncoder(String target,Charset cs){
/** まずは元のStringデータをCharに分解して確認してみる**/
System.out.print("Original: ");
char[] chars = new char[target.length()];
target.getChars(0,target.length(),chars,0);
for(int i = 0; i < chars.length; i++){
System.out.print((int)chars[i] + " ");
}
System.out.println();
/** 次にStringを指定されたEncodeに変換し、バイト表現を確認する **/
ByteBuffer bf = cs.encode(target);
System.out.print(cs.toString() + ": ");
for(int i = 0 ; i < bf.array().length; i++) {
System.out.print((int)bf.array()[i] + " ");
}
System.out.println();
/** 最後にEncodeした文字を、同じ文字コードで再びDecodeし、Charとしての表現を確認する **/
CharBuffer cb = null;
cb = cs.decode(bf);
StringBuffer sb = new StringBuffer();
System.out.print("Unicode(UTF-16): ");
for(int i = 0 ; i < cb.array().length; i++) {
System.out.print((int)cb.array()[i] + " ");
sb.append(cb.array()[i]);
}
System.out.println(" :" + sb.toString());
System.out.println();
}
public static void main(String args[]){
sampleEncoder("日本語",Charset.forName("ISO-2022-JP"));
sampleEncoder("日本語",Charset.forName("Shift-JIS"));
sampleEncoder("日本語",Charset.forName("EUC-JP"));
}
これの実行結果は次のようになる。Original: 26085 26412 35486 ISO-2022-JP: 27 36 66 70 124 75 92 56 108 27 40 66 Unicode(UTF-16): 26085 26412 35486 0 0 0 :日本語 Original: 26085 26412 35486 Shift_JIS: -109 -6 -106 123 -116 -22 Unicode(UTF-16): 26085 26412 35486 :日本語 Original: 26085 26412 35486 EUC-JP: -58 -4 -53 -36 -72 -20 0 0 0 Unicode(UTF-16): 26085 26412 35486 :日本語
public static void sampleCodingErroAction(String hex, CodingErrorAction actionOnMalformedInput, CodingErrorAction actionOnUnmappableCharacter){
ByteBuffer buff = ByteBuffer.allocate(hex.length()/2);
for (int i = 0; i < hex.length(); i+=2) {
buff.put((byte)Integer.parseInt(hex.substring(i, i+2), 16));
}
buff.rewind();
Charset cs = Charset.forName("shift-jis");
CharBuffer cb = null;
try {
cb = cs.newDecoder()
.onMalformedInput(actionOnMalformedInput)
.onUnmappableCharacter(actionOnUnmappableCharacter)
.decode(buff);
System.out.println(cb.toString());
}catch(Exception e){
System.out.println("error");
}
}
public static void main(String args[]){
String hex1 = "93FA967B8CEA"; //日本語
String hex2 = "93FA967B8C00EA"; //不正な文字
System.out.print("正しいShift-JIS ");//A
sampleCodingErroAction(hex1, CodingErrorAction.IGNORE, CodingErrorAction.IGNORE);
System.out.print("不正なShift-JIS(Ignore) ");//B
sampleCodingErroAction(hex2, CodingErrorAction.IGNORE, CodingErrorAction.IGNORE);
System.out.print("不正なShift-JIS(Replace) ");//C
sampleCodingErroAction(hex2, CodingErrorAction.REPLACE, CodingErrorAction.REPLACE);
System.out.print("不正なShift-JIS(Report) ");//D
sampleCodingErroAction(hex2, CodingErrorAction.REPORT, CodingErrorAction.REPORT);
}
正しいShift-JIS 日本語
不正なShift-JIS(Ignore) 日本
不正なShift-JIS(Replace) 日本��
不正なShift-JIS(Report) error
public void testEncoding(){
String target = "日本語";
Charset cs = Charset.forName("UTF-8");
//Charset cs = Charset.forName("Shift-JIS"); // SHIFT-JISに変換したい場合はこれを使う。
//Charset cs = Charset.forName("EUC-JP");// EUC-JPに変換したい場合はこれを。
//Charset cs = Charset.forName("ISO-2022-JP");//ISO-2022-JPに変換したい場合はこれを。
ByteBuffer bf = cs.encode(target);
try {
File file = new File("output.txt");
FileOutputStream fos = new FileOutputStream(file);
fos.write(bf.array());
fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
なお、正しく出力されているのか確認したい場合はブラウザを使うと手っ取り早い。テキストファイルをブラウザで開き、文字コードを変更することによって希望のエンコーディングがされているか確認できる。