View Full Version : String comparison oddness...
maxxon
19th February 2012, 08:33
global output__junk = BlankClip(height=0, width=0, length=0)
global output__filename = "output.log"
function output(string s)
{
output__junk.WriteFileStart(output__filename, "s", append=true)
return 1
}
output("chr(1) == chr(2) = "+(chr(1) == chr(2)).string)
output("chr(1) < chr(2) = "+(chr(1) < chr(2)).string)
output("chr(1) > chr(2) = "+(chr(1) > chr(2)).string)
output("strcmp(chr(1), chr(2)) = "+strcmp(chr(1), chr(2)).string)
The result of the output.log file is very odd...
chr(1) == chr(2) = true
chr(1) < chr(2) = true
chr(1) > chr(2) = false
strcmp(chr(1), chr(2)) = 0
Also I've also noticed that strcmp is not doing as it says it is supposed to on the Internal functions/String functions (http://avisynth.org/mediawiki/Internal_functions/String_functions) page. According to that page this:
output(strcmp("A", "C").string)
should generate a -2. It generates a -1.
VersionString == "AviSynth 2.60, build:May 25 2011 [19:58:41]"
|\/|x
IanB
19th February 2012, 10:19
My result in output.log ischr(1) == chr(2) = false
chr(1) < chr(2) = true
chr(1) > chr(2) = false
strcmp(chr(1), chr(2)) = -1And of course loading the script results in the expectedError: Avisynth open failure:
The script's return value was not a video clip.It's the integer 1 from the last function output's return value, but that does not matter here.
Not at all sure why you are getting those results, lstrcmpi is language aware, maybe, what language is your windows?
As for the -2 versus -1, the documentation seems to be stretching to the implementation a little.
The code is actually using :-AVSValue StrCmp(AVSValue args, void*, IScriptEnvironment* env)
{
return lstrcmp( args[0].AsString(), args[1].AsString() );
}
lstrcmp function
.....
Return value
Type: int
If the string pointed to by lpString1 is less than the string pointed to by lpString2, the return value is negative. If the string pointed to by lpString1 is greater than the string pointed to by lpString2, the return value is positive. If the strings are equal, the return value is zero. (http://msdn.microsoft.com/en-us/library/windows/desktop/ms647488(v=vs.85).aspx)So according to the M$ docs you can only rely on the return being positive, negative or zero. Most strcmp code does actually return the difference of the last comparison, seems lstrcmp does not.
maxxon
20th February 2012, 05:32
My result in output.log ischr(1) == chr(2) = false
chr(1) < chr(2) = true
chr(1) > chr(2) = false
strcmp(chr(1), chr(2)) = -1And of course loading the script results in the expectedError: Avisynth open failure:
The script's return value was not a video clip.It's the integer 1 from the last function output's return value, but that does not matter here.
Not at all sure why you are getting those results, lstrcmpi is language aware, maybe, what language is your windows?
Interesting, are you using the same version? It also could be a wine issue (I'm running under Ubuntu).
EDIT: yeah, wine and lstrcmpi (http://wine.1045685.n5.nabble.com/Bug-10767-New-lstrcmp-and-others-do-not-compare-punctuation-characters-correctly-td1535516i20.html) seems to be the problem. Though I don't understand why chr(1) was both equal and less than chr(2) simultaneously. :confused:
As for the -2 versus -1, the documentation seems to be stretching to the implementation a little.
The code is actually using :-AVSValue StrCmp(AVSValue args, void*, IScriptEnvironment* env)
{
return lstrcmp( args[0].AsString(), args[1].AsString() );
}
So according to the M$ docs you can only rely on the return being positive, negative or zero. Most strcmp code does actually return the difference of the last comparison, seems lstrcmp does not.
Yeah, I was figuring as much.
Is there some sort of ORD or ASC function considered?
|\/|x
IanB
20th February 2012, 21:59
Yep, we can add an ORD(String Arg)
I guess just return the first char of a string as an integer.
And I guess we should really stop using lstrcmp(i), it's been on the to do list forever.
maxxon
21st February 2012, 22:34
Well, it isn't bad if you are using multilingual character sets, but you appear only to use ASCII so it isn't really that useful.
pbristow
27th February 2012, 16:29
Any chance we could change the thread title to "String comparison oddness", or somesuch...? Just the help future archaeologists make sense of things, y'understand. :)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.