Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #213 Case-insensitive string compare

Compare four strings in pair-wise variations. The string comparison can be implemented with an equality test or a containment test, must be case-insensitive and must apply Unicode casefolding.

code (C) when $a =< C andalso C =< $z -> C - $a;
code (C) when $A =< C andalso C =< $Z -> C - $A;
code(C) -> C.

isSame([C | Rest1], [C | Rest2]) when is_integer(C)->
        isSame(Rest1, Rest2);
isSame([C1 | Rest1], [C2 | Rest2]) ->
        case (code(C1) - code(C2)) of
                0 -> isSame(Rest1, Rest2);
                _ -> false
        end;
isSame([], []) -> true;
isSame(_, _) -> false.

with tail call optimization

New implementation...