HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Detecting if letter is lower or upper case

05-14-2006, 07:35 PM#1
Captain Griffen
EDIT: Ignore this thread, since it appears that a != A in a string comparison (now?). I was under the impression that a == A in WC3. This means that all of this is a complete waste of time; sorry.


I'm not sure if anyone has thought of this before, or indeed if it works, as I cannot test it, but in theory I think it should.

As far as I know, it is thought to be impossible to test if a letter in a string is upper or lower case. If it was possible, it would make save codes a lot shorter.

However, JASS is case sensitive. This means that the function stringA and stringa would be different functions, correct? This means that if we can run a trigger via a string, then we could have functions from a-z and A-Z, with them giving a boolean referring to if it is upper or lower case function.

Since ExecuteFunc takes a string, this could be used to find out if a letter is upper or lower case, if you made the required 52 functions.
05-14-2006, 07:44 PM#2
PipeDream
Collapse JASS:
function IsCharUpper takes nothing returns nothing 
    return c == StringCase(c,true)
endfunction
05-14-2006, 07:51 PM#3
The_AwaKening
NIce, didn't know about that function. Will come in handy.
05-14-2006, 07:57 PM#4
Captain Griffen
Why is that function returning nothing and yet then returns something, which is an undefined variable (I don't know much JASS, but I do know several other programming languages)?

Why do Blizzard add stuff like this and then not tell anyone or put it into the patch notes?

EDIT: Okay, I was a little suspicious, so I checked around, and all StringCase does it turn a string either into upper case or into lower case - which ISN'T the same thing.
05-14-2006, 08:07 PM#5
TaintedReality
What that function does is takes a string c (although it wasn't in Pipe's arguements, guessing he just forgot it). Then, it checks whether c is equal to an all uppercase version of c. If it is, it returns true (therefore being uppercase). If it's not, it returns false (therefore being lowercase).
05-14-2006, 08:15 PM#6
Captain Griffen
Quote:
native StringCase takes string source, boolean upper returns string

Takes a string, turns it to upper/lower case, returns string.
05-14-2006, 08:22 PM#7
PipeDream
I recommend reading common.j. As far as I know StringCase is part of the original RoC API, but shrug.
05-14-2006, 08:22 PM#8
TaintedReality
Collapse JASS:
function IsCharUpper takes string c returns nothing 
    return c == StringCase(c,true)
endfunction

I'm talking about that function. Read it again, I bet you'll get it =P.
05-14-2006, 08:26 PM#9
Captain Griffen
Ahh, yea, sorry, missed the double '=' (silly me). And for your information, that function was new in 1.13.

Do string comparisons actually test for the case? I was under the impression that they didn't, and that testing for the upper or lower case was impossible (hence why upper and lower case letters aren't used in save codes, despite the effectiveness they would have in reducing their length). If it does, then my memory is failing me and this thread is worthless.
05-14-2006, 08:27 PM#10
TaintedReality
Never actually tried, but it would be easy to test.
05-14-2006, 08:30 PM#11
iNfraNe
The jass still isnt correct, it should return a boolean:
Collapse JASS:
function IsCharUpper takes string c returns boolean
    return c == StringCase(c,true)
endfunction
05-14-2006, 08:31 PM#12
Captain Griffen
Can someone test this for me (at present I can't)? Wondering if I'm going insane here...
05-14-2006, 08:35 PM#13
PipeDream
Upper and lower case characters are distinguished. Part of the preprocessing for Aftermath's save system is to StringCase(playername,false).
05-14-2006, 08:39 PM#14
Captain Griffen
Strange, guessing it got changed some time (haven't done anything with save codes for a long time). Or my memory is tricking me. Never mind.
05-15-2006, 04:11 PM#15
The)TideHunter(
Quote:
Originally Posted by iNfraNe
The jass still isnt correct, it should return a boolean:
Collapse JASS:
function IsCharUpper takes string c returns boolean
    return c == StringCase(c,true)
endfunction

That function does return a boolean, return (c == StringCase(c,true))
meaning:

Collapse JASS:
return (c == StringCase(c,true))

is the same as:

Collapse JASS:
if(c == StringCase(c,true)) then
    return true
endif
return false