Wishes: hex-output

Erik Reitsma (ELN) Erik.Reitsma@REDACTED
Thu Feb 1 13:23:38 CET 2001


Or alternatively replace 32 with ($a-$A):
 
 ucase([C|Cs]) when C>=$a,C=<$z -> [C-($a-$A)|ucase(Cs)]; % a-z
 ucase([C|Cs])                  -> [C|ucase(Cs)];
 ucase([])                      -> [].
 
 lcase([C|Cs]) when C>=$A,C=<$Z -> [C-($A-$a)|lcase(Cs)]; % A-Z
 lcase([C|Cs])                  -> [C|lcase(Cs)];
 lcase([])                      -> [].
 
 capw([C|Cs]) when C>=$a,C=<$z  -> [C-($a-$A)|lcase(Cs)]; 
 capw(Cs)                       -> lcase(Cs). 

This only relies on $a-$z and $A-$Z being consecutive integer intervals, not on the distance between these intervals (which is 32 in case of ASCII). I just hope that the compiler will optimize $a-$A, otherwise this would require more computation...

*Erik.



More information about the erlang-questions mailing list