Difference between revisions of "Utility Module"
Jump to navigation
Jump to search
| Line 3: | Line 3: | ||
=Conventions= | =Conventions= | ||
| − | All functions in this module and errors are assigned to the <code><nowiki>http://basex.org/modules/util</nowiki></code> namespace, which is statically bound to the {{Code|util}} prefix.<br/> | + | All functions and errors in this module and errors are assigned to the <code><nowiki>http://basex.org/modules/util</nowiki></code> namespace, which is statically bound to the {{Code|util}} prefix.<br/> |
=Functions= | =Functions= | ||
| Line 51: | Line 51: | ||
| | | | ||
* <code>util:last-from(reverse(1 to 100))</code> returns <code>1</code>. | * <code>util:last-from(reverse(1 to 100))</code> returns <code>1</code>. | ||
| + | |} | ||
| + | |||
| + | ==util:replicate== | ||
| + | |||
| + | {{Mark|Introduced with Version 9.0}}. | ||
| + | |||
| + | {| width='100%' | ||
| + | |- | ||
| + | | width='120' | '''Signatures''' | ||
| + | |{{Func|util:replicate|$sequence as item()*, $count as xs:integer|item()*}}<br/> | ||
| + | |- | ||
| + | | '''Summary''' | ||
| + | |Returns {{Code|$count}} instances of the specified {{Code|$sequence}}. Equivalent to <code>(1 to $count) ! $sequence</code>. | ||
| + | |- | ||
| + | | '''Errors''' | ||
| + | |{{Error|negative|#Errors}} The specified number is negative. | ||
| + | |- | ||
| + | | '''Examples''' | ||
| + | | | ||
| + | * <code>util:replicate('A', 3)</code> returns <code>A A A</code>. | ||
| + | |} | ||
| + | |||
| + | =Errors= | ||
| + | |||
| + | {| class="wikitable" width="100%" | ||
| + | ! width="110"|Code | ||
| + | |Description | ||
| + | |- | ||
| + | |{{Code|negative}} | ||
| + | |The specified number is negative. | ||
|} | |} | ||
=Changelog= | =Changelog= | ||
| + | |||
| + | ;Version 9.0 | ||
| + | * Added: [[#util:replicate|util:replicate]] | ||
The Module was introduced with Version 8.5. | The Module was introduced with Version 8.5. | ||
Revision as of 17:06, 13 November 2017
This XQuery Module contains various small utility and helper functions. Please note that some of the functions are used for internal query rewritings. They may be renamed or moved to other modules in future versions of BaseX.
Contents
Conventions
All functions and errors in this module and errors are assigned to the http://basex.org/modules/util namespace, which is statically bound to the util prefix.
Functions
util:item-at
| Signatures | util:item-at($sequence as item()*, $position as xs:double) as item()? |
| Summary | Returns the item from $sequence at the specified $position. Equivalent to $sequence[$position].
|
| Examples |
|
util:item-range
| Signatures | util:item-range($sequence as item()*, $first as xs:double, $last as xs:double) as item()* |
| Summary | Returns items from $sequence, starting at position $first and ending at $last. Equivalent to subsequence($sequence, $first, $last - $first + 1).
|
| Examples |
|
util:last-from
| Signatures | util:last-from($sequence as item()*) as item()? |
| Summary | Returns last item of a $sequence. Equivalent to $sequence[last()].
|
| Examples |
|
util:replicate
| Signatures | util:replicate($sequence as item()*, $count as xs:integer) as item()* |
| Summary | Returns $count instances of the specified $sequence. Equivalent to (1 to $count) ! $sequence.
|
| Errors | negative: The specified number is negative.
|
| Examples |
|
Errors
| Code | Description |
|---|---|
negative
|
The specified number is negative. |
Changelog
- Version 9.0
- Added: util:replicate
The Module was introduced with Version 8.5.