Erlang standard library quirks

Håkan Stenholm <>
Sun Jan 29 23:10:26 CET 2006


Richard Cameron wrote:

>
> On 29 Jan 2006, at 03:05, James Hague wrote:
>
>> What standard library quirks bug you?
>
>
> to_upper/1 and to_lower/1 are defined in the httpd_util module rather  
> than in string.
>
> I invariably end up re-implementing these functions every time I want  
> to use them, just because I find it criminally perverse to have the  
> words httpd_util:to_upper(Str) in an application which doesn't do  
> anything involving the http protocol.
>
> Richard.
>
Worse is that it only works properly for the ASCII subset of latin-1 
(the char encoding used by erlang), so å, ä, ö, é and similar chars 
won't be case converted at all. See:

===========================================================

otp_src_R10B-8/lib/inets/src/http_server/httpd_util.erl:

%% to_upper

to_upper(Str) ->
    http_util:to_upper(Str).

%% to_lower

to_lower(Str) ->
    http_util:to_lower(Str).

===========================================================


otp_src_R10B-8/lib/inets/src/http_lib/http_util.erl:


to_upper(Str) ->
    to_upper(Str, []).

to_upper([C|Cs], Acc) when C >= $a, C =< $z ->
    to_upper(Cs, [C-($a-$A)| Acc]);
to_upper([C|Cs], Acc) ->
    to_upper(Cs, [C | Acc]);
to_upper([], Acc) ->
    lists:reverse(Acc).

to_lower(Str) ->
    to_lower(Str, []).
to_lower([C|Cs], Acc) when C >= $A, C =< $Z ->
    to_lower(Cs, [C+($a-$A)| Acc]);
to_lower([C|Cs], Acc) ->
    to_lower(Cs, [C| Acc]);
to_lower([], Acc) ->
    lists:reverse(Acc).



More information about the erlang-questions mailing list