Hello,
I'm having some weird issues with NumberFormat. I'm using it with the currency pattern, which for my locale is the euro.
The first problem I've notice is that the parser is treating the string " €" as a "positiveSuffix". And if such string is not at the end of the string being parsed, the error "X does not have either positive or negative affixes" is raised. And well, it's normal that such suffix is not there, people won't manually type a space plus the euro symbol. It's ok if such string is added by the format method but it should not be required by the parser.
I guess that's pretty much a bug for NumberFormat, right?
And well, that's not all. After trying to work around this by manually adding the " €" to the end of my numbers, it still raised the same exception. So I decide to debug it, and I saw that, in spite of the correct string being there, the endsWith method was returning false. I just couldn't understand, until I decide to add a watch expression requesting the getBytes() of each string. And what was my surprise when I saw that the blank space character had different bytes in each string being compared! In the "positiveSuffix" variable of NumberFormat, the space character was represented by two bytes, while in my input string, it was only the byte 32. Actually, it seems my input string was using an 8 bit encoding, since only the euro symbol used more than one byte.
These are the strings and their bytes:
The input: "10 €" => [49, 48, 32, -30, -126, -84]
The positiveSuffix: " €" => [-62, -96, -30, -126, -84]
As you see, it seems blank space in the input is 32 while in the positiveSuffix it is [-62, -96].
I'm guessing javascript doesn't give the same guarantee that Java does, that is, that every in memory string uses the same encoding. But, if that's the case, shouldn't GWT try to assure always the same encoding is being used? Because, otherwise, how should we do? I know that we can set encoding for Writers and Readers in Java but for in memory strings, how can we make sure we're always using the same encoding?
Thank you,
--
Tiago Rinck Caveden