Difference between revisions of "Output Module"

From BaseX Documentation
Jump to navigation Jump to search
Line 60: Line 60:
 
| valign='top' | '''Examples'''
 
| valign='top' | '''Examples'''
 
|The expression <code>util:ms("1 to 100000")</code> might return <code>25.69</code>.<br />The expression <code>util:ms("1 to 100000", true())</code> might return <code>208.12</code>.<br />
 
|The expression <code>util:ms("1 to 100000")</code> might return <code>25.69</code>.<br />The expression <code>util:ms("1 to 100000", true())</code> might return <code>208.12</code>.<br />
 +
|}
 +
 +
==util:integer-to-base==
 +
{|
 +
|-
 +
| valign='top' width='90' | '''Signatures'''
 +
|<code><b>util:integer-to-base</b>($num as xs:integer, $base as xs:integer) as xs:string</code><br />
 +
|-
 +
| valign='top' | '''Summary'''
 +
|Converts <code>$num</code> to base <code>$base</code>, interpreting it as a 64-bit unsigned integer. The first <code>$base</code> elements of the sequence <code>'0',..,'9','a',..,'z'</code> are used as digits.<br />
 +
|-
 +
| valign='top' | '''Rules'''
 +
|Valid bases are <code>2, .., 36</code>.<br />
 +
|-
 +
| valign='top' | '''Examples'''
 +
|The expression <code>util:integer-to-base(22, 5)</code> returns <code>'42'</code>.<br /> The expression <code>util:integer-to-base(-1, 16)</code> returns <code>'ffffffffffffffff'</code>.<br />
 +
|}
 +
 +
==util:integer-from-base==
 +
{|
 +
|-
 +
| valign='top' width='90' | '''Signatures'''
 +
|<code><b>util:integer-from-base</b>($str as xs:string, $base as xs:integer) as xs:integer</code><br />
 +
|-
 +
| valign='top' | '''Summary'''
 +
|Decodes an <code>xs:integer</code> from <code>$str</code>, assuming that it's encoded in base <code>$base</code>.<br /> The first <code>$base</code> elements of the sequence <code>'0',..,'9','a',..,'z'</code> are allowed as digits.<br />
 +
|-
 +
| valign='top' | '''Rules'''
 +
|Valid bases are <code>2, .., 36</code>.<br /> If <code>$str</code> contains more than 64 bits of information, the result is truncated arbitarily.
 +
|-
 +
| valign='top' | '''Examples'''
 +
|The expression <code>util:integer-from-base('42', 5)</code> returns <code>22</code>.<br /> The expression <code>util:integer-from-base('ffffffffffffffff', 16)</code> returns <code>-1</code>.<br /> The expression <code>util:integer-from-base(util:integer-to-base(123, 7), 7)</code> returns <code>123</code>.<br />
 
|}
 
|}
  
 
[[Category:XQuery]]
 
[[Category:XQuery]]

Revision as of 15:56, 15 February 2011

This module contains auxiliary XQuery Functions, which can be used for testing and profiling the code. All functions are preceded by the util: prefix.

util:eval

Signatures util:eval($expr as xs:string) as item()*
Summary Evaluates the argument at runtime.
Rules This function dynamically evaluates $expr as XQuery expression and returns the resulting items.
Examples The expression util:eval("1+3") returns 4.

util:run

Signatures util:run($input as xs:string) as item()*
Summary Opens the argument as file and evaluates it at runtime.
Rules This function opens $input as file, evaluates it as XQuery expression, and returns the resulting items.

util:mb

Signatures util:mb($expr as item()) as xs:double
util:mb($expr as item(), $cache as xs:boolean) as xs:double
Summary Measures the memory consumption for evaluating the argument.
Rules This function measures the amount of memory that is needed to evaluate $expr. If the value of $cache is true(), the result will be cached. The returned xs:double value represents the amount of memory in megabytes.
Examples The expression util:mb("1 to 100000") might return 0.
The expression util:mb("1 to 100000", true()) might return 26.678.

util:ms

Signatures util:ms($expr as item()) as xs:double
util:ms($expr as item(), $cache as xs:boolean) as xs:double
Summary Measures the time needed for evaluating the argument.
Rules This function measures the time needed to evaluate $expr. If the value of $cache is true(), the result will be cached. The returned xs:double value represents the needed time in milliseconds.
Examples The expression util:ms("1 to 100000") might return 25.69.
The expression util:ms("1 to 100000", true()) might return 208.12.

util:integer-to-base

Signatures util:integer-to-base($num as xs:integer, $base as xs:integer) as xs:string
Summary Converts $num to base $base, interpreting it as a 64-bit unsigned integer. The first $base elements of the sequence '0',..,'9','a',..,'z' are used as digits.
Rules Valid bases are 2, .., 36.
Examples The expression util:integer-to-base(22, 5) returns '42'.
The expression util:integer-to-base(-1, 16) returns 'ffffffffffffffff'.

util:integer-from-base

Signatures util:integer-from-base($str as xs:string, $base as xs:integer) as xs:integer
Summary Decodes an xs:integer from $str, assuming that it's encoded in base $base.
The first $base elements of the sequence '0',..,'9','a',..,'z' are allowed as digits.
Rules Valid bases are 2, .., 36.
If $str contains more than 64 bits of information, the result is truncated arbitarily.
Examples The expression util:integer-from-base('42', 5) returns 22.
The expression util:integer-from-base('ffffffffffffffff', 16) returns -1.
The expression util:integer-from-base(util:integer-to-base(123, 7), 7) returns 123.