PDA

View Full Version : LUA Pattern matching issue...



celestian
October 19th, 2020, 21:18
Can anyone see why this:



local nStart, nEnd = string.find(sNoteText,'<linklist>[^<]+<link class="imagewindow" recordname="[^\"]+">[^<]+</link>[^<]+</linklist>',1);


Doesn't match:


<p>Add links below.</p>
<linklist>
<link class="imagewindow" recordname="image.id-00002">Image: tsr</link>
</linklist>


The same code works in FGC so im not sure why it breaks in FGU unless there is some hidden chars in there but even if that the method im using to set barriers should still accommodate that.

For reference here is a similar entry from FGC:


<p>Links here:</p>
<linklist>
<link class="imagewindow" recordname="image.id-00003">wizard-token</link>
</linklist>



(this is one of those places where we REALLY REALLY need actual regular expressions)

damned
October 19th, 2020, 22:25
Can you try matching on:

local nStart, nEnd = string.find(sNoteText,'<link class="imagewindow" recordname="[^\"]+">[^<]+</link>',1);

and see if its the linebreak that is causing the issue?

celestian
October 19th, 2020, 22:41
Can you try matching on:

local nStart, nEnd = string.find(sNoteText,'<link class="imagewindow" recordname="[^\"]+">[^<]+</link>',1);

and see if its the linebreak that is causing the issue?

Unfortunately the way the code works is I need the entire <linklist>...</linklist> piece... that said [^<]+ should process any character (including \r or \n) up until the first < which is <link ...

This would be so much easier if one could use "'<linklist>(.*)?<link class="imagewindow" recordname="(.*)"</link>(.*)?</linklist>'"


That said I can test it and if it is then perhaps the return value from a formattedtext is different in FGU versus FGC.

celestian
October 20th, 2020, 23:07
This looks to be a "bug" or... new way to handle text fields in FGU? If I change the match string to:



local nStart, nEnd = string.find(sNoteText,'<linklist><link class="imagewindow" recordname="[^\"]+">[^<]+</link></linklist>',1);


It matches.... which means the local sNoteText = DB.getValue(nodeStory,"text",""); Removes \n\r now?

IT also seems like getImageSize is no longer valid?



local w = Interface.openWindow("imagewindow",nodeImage);
if w then
local ctrl = w.createControl("image_refblock", "image");
Debug.console("manager_author_adnd.lua","createBlockImage","window (w)",w);
Debug.console("manager_author_adnd.lua","createBlockImage","ctrl",ctrl);
nXOriginal, nYOriginal = ctrl.getImageSize();
nX, nY = getAdjustedImageSize(win,ctrl);
w.close();
end



The above code fails when the values "w" and "ctrl" seem valid.



[10/20/2020 5:09:50 PM] s'manager_author_adnd.lua' | s'createBlockImage' | s'sImageNode' | s'image.id-00002'
[10/20/2020 5:09:50 PM] s'manager_author_adnd.lua' | s'createBlockImage' | s'sImageCaption' | s'Image tsr'
[10/20/2020 5:09:50 PM] s'manager_author_adnd.lua' | s'createBlockImage' | s'nodeImage' | databasenode = { image.id-00002 }
[10/20/2020 5:09:50 PM] s'manager_author_adnd.lua' | s'createBlockImage' | s'window (w)' | windowinstance = { class = imagewindow, node = image.id-00002, x,y,w,h = 658,44,778,765 }
[10/20/2020 5:09:50 PM] s'manager_author_adnd.lua' | s'createBlockImage' | s'ctrl' | genericcontrol = { name = s'image', x,y,w,h = 0,0,0,0 }
[10/20/2020 5:09:50 PM] [<color="red">ERROR</color>] Script execution error: [string "scripts/manager_author_adnd.lua"]:398: attempt to call field 'getImageSize' (a nil value)


Same output in FGC (with the newline pattern) except getImageSize() works.