Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
17th February 2011, 19:37 | #1 | Link |
Registered User
Join Date: Feb 2010
Location: New York
Posts: 116
|
Is FindStr() intentionally case sensitive?
At Gavino's suggestion, I'm starting a thread here to get some clarification.
While testing a recent update to a script of mine, I traced some unexpected behavior to the apparent case sensitivity of FindStr(). While I'd think such a feature might be useful to some people, it seems inconsistent with the other string functions (LeftStr, MidStr, RightStr, all case insensitive) and, as Gavino noted, the logical operators as applied to strings. Beyond that, the example in the documentation, calling FindStr("AviSynth","syn") and getting a return value of 4, doesn't work; the function returns 0, unless I capitalize the 's' in "syn". I've found this happens in 2.5.6, 2.5.7, 2.5.8, SEt's 2.5.8MT, and the September 27th, 2009 2.6.0 alpha. I've been able to avoid the issue in my own script by way of calling LCase() on strings before comparing them, but I'm still curious: is this sensitivity by design, and only a mixup in the docs, or is it an actual bug? |
17th February 2011, 22:05 | #2 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
FindStr() has always used strstr so I guess it is by design. Some libc support the strcasestr() function, but it is a non-standard extension.
Functions like LeftStr are case agnostic rather than insensitive. I guess the doco example was a typo, I have fixed it in CVS. I am more concerned that == is case insensitive and there is no case sensitive alternative, but no-one has had an issue until now. Given the tools LCase() or UCase() you can build case insensitive versions from case sensitive comparisons, but give case insensitive comparisons you cannot build case sensitive ones. Code:
AVSValue FindStr(AVSValue args, void*, IScriptEnvironment* env) { const char *pdest; int result; pdest = strstr( args[0].AsString(),args[1].AsString() ); result = pdest - args[0].AsString() +1; if (pdest == NULL) result = 0; return result; } Code:
AVSValue ExpEqual::Evaluate(IScriptEnvironment* env) { AVSValue x = a->Evaluate(env); AVSValue y = b->Evaluate(env); ... else if (x.IsString() && y.IsString()) { return !lstrcmpi(x.AsString(), y.AsString()); } ... |
17th February 2011, 22:58 | #3 | Link |
Registered User
Join Date: Feb 2010
Location: New York
Posts: 116
|
Oh, I'm not really affected by it, I was only wondering. I just happened to realize that in all of my testing for previous releases of SimpleSlugUpscale, I'd been typing strings the way I'd intended them to be typed. "DVwidepNTSC", for example. Something compelled me to try it all lowercase this time, and when I did I got output that wasn't sized correctly, ultimately leading me to my use of FindStr().
I haven't gotten any complaints about it from users, but I made sure with version 1.10 to convert to lower case before checking the strings, just in case. I'm sure it's nothing to worry about, if no one else has said anything, but thank you for clearing that up and updating the documentation! |
18th February 2011, 00:31 | #4 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
StrLen(A) == StrLen(B) && FindStr(A, B) == 1 Not-equals is obviously the converse, but case-sensitive comparisons like "<" are still impossible. |
|
Tags |
case, findstr, sensitive |
Thread Tools | Search this Thread |
Display Modes | |
|
|