Reply
 
Thread Tools Display Modes
Old 11-03-05, 07:03 AM   #1
vincentgdg
A Murloc Raider
Join Date: Sep 2005
Posts: 8
How to scan the command line for an item link with spaces

Hello there.

I am nearly finished with my addon "restack" but now I have a little problem with scanning the command line.

I use a function GetCmd() from somewhere, but that one splits arguments when there is a space in the line.

So when I get a line with a link in it that has space, it breaks.

What I want to have is a function that does the following:

cmdline = "a test" -> returns "a","test"

cmdline = "4231:0:0...[name with spaces] 3" -> returns "4231:0:0...[name with spaces]","3"

I know there must be a very easy regex for this, if I only would be better in this. :-)

Pls help.

Regards
Thomas
vincentgdg is offline   Reply With Quote
Old 11-03-05, 02:20 PM   #2
noraj
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 102
why cant you have each word(characters seperated by space) returned seperatly?

what are you trying to do

I guess you could do

local thiscommandarray =GetCommand()
for key, value in thiscommandarray do
if(not thiscommandstring)and (value) then thiscommandstring = value end
elseif(thiscommandstring) and (value) then thiscommandstring = thiscommandstring.." "..value end
end
DEFAULT_CHAT_FRAME:AddMessage(thiscommandstring)

that should do what you want...dunno if its the best way though
noraj is offline   Reply With Quote
Old 11-04-05, 08:04 PM   #3
Aquendyn
A Deviate Faerie Dragon
Join Date: Sep 2005
Posts: 12
see which pattern match comes first.
Code:
function parseCommand( cmdLine )
local a={}
local linkPat = "|?|H.-|h.-|h";
local wordPat = "%S+";

while ( ""~=gsub(cmdLine, "%s", "") ) do
	local word, link, pattern;
	word = strfind( cmdLine, wordPat);
	link = strfind( cmdLine, linkPat);
	pattern = word and link;
	if ( word and not link or pattern and word < link ) then
		pattern = wordPat;
	else
		pattern = linkPat;
	end
		
	cmdLine = gsub( cmdLine, pattern, function(i)
		table.insert(a, i);
	end, 1 )
end
return a;
end
Aquendyn is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » How to scan the command line for an item link with spaces

Thread Tools
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

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