<div dir="ltr">When you say input, do you mean the standard input? If so, you can set the IO device to be unicode explicitly:<div><br></div><div> ok = io:setopts(standard_io, [binary,{encoding,utf8}])</div><div> ok = io:setopts(standard_error, [{unicode,true}]) </div>
<div><br></div><div>This works if you are only reading and writing to standard io and standard error.</div><div><br></div><div>If working with files, you must pass the unicode option when opening the file and if you want to have unicode filenames, you need to pass them as binaries (or be sure to start the VM with one of the +fnu flags).</div>
<div><br></div><div>file:get_cwd, init:get_arguments and os:cmd may also have different behaviour depending on the OS before R17. For those cases, you need to do a proper translation using file:native_name_encoding() or alternatively just set the +fnu flag on boot as well.</div>
</div><div class="gmail_extra"><br clear="all"><div><div><br></div><div><br></div><div><span style="font-size:13px"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b>José Valim</b></span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><div><span style="font-family:verdana,sans-serif;font-size:x-small"><a href="http://www.plataformatec.com.br/" style="color:rgb(42,93,176)" target="_blank">www.plataformatec.com.br</a></span></div>
<div><span style="font-family:verdana,sans-serif;font-size:x-small">Skype: jv.ptec</span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Founder and Lead Developer</span></div></span></div></span></div>
</div>
<br><br><div class="gmail_quote">On Thu, Apr 17, 2014 at 5:07 PM, Benoit Chesneau <span dir="ltr"><<a href="mailto:bchesneau@gmail.com" target="_blank">bchesneau@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Hi all,<div><br></div><div>I have a library where the input to the function should be given as utf8.</div><div><br></div><div>Inputs can be:</div><div><br></div><div>"<a href="http://www.xn--8ws00zhy3a.com/atomtests/iri/" target="_blank">http://www.詹姆斯.com/atomtests/iri/</a>詹.html"<br>
</div><div><br></div><div><<"<a href="http://www.xn--8ws00zhy3a.com/atomtests/iri/" target="_blank">http://www.詹姆斯.com/atomtests/iri/</a>詹.html"/utf8>></div><div><br></div><div>or sometimes <<"<a href="http://www.xn--8ws00zhy3a.com/atomtests/iri/" target="_blank">http://www.詹姆斯.com/atomtests/iri/</a>詹.html">></div>
<div><br></div><div>The library I am using should be compatible with the Erlang R15 to 17.0 versions and I wonder if there is a graceful way to handle inputs depending on the Erlang version</div><div><br></div><div>From a discussion on IRC, I found I can easily convert a string to unicode using the following function:</div>
<div><br></div><div> UnicodeURL = case unicode:characters_to_binary(URL, InEnc) of<br></div><div><div> URL1 when is_binary(URL1) -></div><div> URL1</div><div> _ -><br></div><div> unicode:characters_to_binary(list_to_binary(URL))</div>
<div> end</div></div><div><br></div><div>It also works on R16B if I set the source code encoding with the file header `%% -*- coding: utf-8 -*-`. </div><div><br></div><div>But how to handle it when the source code encoding is latin1? How to handle it in version < R16B? Is this possible?</div>
<div><br></div><div>If not, can we disable functions depending of an Erlang version in a module?</div><div><br></div><div><br></div><div>Any help is appreciated :)</div><span class="HOEnZb"><font color="#888888"><div><br>
</div><div>- benoit</div><div><br></div><div>
<br></div></font></span></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>