Created
January 24, 2015 21:23
-
-
Save m2ym/8a54e58b16e2ecd77af7 to your computer and use it in GitHub Desktop.
libguess を ocaml-ctypes で使ってみる
This file contains hidden or 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
$ sudo apt-get install libguess-dev | |
$ ocamlfind ocamlc -package ctypes.foreign -linkpkg -custom -cclib -lguess -o guess guess.ml | |
$ ./guess "こんにちは世界" | |
UTF-8 | |
$ ./guess $(echo "こんにちは世界" | nkf -Ws) | |
SJIS | |
$ ./guess $(echo "こんにちは世界" | nkf -We) | |
EUC-JP |
This file contains hidden or 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
open Ctypes | |
open Foreign | |
let libguess_determine_encoding = | |
foreign "libguess_determine_encoding" (string @-> int @-> string @-> returning string) | |
let () = | |
let bytes = Sys.argv.(1) in | |
let charset = libguess_determine_encoding bytes (Bytes.length bytes) "Japanese" in | |
print_endline charset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment