[erlang-questions] unicode + version < 17.0

José Valim jose.valim@REDACTED
Thu Apr 17 17:19:33 CEST 2014

When you say input, do you mean the standard input? If so, you can set the
IO device to be unicode explicitly:

    ok = io:setopts(standard_io, [binary,{encoding,utf8}])
    ok = io:setopts(standard_error, [{unicode,true}])

This works if you are only reading and writing to standard io and standard

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).

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.

*José Valim*
Skype: jv.ptec
Founder and Lead Developer

On Thu, Apr 17, 2014 at 5:07 PM, Benoit Chesneau <bchesneau@REDACTED>wrote:

> Hi all,
> I have a library where the input to the function should be given as utf8.
> Inputs can be:
> "http://www.詹姆斯.com/atomtests/iri/<http://www.xn--8ws00zhy3a.com/atomtests/iri/>
> 詹.html"
> <<"http://www.詹姆斯.com/atomtests/iri/<http://www.xn--8ws00zhy3a.com/atomtests/iri/>
> 詹.html"/utf8>>
> or sometimes <<"http://www.詹姆斯.com/atomtests/iri/<http://www.xn--8ws00zhy3a.com/atomtests/iri/>
> 詹.html">>
> 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
> From a discussion on IRC, I found I can easily convert a string to unicode
> using the following function:
>      UnicodeURL = case unicode:characters_to_binary(URL, InEnc) of
>          URL1 when is_binary(URL1) ->
>               URL1
>          _ ->
>               unicode:characters_to_binary(list_to_binary(URL))
>       end
> It also works on R16B if I set the source code encoding with the file
> header `%% -*- coding: utf-8 -*-`.
> But how to handle it when the source code encoding is latin1? How to
> handle it in version < R16B? Is this possible?
> If not, can we disable functions depending of an Erlang version in a
> module?
> Any help is appreciated :)
> - benoit
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140417/53cb4495/attachment.htm>

More information about the erlang-questions mailing list