Erlang - Eccentricity with accented characters and string literal
I am trying to implement a function to differentiate between french vowels and consonnants. It should be trivial, let's see what I wrote down :
-define(vowels,"aeiouyàâéèêëôù").
is_vowel(Char) -> C = string:to_lower(Char),
lists:member(C,?vowels).
It's pretty simple, but it behaves incorrectly :
2> char:is_vowel($â).
false
While the interpreted version works well :
3> C = string:to_l开发者_如何学JAVAower($â), lists:member(C,"aeiouyàâéèêëôù").
true
What's going on ?
The most likely thing here is a conflict of encodings. Your vowels list in the compiled code is using different character values for the accented characters. You should be able to see this by defining acirc() -> $â.
in your compiled code and looking at the number output by calling char:acirc().
versus $â.
in the interpreter. I think that the compiler assumes that source files are in ISO-Latin-1 encoding, but the interpreter will consult your locale settings and use that encoding, probably UTF-8 if you're on a modern linux distro. See Using Unicode in Erlang for more information.
精彩评论