[erlang-questions] Charset conversion / stylistic question.

Ulf Wiger ulf@REDACTED
Wed Apr 18 20:06:38 CEST 2007


2007/4/18, Tim Becker <tim.becker@REDACTED>:
>
> Hmmm,
> thanks for the replies, I was worried more about how to implement the
> conversion functions per se and completely overlooked the aspect of
> tail recursion.


Well, that part was fine. (:
You could also write a multibyte-capable version
like so:

map_1(F, Bin) ->
  {C, Rest} = F(Bin),
  [C | map_1(F, Rest)];
map_1(F, <<>>) -> [].

where e.g. F could call:

cp037_to_iso8859_1 (<<129:1, Rest/binary>>) -> {97,Rest}; % a
...

Then, your conversion fun could select as many bytes
as it needs to.

BR,
Ulf W
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070418/46f7d084/attachment.htm>


More information about the erlang-questions mailing list