Comperio
23rd April 2007 04:47 UTC
WordFind bug
This is a function included with NSIS, but I'm not sure whether this would be considered a problem in NSIS or just the external function, so I'll report it here.
To Kichik:
If you feel this should be reported as a bug in NSIS, let me know.
Details
Here's the example code:
OutFile "testme.exe"
ShowInstDetails show
!include WordFunc.nsh
!insertmacro WordFind
!define String "one|two|three|four|five"
Section
DetailPrint "String = ${String}"
DetailPrint '${WordFind} "${String}" "three" "#" $1'
${WordFind} "${String}" "three" "#" $1
DetailPrint "Answer: $1"
Strcpy $1 ""
DetailPrint "Example in manaual:"
DetailPrint '${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " C:\" "#" $1'
${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " C:\" "#" $1
DetailPrint "answer: $1"
SectionEnd
The answer for the first WordFind call returns 2, when it should only be 1. But, the function works fine when you are dealing with paths (from the 2nd WordFind call above)
Instructor
23rd April 2007 08:28 UTC
${WordFind} "${String}" "three" "*" $1
Comperio
23rd April 2007 15:46 UTC
OK, I see the problem:
The docs say "*" is supposed to return the number of delimiters, while "#" is supposed to return the sum of the words.
I can see that your example works and now understand why:
It's because the "*" counts delimiters and it seems that delimiters can never be the first in the list.
So, your example works for the "three", but if I change to look for "one", then it returns the "1" for both.
I still think there's a bug here. If "#" works like is documented, then it should return the same number regardless of whether the item to be searched in in the beginning or middle of the string.
Instructor
23rd April 2007 16:00 UTC
Where is no bug. What you are trying to do?
Comperio
23rd April 2007 17:53 UTC
I'm trying to count how many times a word appears in a delimited list.
also:
To make it clear, your suggestion does work, but doesn't appear to follow the documentation for reasons outlined in my last post.
Comperio
23rd April 2007 18:01 UTC
Nevermind...
I was playing around some more and finally see why:
In my example, "three" is considered a delimiter. So between the delimiter, there are actually 2 "words":
"one|two|" and "|four"
But only one "delimiter":
"three"
I guess it just didn't make sense to me following the examples. But after I read closer the actual description, it finally started to make sense.
Thanks, Instructor.