Understanding ProcessTextSection?

george
18 Oct 2013, 01:11
As part of working on modifying the UI so output text can be sent to the command line (see viewtopic.php?f=10&t=3961 ) I have some questions about the Core function ProcessTextSection (PTS) if anyone's game.

For reference here's the function:

<function name="ProcessTextSection" type="string" parameters="text, data">
<![CDATA[

containsUnprocessedSection = false

open = Instr(text, "{")

if (open > 0) {
nestCount = 1
searchStart = open + 1
finished = false

while (not finished) {
nextOpen = Instr(searchStart, text, "{")
nextClose = Instr(searchStart, text, "}")

if (nextClose > 0) {
if (nextOpen > 0 and nextOpen < nextClose) {
nestCount = nestCount + 1
searchStart = nextOpen + 1
}
else {
nestCount = nestCount - 1
searchStart = nextClose + 1
if (nestCount = 0) {
close = nextClose
containsUnprocessedSection = true
finished = true
}
}
}
else {
finished = true
}
}
}

if (containsUnprocessedSection) {
section = Mid(text, open + 1, close - open - 1)
value = ProcessTextCommand(section, data)
text = Left(text, open - 1) + value + ProcessTextSection(Mid(text, close + 1), data)
}

return (text)
]]>
</function>


So recall that OutputText calls PTS here,


<function name="OutputText" parameters="text">
<![CDATA[
data = NewDictionary()
dictionary add (data, "fulltext", text)
text = ProcessTextSection(text, data)
OutputTextRaw(text)
]]>
</function>


And from what I understand all msg calls go through OutputText. So my question is pretty basic. Is the purpose of this function to evaluate any expressions (like things in { } ) you've written in your text before they go to output?

jaynabonne
18 Oct 2013, 13:19
Yes, this function handles any text commands (e.g. {cmd:xxxx}, {object:xxx}, etc). It looks for the special { } characters and invokes the text processor for each one.