Skip to content
⌘ NSIS Forum Archive

string functions

117 posts

deguix#
The failure is in Examples\StrFunc.nsi.
But where in the file? I tested and everything passed...

IsCharAlpha needs a char. For this, you can treat the string a struct of some bytes and get the first byte.
I'm not getting this code to work for days. And I already tried that without any luck.

If I were you, I'd prefer keeping the LogicLib code. It's simpler. Why keep two versions? It's more work.
Ok, at least you know how difficult is to create one... I just wanted to keep the original because it doesn't require LogicLib, but if you think so, I'll fix that at night.
kichik#
With the files you've attached, it fails in the uninstaller. I haven't gotten into it to see which line exactly.
deguix#
I attached the example again. It's still working for me normally.

(I should add another thing to the documentation about the "${UnStrFunc}" which was removed)
kichik#
I managed to solve it by passing OpenClipboard the window handle (was giving errors about the thread not having an open clipboard associated with it) and by locking and unlocking the handle returned by GetClipboardData (like in the MSDN example).
deguix#
I managed to solve it by passing OpenClipboard the window handle (was giving errors about the thread not having an open clipboard associated with it) and by locking and unlocking the handle returned by GetClipboardData (like in the MSDN example).
The code I used was mostly copied (only with added comments and united options) from the separated old ${StrClbSet} and ${StrClbGet}. The older versions didn't have the window handle set.

If you are getting errors now, you never tested those before (I think). Can you test if the older StrFunc.nsh version ${StrClbSet} and ${StrClbGet} have this problem?
deguix#
Posted version requiring LogicLib.nsh to be included before including StrFunc.nsh. But there is still the problems about "IsCharAlpha" API and "${StrClb}" with that issue you said. Maybe is better you to fix the issues above as I don't know how to fix them 🙁...
kichik#
The original example had just one test. The new example has many and it usually doesn't fail in the first one. If I add more tests to the original example, it fails too.

Here's an example for IsCharAlpha:
StrCpy $0 "testing... testing... 1 2 3"

System::Call "*(&t${NSIS_MAX_STRLEN} r0) i .r1"
StrCpy $2 $1
loop:
System::Call "*$2(&i1 .r4)"
StrCmp $4 0 done
System::Call "user32::IsCharAlpha(i r4) i .r4"
StrCmp $4 0 0 +3
DetailPrint "$4 - not alpha"
Goto +2
DetailPrint "$4 - alpha"
IntOp $2 $2 + 1
Goto loop
done:
System::Free $1
deguix#
I'm going to fix tomorrow morning or night (depending if I have time). But what did you do to result in that code so fast? I think only you and brainsucker (and some other people) knows how to do everything with System plugin.
deguix#
Ok, I've done what you told me. However maybe you should give the code of ${StrClb} that worked with you so I can implement it to the header file. I can't do anything else because on my computer the old example (first published 1.07 example) runs perfectly.

I re-added "<>" (switch) case for ${StrCase} because of the code you gave me on your last post.
kichik#
It would be nicer if you include LogicLib.nsh yourself and not ask the user to do it. There will be no errors if it's included more than once.

You forgot to System::Free call for the allocated buffers in StrCase.

StrClb changes are really simple. Lock and unlock what you get from GetClipboardData and pass $HWNDPARENT and not 0 to OpenClipboard.
deguix#
StrClb changes are really simple. Lock and unlock what you get from GetClipboardData and pass $HWNDPARENT and not 0 to OpenClipboard.
I'm not totally experienced on System plugin (as I implicitly said with "IsCharAlpha"). I think this discussion could be shortned by just posting a simple code like that one you posted for "IsCharAlpha" (as you said it's simple for you and that you done it already).

If I would do the code, then probably in the future I would need to fix something on this code as it could not continue to work on your computer... Sorry if I'm so dumb to understand it completely. 😉
deguix#
Thanks kichik for including your changes to StrFunc.nsh on NSIS 2.01. Everything is working perfectly.
deguix#
New version of StrFunc. The biggest change: all functions from StrFunc are now on LogicLib coding, and comments added on most parts of functions. Second biggest change: StrSort has been changed and can break old scripts. See its documentation. List of changes:

1.08 - 10/12/2004

- Converted all the functions to LogicLib.
- StrSort: Totally remade and it can break old scripts. See documentation for details.
- Added defines: StrFunc_List, *_List and *_TypeList.
- Fixed StrStrAdv: Variables $R0-$R3 couldn't be used on scripts before calling.
- StrRep: Cut down some variables.
- Arranged correctly the order of StrSort on the documentation.
evilO#
Hi Deguix 🙂

I know I haven't been on the forum for a while, I just had tons of work to do (and still no Internet connection at home..).
But I was keeping an eye on your String functions header.. I downloaded the last version... Really nice job 👍 !

Well, I just had 2 problems using the new functions header file (but I didn't test all the functions):
- I had to fix all the "StrTok" calls in my scripts as you decreased the starting index for the "ResultPart" (and to re-test and validate everything 🙁)
- You forgot a "Push $R0 / Pop $R0" in the function "StrTok", the content of $R0 is lost when the function exits

That's all for now.. bye 🙂


evilO/Olive
deguix#
You forgot a "Push $R0 / Pop $R0" in the function "StrTok", the content of $R0 is lost when the function exits
It's even worse than I thought, $9 contents are lost also. Thanks for the information.
deguix#
I didn't even start to work on it. I totally forgot about NSIS 2.02. As there are only small fixes requested this should be completed tomorrow evening or even sooner.
evilO#
Hi Deguix 🙂

Hum I noticed some other small problems with the new version of StrFunc.nsh while I was doing some further testing:


------- StrCase:
An instruction is missing at the beginning of the function (Exch), the contents of $0 and $1 are swapped when the function exits


------- StrClb:
- I couldn't manage to swap strings using "<>", so I modified the function, but you'll probably find a better fix 😁

One thing I didn't understand:
For the operation "<", after the call to "GetClipboardData" there is the handle in $2
For the operation "<>", after the call to "GetClipboardData" there is the string in $2
Why?

- There is a typo in the function's comments:

$0 = Action (input)
$1 = String (input)

should be

$0 = String (input)
$1 = Action (input)

------- StrRep:
An instruction is missing at the end of the function (Pop $R3), the content of $R3 is lost


------- StrSort:
There is a parameter missing in the doc's example


------- StrStrAdv:
The example in the doc is slightly wrong:
${StrStrAdv} $0 "This IS really just an example" "IS " ">" ">" "1" "0" "1" 
returns "IS really just an example" (and not "really just an example" as stated in the doc)

To get the string "really just an example", the example should be
${StrStrAdv} $0 "This IS really just an example" "IS " ">" ">" "0" "0" "1" 

Hum I think that's all I found..
Have a nice day 🙂


evilO/Olive
deguix#
OK, I expected those functions to have bugs, but I didn't think they contained so many of them.

I can see that those are mainly from stack, so I should add to the StrFunc.nsi StrCpy's for each variable, and see if they are swaped when they shouldn't be.
evilO#
Well they didn't contain that much bugs since you rewrote a lot of the code.. 🙂 Moreover, the functions *do* work, as you said it's mainly stack problems..
Well, I spoted them because I had strange behaviors in my installers all of a sudden..
I can see that those are mainly from stack, so I should add to the StrFunc.nsi StrCpy's for each variable, and see if they are swaped when they shouldn't be.
Hum I used a user-defined variable and the "dumpstate" plugin to check the content of the variables, you could do that in a shortened version of StrFunc.nsi to test..

Ah, and have you an answer for my question about "GetClipboardData" ?

Thanks, bye ! 🙂

evilO/Olive

PS: sorry I should have attached the 'nsh' file in the previous post..
deguix#edited
Well they didn't contain that much bugs since you rewrote a lot of the code...
For me one bug is enough to make me fix it, so I say one is a lot.

Hum I used a user-defined variable and the "dumpstate" plugin to check the content of the variables, you could do that in a shortened version of StrFunc.nsi to test..
I'm going to do that because that way it is automatic. This means (about) never this bug will appear again when scripting.

About the documentation, as it is not done automatically, it will probably have typos.

Ah, and have you an answer for my question about "GetClipboardData" ?
Not yet, I have to share the computer with 3 more people so my time is restricted.

(next time attach .nsh files as they are, don't use the extention .txt at the end)
deguix#
String Functions Header File 1.09

I fixed those bugs and some others from other topics posts:

1.09 - 10/22/2004

- Fixed stack problems involving: StrCase, StrRep, StrSort, StrTok.
- Fixed StrClb: When "Action" = "<>", handle was wrongly outputed as text.
- Fixed StrSort, StrStrAdv documentation examples.
- Fixed StrIOToNSIS, StrLoc, StrNSISToIO, StrRep, StrStr: sometimes didn't find "StrToSearch" at all.
evilO#
For me one bug is enough to make me fix it, so I say one is a lot
Well from that point of view of course..
I'm going to do that because that way it is automatic
Ok I didn't understand exactly what you intended to do in the first place..
About the documentation, as it is not done automatically, it will probably have typos
Hum yes just another typo: for the example of "StrSort" I think that
${StrSort} $0 "This is just an example" " just" "" "ple" "0" "0" "0" 
should be
${StrSort} $0 "This is just an example" "" " just" "ple" "0" "0" "0" 
next time attach .nsh files as they are, don't use the extention .txt at the end
Oops I wasn't awake this day, I missed "nsh" in the valid file extensions.. 😁

Bye 🙂 !

evilO/Olive
deguix#
This alternative version has a more compressed code on the header file than this current version. A drawback is the slower speed of compilation for the user. (That's why it's alternative from the current version).

It shows how to make the use of "!system" compile time instruction to bypass the limitation of inclusion of macros inside macros by using the inclusion of external files. (macros can include macros from other files only)

The resulted executable will have the exact size as using the default one.

I'm sad that this approach didn't make my code smaller w/ a decent speed. 🙁
congtak#
Hi,
i have this problem to solve,
I want to remove the very last "\" from a string
example : "C:\abcd\abcd\"
I want to convert this string to "C:\abcd\abcd"

I tried to use

StrLoc $0 "C:\abcd\abcd\" "\" "<"

but $0 = 11 instead of 1
so StrLoc counts the location from the end of string but doesnt start the search from the end of the String so it still gives the first "\" found. Is there any way to solve my problem?

Thanks