|
Comparing Upper/Lower case
Last post 07-16-2007 9:39 AM by ammoQ. 19 replies.
-
07-13-2007 2:17 PM
|
|
-
snoofle


- Joined on 06-22-2006
- Posts 699
|
Comparing Upper/Lower case
Just ran into this - pretty much says it all:
Java:
int compareTo(Object o) {
SomeObject that = (SomeObject) o;
return this.stringField.toLowerCase().toUpperCase().compareTo(that.stringField.toLowerCase().toUpperCase());
}
|
|
-
-
Pap


- Joined on 09-12-2006
- Earf
- Posts 281
|
Re: Comparing Upper/Lower case
It's necessary to absolutely force the case to change, such as when people write their posts with the CAPS LOCK key on instead of shift, which is temporary.
|
|
-
-
misguided


- Joined on 07-12-2007
- Edmonton, AB, Canada
- Posts 109
|
Re: Comparing Upper/Lower case
Yeah, but the WTF is, why would you toLower and then toUpper just to do a compareTo? you're going to get the same state if you run just one of them, running both is mind-boggling. Edit: But the WTF is, why am I posting before fully absorbing sarcasm? Or tags?
|
|
-
-
snoofle


- Joined on 06-22-2006
- Posts 699
|
Re: Comparing Upper/Lower case
I get the purpose for a case-insensitive compare. The point was that the coder forced it to lower and then upper case, when one (or the other) would have sufficed. Edit: Gaaa - Friday 13th - my sarcasm detector is on the fritz!
|
|
-
-
misguided


- Joined on 07-12-2007
- Edmonton, AB, Canada
- Posts 109
|
Re: Comparing Upper/Lower case
snoofle:I get the purpose for a case-insensitive compare. The point was that the coder forced it to lower and then upper case, when one (or the other) would have sufficed. Edit: Gaaa - Friday 13th - my sarcasm detector is on the fritz!
YESSSSS! Not being the only one FTW :)
|
|
-
-
iwpg


- Joined on 05-24-2006
- Posts 258
|
Re: Comparing Upper/Lower case
I think (not certain) this is needed to handle weird Unicode characters for which there isn't a one-to-one mapping between upper-case and lower-case. Java's compareToIgnoreCase method (which they should have used to begin with) does basically the same thing. Of course, it wouldn't hurt to add a comment to that effect....
|
|
-
-
pcooper


- Joined on 03-05-2007
- Posts 5
|
Re: Comparing Upper/Lower case
Yes, as odd as it may seem to native English speakers, not all characters will round-trip between lowercasing and uppercasing. Really, the correct approach is to call your system case-insensitive-comparison function that deals with all that for you, but that may have been a reasonable substitute for the languages they were using if the built-in function didn't have the functionality they were looking for.
Or maybe the programmer just had no clue what they were doing. Really just as likely, but I wouldn't jump to that conclusion just based on this.
|
|
-
-
misguided


- Joined on 07-12-2007
- Edmonton, AB, Canada
- Posts 109
|
Re: Comparing Upper/Lower case
That's wild, but actually makes total sense now that I think about it! The things you learn from laughing at other people's mistakes that aren't mistakes. :$
|
|
-
-
roto


- Joined on 09-01-2006
- Posts 33
|
Re: Comparing Upper/Lower case
pcooper:Yes, as odd as it may seem to native English speakers, not all characters will round-trip between lowercasing and uppercasing. Really, the correct approach is to call your system case-insensitive-comparison function that deals with all that for you, but that may have been a reasonable substitute for the languages they were using if the built-in function didn't have the functionality they were looking for.
Or maybe the programmer just had no clue what they were doing. Really just as likely, but I wouldn't jump to that conclusion just based on this.
Could you give some examples of this? He is using Java and I've never heard of such a thing. I'm not trying to say I've heard it all, just that I'd be interested to know how this issue would relate to a managed environment like Java.
Do you have an extra GOTO 10 line?
|
|
-
-
snoofle


- Joined on 06-22-2006
- Posts 699
|
Re: Comparing Upper/Lower case
iwpg:I think (not certain) this is needed to handle weird Unicode characters for which there isn't a one-to-one mapping between upper-case and lower-case. Java's compareToIgnoreCase method (which they should have used to begin with) does basically the same thing. Of course, it wouldn't hurt to add a comment to that effect....
A completely reasonable guess, but not the case here. This thing uses just the ASCII (albeit in Java) subset of Unicode, so a straight toUpperCase() (or toLowerCase()) on both ends would have handled it, or the compareToIgnoreCase as was also pointed out!
|
|
-
-
pcooper


- Joined on 03-05-2007
- Posts 5
|
Re: Comparing Upper/Lower case
roto: pcooper:Yes, as odd as it may seem to native English speakers, not all characters will round-trip between lowercasing and uppercasing. Really, the correct approach is to call your system case-insensitive-comparison function that deals with all that for you, but that may have been a reasonable substitute for the languages they were using if the built-in function didn't have the functionality they were looking for.
Or maybe the programmer just had no clue what they were doing. Really just as likely, but I wouldn't jump to that conclusion just based on this.
Could you give some examples of this? He is using Java and I've never heard of such a thing. I'm not trying to say I've heard it all, just that I'd be interested to know how this issue would relate to a managed environment like Java.
One example that I know of is that the letter "ß" has an uppercase of "SS", which can have a lowercase of "ss". I believe there are others as well, but as I'm only a fluent speaker of English, I don't really know all the cases offhand. I just know that casing, comparison, and collation aren't nearly as simple as one might think at first.
|
|
-
-
Licky Lindsay


- Joined on 12-22-2006
- Posts 47
|
Re: Comparing Upper/Lower case
None of this excuses him for not using equalsIgnoreCase().
"If you’re in a corporation – the EVE version of guilds – this opens up the option of warfare."
|
|
-
-
Random832


- Joined on 05-09-2007
- Posts 482
|
Re: Comparing Upper/Lower case
I thought "SS" had a lowercase of "B" - as in ClaBic.
|
|
-
-
aihtdikh


- Joined on 02-07-2006
- Posts 53
|
Re: Comparing Upper/Lower case
Random832:I thought "SS" had a lowercase of "B" - as in ClaBic.
I was thinking "SS" lowercased to "butt", although I can't account for the A
|
|
-
-
wolff


- Joined on 07-14-2007
- Posts 7
|
Re: Comparing Upper/Lower case
snoofle:A completely reasonable guess, but not the case here. This thing uses just the ASCII (albeit in Java) subset of Unicode
Doesn't matter: In Turkish, the uppercase of " i " would be " İ " (U+0130) - and the lower case of " I " is " ı ".
|
|
-
-
db2


- Joined on 06-15-2006
- Posts 179
|
Re: Comparing Upper/Lower case
aihtdikh: Random832:I thought "SS" had a lowercase of "B" - as in ClaBic.
I was thinking "SS" lowercased to "butt", although I can't account for the A
The 'a' is elided. I think it's a dialectical thing.
|
|
-
-
asuffield


- Joined on 05-31-2006
- Posts 2,137
|
Re: Comparing Upper/Lower case
pcooper:
One example that I know of is that the letter "ß" has an uppercase of "SS", which can have a lowercase of "ss". I believe there are others as well
The other ones in unicode aren't used in any modern languages (most of them are obscure ancient greek junk that nobody uses). Eszett is the bastard that makes case folding difficult. There are a number of words in German that become different words if you convert them to uppercase and then to lowercase. A number of solutions have been proposed, but they're all very involved. The best one so far is to cut off all internet access to Germany and pretend that they don't exist.
|
|
-
-
ammoQ


- Joined on 04-13-2005
- Vienna.Austria.Europe.Earth
- Posts 3,461
|
Re: Comparing Upper/Lower case
asuffield:The other ones in unicode aren't used in any modern languages (most of them are obscure ancient greek junk that nobody uses). Eszett is the bastard that makes case folding difficult. There are a number of words in German that become different words if you convert them to uppercase and then to lowercase. A number of solutions have been proposed, but they're all very involved. The best one so far is to cut off all internet access to Germany and pretend that they don't exist.
You forget that us Austrians use the ß, too. ;-) The most obvious solution is to switch to Swiss German - they simply got rid of the ß and write ss in all occurences instead. I know of only one word where the meaning changes when the ß is replaced with the ss: Masse (mass) vs. Maße (dimensions)
beanbag girl 4ever
|
|
-
-
Thief^


- Joined on 12-06-2006
- Posts 290
|
Re: Comparing Upper/Lower case
ammoQ:I know of only one word where the meaning changes when the ß is replaced with the ss: Masse (mass) vs. Maße (dimensions)
What's the difference in pronunciation?
|
|
-
-
ammoQ


- Joined on 04-13-2005
- Vienna.Austria.Europe.Earth
- Posts 3,461
|
Re: Comparing Upper/Lower case
Thief^: ammoQ:I know of only one word where the meaning changes when the ß is replaced with the ss: Masse (mass) vs. Maße (dimensions)
What's the difference in pronunciation?
Maße is spoken with an accented a, Masse with an unaccented a.
beanbag girl 4ever
|
|
Page 1 of 1 (20 items)
|
|
|