Commit ba5636d2 authored by Benito van der Zander's avatar Benito van der Zander

add clear-log, get-log functions

parent 79f17006
......@@ -4,7 +4,9 @@ Some important changes:
--------Xidel 0.9.7 --------
- fix system(), file:exists, file:move (override), file:path-to-uri on Windows
- Cookie handling follows RFC 6265 rather than sending all cookies to all servers.
- further minor bug fixes
- add t:siblings-header/siblings elements to pattern matcher to match certain element siblings regardless of their ordering (e.g. table columns).
- add functions x:call-action, x:get-log, x:clear-log to give programatical access to multipage templates and variable changelog.
- further minor bug fixes and performance improvements
--------Xidel 0.9.6 --------
(2016-11-20)
......
This diff is collapsed.
......@@ -200,8 +200,6 @@ Important extensions are:
eval("xpath") This will evaluate the string "xpath" as an XPath/XQuery expression
system("..") Runs a certain program and returns its stdout result as string
read() Reads a line from stdin
deep-text() This is the concatenated plain text of the every tag inside the current text.
You can also pass a separator like deep-text(' ') to separate text of different nodes.
inner-html() This is the HTML content of node ., like innerHTML in javascript.
outer-html() This is the same as inner-html, but includes the node itself
inner-xml() This is the XML content of node, similar to inner-html()
......@@ -229,6 +227,8 @@ Important extensions are:
<a>FOO</a> and <a>BAR</a>.
The template can be a node or a string. Written as string the above example would be
match("<a>{.}</a>", <x><a>FOO</a><a>BAR</a></x>).
x:call-action($name)
Calls the action of a multipage template.
transform(node, transformer-function)
This function can perform an arbitrary transformation of a document, by calling the
transformer-function for every descendant node and replacing the node with the value returned by the function.
......@@ -247,6 +247,12 @@ Important extensions are:
Converts a string to an integer. It accepts base-prefixes like 0x or 0b, e.g 0xABCDEF
x:integer-to-base($i, $base)
Converts an integer to a certain base
x:clear-log([$name])
Removes variables.
x:get($name, [$default])
Gets the value of a variable, or $default if the variable does not exist.
x:get-log([$name])
Gets every value a variable had.
Additional functions without prefix are in the pxp: namespace, which is also set as default namespace.
......
a := 1
a := 2
b := 3
t := {"name": "a", "value": 1}
{"name": "a", "value": 2}
{"name": "b", "value": 3}
u := a
[1]
[2]
b
[3]
c
a := 1
a := 2
c := 4
t := {"name": "a", "value": 1}
{"name": "a", "value": 2}
{"name": "c", "value": 4}
u := a
[1]
[2]
b
c
[4]
b := 3
c := 4
t := {"name": "b", "value": 3}
{"name": "c", "value": 4}
u := a
b
[3]
c
[4]
......@@ -421,6 +421,9 @@ tests/test.sh moduleFuncImportRel -e 'import module namespace rename = "pseudo:/
tests/test.sh moduleFuncImportRel --extract-file tests/subdir/test.xq
tests/test.sh moduleFuncImportRel tests/subdir/test.xq
tests/test.sh varlogBC -e 'x:clear-log(),a:=1,a:=2,b:=3,c:=4,x:clear-log("a"), t:=x:get-log(), u:=("a","b","c")!(.,x:get-log(.))'
tests/test.sh varlogAC -e 'x:clear-log(),a:=1,a:=2,b:=3,c:=4,x:clear-log("b"), t:=x:get-log(), u:=("a","b","c")!(.,x:get-log(.))'
tests/test.sh varlogAB -e 'x:clear-log(),a:=1,a:=2,b:=3,c:=4,x:clear-log("c"), t:=x:get-log(), u:=("a","b","c")!(.,x:get-log(.))'
#interpreter tests
tests/test.sh utf8 -e 'substring("äbcd",1,3)'
......
......@@ -28,7 +28,7 @@ Serializes a value as JSON, i.e. converts the value to JSON and converts that to
<f name="extract" args="($string as xs:string, $regex as xs:string [, $match as xs:integer *,[$flags as xs:string]])">
This applies the regex $regex to $string and returns only the matching part. This returns basically what the program grep would return. <br/>
If the $match argument is provided, only the $match-th submatch will be returned. This can be a sequence of several integers.<br/>
If flags contains *, all occurrences are returned.<br>
If flags contains *, all occurrences are returned.<br/>
Otherwise the regex and flags parameters behave identical to the parameters of <a>fn:matches</a> and <a>fn:replace</a>.
</f>
......@@ -86,7 +86,7 @@ Parses an HTML document similar to <a>fn:parse-xml</a>. If the string is invalid
<f name="form" args="($form as node()*[, $override as item()*])">
This creates the request corresponding to a HTML form. The request includes the value of all input/select/textarea descendants of the first parameter.<br/>
You can use the second parameter to give a sequence of values replacing the default values of the form elements.<br/>
A value is either a string, e.g. "name=value&name2=..." which has to be url encoded and is splitted at the &-separators by this function to override each parameter separately. (so the order of the name=value pairs is changed to the order of the input elements in the form). For example <code>form(//form[1], "foo=bar&xyz=123")</code> returns a request for the first form,
A value is either a string, e.g. "name=value&amp;name2=..." which has to be url encoded and is splitted at the &amp;-separators by this function to override each parameter separately. (so the order of the name=value pairs is changed to the order of the input elements in the form). For example <code>form(//form[1], "foo=bar&amp;xyz=123")</code> returns a request for the first form,
with the foo and xyz input fields overridden by bar and 123. <br/>
Or a JSON-like object <code>{"name": "value", ...}</code>, in which the properties must not be url encodeded (i.e. the form method url encodes each property) and in which each property overrides the corresponding input field. For example <code>form(//form[1], {"foo": "bar", "xyz": 123})</code> <br/><br/>
......@@ -106,7 +106,7 @@ For multipart encoded data, the value parameters do not have to be strings, but
<li>value: for a string value.</li>
<li>filename: to set the filename field of the Content-Disposition header.</li>
<li>type: Becomes a Content-Type header</li>
<li>headers: An arbitrary sequence of headers</li>
<li>headers: An arbitrary sequence of headers</li></ul>
</f>
<f name="resolve-html">
Resolves every value in the $relative sequence to an HTTP request with an absolute URL/URI, using $base as reference base URI.<br/>
......@@ -156,10 +156,10 @@ You can pass multiple patterns and nodes, in which case each pattern is applied
If the pattern cannot be matched, an error is raised.
</f>
<f name="transform">
This function can perform an arbitrary transformation of a document, by calling the transformer-function <code>$f</code> for every descendant node and replacing the node with the value returned by the function.<br>
This function can perform an arbitrary transformation of a document, by calling the transformer-function <code>$f</code> for every descendant node and replacing the node with the value returned by the function.<br/>
For example <code><![CDATA[transform(/, function($x) { if (name($x) = "a") then <a>{$x/@*, <b>{$x/node()}</b>}</a> else $x } )]]></code>
will make every link bold.<br>
If $root is omitted, the context item . is used.<br>
will make every link bold.<br/>
If $root is omitted, the context item . is used.<br/>
If $options("always-recurse") is true, all values returned by $f are also transformed with further calls of $f.<br/>
Preliminary, behavior might change in future versions. E.g. it might be renamed to map-nodes
</f>
......@@ -218,5 +218,17 @@ Compares strings like the @class attribute.
<f name="lines" internal="true">
Splits a text into lines.
</f>
<f name="call-action" args="($name as xs:string) as empty-sequence()">
Calls the action of a multipage template.
</f>
<f name="get-log" args="([$var as xs:string]) as item()*">
Gets all values of all variables, or all values of a single variable. <br/>
For all variables it returns a sequence of objects with name and value of the variable as properties.<br/>
For a single variable it returns a sequence of arrays, each array representing one assignment to the variable. (since the assignment might be a sequence, and a sequence of sequences does not exist)
</f>
<f name="clear-log" args="([$var as xs:string]) as empty-sequence()">
Removes all values of all variables, or a single variable.
</f>
</module>
</functions>
\ No newline at end of file
......@@ -4179,6 +4179,55 @@ begin
multipage.callAction(args[0].toString);
end;
function xqfClearLog(argc: SizeInt; args: PIXQValue): IXQValue;
begin
result := xqvalue;
if argc = 0 then begin
htmlparser.variableChangeLog.clear;
htmlparser.oldVariableChangeLog.clear;
end else begin
htmlparser.variableChangeLog.remove(args[0].toString);
htmlparser.oldVariableChangeLog.remove(args[0].toString);
end;
end;
function xqfGetLog(argc: SizeInt; args: PIXQValue): IXQValue;
var
name: String;
reslist: TXQVList;
procedure handleLog(log: TXQVariableChangeLog);
var
tempobj: TXQValueObject;
tempArray: TXQValueJSONArray;
begin
if name = '' then begin
for i := 0 to log.count - 1 do begin
tempobj := TXQValueObject.create();
tempobj.setMutable('name', log.getName(i));
tempobj.setMutable('value', log.get(i));
if log.getNamespace(i) <> '' then tempobj.setMutable('namespace', log.getNamespace(i));
reslist.add(tempobj);
end;
end else begin
for i := 0 to log.count - 1 do begin
if log.getName(i) <> name then continue;
tempArray := TXQValueJSONArray.create();
tempArray.add(log.get(i));
reslist.add(tempArray);
end;
end;
log.free;
end;
begin
if argc = 1 then name := args[0].toString
else name := '';
reslist := TXQVList.create(htmlparser.oldVariableChangeLog.count + htmlparser.variableChangeLog.count);
handleLog(htmlparser.oldVariableChangeLog.condensed);
handleLog(htmlparser.variableChangeLog.condensed);
xqvalueSeqSqueezed(result, reslist);
end;
procedure blockFileAccessFunctions;
var fn, pxp, jn: TXQNativeModule;
......@@ -4220,5 +4269,7 @@ initialization
pxpx.registerFunction('integer', @xqfInteger, ['($arg as item()) as xs:integer', '($arg as item(), $base as xs:integer) as xs:integer']);
pxpx.registerFunction('integer-to-base', @xqfIntegerToBase, ['($arg as xs:integer, $base as xs:integer) as xs:string']);
pxpx.registerFunction('call-action', @xqfCallAction, ['($arg as xs:string) as empty-sequence()']);
pxpx.registerFunction('clear-log', @xqfClearLog, ['() as empty-sequence()', '($var as xs:string) as empty-sequence()']);
pxpx.registerFunction('get-log', @xqfGetLog, ['() as item()*', '($var as xs:string) as item()*']);
end.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment