[erlang-questions] misultin / unicode

Slav Pankratov gnoblin@REDACTED
Fri Sep 2 13:02:30 CEST 2011


Roberto, thanks!

Antoine,
yes in my case
~ts helps together with unicode:characters_to_list(list_to_binary())
(and it seems I have latin1 text coming in, not unicode - my mistake!)

thanks,
Slav

2011/9/2 Antoine Koener <antoine.koener@REDACTED>

> On Thu, Sep 1, 2011 at 10:21 PM, Roberto Ostinelli <roberto@REDACTED>
> wrote:
> >
> >
> > 2011/9/1 Slav Pankratov <gnoblin@REDACTED>
> >>
> >> Hello!
> >>
> >>
> >>
> >>
> >> I'm using misultin to receive http calls, and they sometimes contain
> >> Russian symbols (unicode).
> >>
> >>
> >>>
> >>>
> >>> % handle a GET on /users/{username}
> >>>
> >>>
> >>> handle('GET', ["users", UserName], Req) ->
> >>>
> >>>
> >>>         io:format("~s~n", [UserName]),
>
> I may be completely wrong but: try with ~ts instead of ~s in your io:format
>
>
> >>>
> >>>
> >>>     Req:ok([{"Content-Type", "text/plain"}], "This is ~s's page.",
> >>> [UserName]);
> >>
> >>
> >>
> >>
> >> In both terminal and browser I see incorrect output - what can be done
> >> about it?
> >>
> >> big thanks,
> >> Slav
> >
> > hi slav,
> >
> > this is not particularly related to misultin. when using uri you need to
> > ensure that these are properly encoded for HTTP. You also need to ensure
> > that the browser is rendering html encoded in UTF-8 so you should have in
> > your code:
> >
> > % handle a GET on /users/{username}
> > handle('GET', ["users", UserName], Req) ->
> >     Req:ok([{"Content-Type", "text/html; charset=UTF-8"}], "This is ~s's
> > page.", [UserName]);
> >
> > then, you may serve the page:
> >
> >
> http://localhost:8080/users/%26%231055%3B%26%231088%3B%26%231080%3B%26%231074%3B%26%231077%3B%26%231090%3B
> >
> > that will print;
> >
> > This is Привет's page.
> >
> > you probably also could read into IRI:
> http://tools.ietf.org/html/rfc3987
> >
> > my 2c.
> >
> > r.
> >
> > _______________________________________________
> > 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/20110902/fdce3eaa/attachment.htm>


More information about the erlang-questions mailing list