Old 17th March 2006, 17:44   #1
cowwoc
Member
 
Join Date: Feb 2005
Posts: 51
Passing in quotes as an argument to a macro

Hi,

I've got a function which takes in a string as an argument. I want to pass in the string '"' -- that is, single quotes.

Problem is NSIS gives me:

Error: unterminated string parsing line at macro:IndexOf:2
Error in macro IndexOf on macroline 2

and my macro is defined as:

!macro IndexOf String SubString StartingIndex Result
Push "${String}"
Push "${SubString}"
Push "${StartingIndex}"
Call IndexOf
Pop "${Result}"
!macroend
!define IndexOf "!insertmacro IndexOf"

So obviously Push "${SubString}" is failing but I have no idea how to fix it. Passing in non-quote characters works fine. I also tried "$\"" as an argument and it fails too.

Gili
cowwoc is offline   Reply With Quote
Old 17th March 2006, 17:47   #2
cowwoc
Member
 
Join Date: Feb 2005
Posts: 51
Using backticks for Push worked, but it feels like a hack. What happens if the input string actually contains backtick characters?
cowwoc is offline   Reply With Quote
Old 17th March 2006, 17:51   #3
dienjd
Senior Member
 
Join Date: Oct 2005
Posts: 189
Does this work for you?
code:

Name "quotetest"
Outfile "quotetest.exe"

!macro test param1
MessageBox MB_OK "${param1}"
!macroend

Section ""
StrCpy $0 '"'
!insertmacro test "$0"
SectionEnd

dienjd is offline   Reply With Quote
Old 17th March 2006, 17:55   #4
cowwoc
Member
 
Join Date: Feb 2005
Posts: 51
Yes, that testcase works. Not sure why Push would fail then...
cowwoc is offline   Reply With Quote
Old 18th March 2006, 09:07   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Tried?
Push '${String}'
Push '${SubString}'
Push '${StartingIndex}'
Call IndexOf
Pop '${Result}'

-Stu
Afrow UK is offline   Reply With Quote
Old 18th March 2006, 16:24   #6
Comm@nder21
Major Dude
 
Join Date: Jul 2003
Location: germany, b-w
Posts: 734
Send a message via ICQ to Comm@nder21
or even use ``

as ' and " are quite common. but nsis supports ` as third quotation mark.
Comm@nder21 is offline   Reply With Quote
Old 18th March 2006, 23:35   #7
cowwoc
Member
 
Join Date: Feb 2005
Posts: 51
My point though is that there should be a way to generally quote a variable without having to know what quotes are used inside. Why can't NSIS know that "$someVar" means that it should get quoted regardless of the type of quotes inside?
cowwoc is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump