Skip to content

Instantly share code, notes, and snippets.

@shino
Created October 9, 2014 04:35
Show Gist options
  • Save shino/986cc4300cc34bb95f76 to your computer and use it in GitHub Desktop.
Save shino/986cc4300cc34bb95f76 to your computer and use it in GitHub Desktop.
% $R16B03_1_hipe/bin/erlc utf8_with_magic_comment.erl
% $R16B03_1_hipe/bin/erl -noshell -s utf8_with_magic_comment start -s init stop
===== format by 's'
[bytes]: あ
===== format by 'ts'
[codepoint]: \x{3042}
[bytes]: あ
[string_literal]: \x{3042}
===== format by 'ts' with io:setopts([{encoding, utf8}])
[codepoint]: あ
[bytes]: ã
[string_literal]: あ
%% -*- coding: utf-8 -*-
-module(utf8_with_magic_comment).
-compile(export_all).
start() ->
io:format(" ===== format by 's'~n"),
[catch io:format("[~s]: ~s~n",
[HowToCreate, hiragana_A(HowToCreate)]) ||
HowToCreate <- [codepoint, bytes, string_literal]],
io:format(" ===== format by 'ts'~n"),
[catch io:format("[~s]: ~ts~n",
[HowToCreate, hiragana_A(HowToCreate)]) ||
HowToCreate <- [codepoint, bytes, string_literal]],
io:format(" ===== format by 'ts' with io:setopts([{encoding, utf8}])~n"),
io:setopts([{encoding, utf8}]),
[catch io:format("[~s]: ~ts~n",
[HowToCreate, hiragana_A(HowToCreate)]) ||
HowToCreate <- [codepoint, bytes, string_literal]].
hiragana_A(codepoint) ->
[12354];
hiragana_A(bytes) ->
[227,129,130];
hiragana_A(string_literal) ->
"あ".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment