Archive: TRIM function from the documentation.


TRIM function from the documentation.
In the documentation that comes with NSIS can be found a function called TrimNewLines. Has anyone ever passed that function a string that doesn't contain a trailing CRLF (or any variant thereof)? The results that I've experienced indicate that given a string with no trailing CR or LF characters, the function will quite happily return a null string.

Maybe it's the way I'm invoking it, but I don't think so. In the following, the function's renamed TrimCRLF and my string is in R1:

push $R1
call TrimCRLF
pop $R1

That's all that I'm doing to use it. Attached is the old code and revised code that seems to fix the problem. The problem seems to be that if CR or LF are not found, it decides to return a string of MaxLen 0.


The same as this:

Function TrimNewlines
Exch $R0
Push $R1
Push $R2
StrCpy $R1 0
loop:
IntOp $R1 $R1 - 1
StrCpy $R2 $R0 1 $R1
StrCmp $R2 "$\r" loop
StrCmp $R2 "$\n" loop
IntOp $R1 $R1 + 1
StrCmp $R1 0 +2
StrCpy $R0 $R0 $R1
Pop $R2
Pop $R1
Exch $R0
FunctionEnd


-Stu

Thanks, but this has already been fixed in the latest CVS version.

For more information about the latest CVS version see this page. Note that your script might require some changes when updating to the latest CVS version.