This module provides string related functions.
Mostly, the functions in this module provide primitives to work with streamable strings. For example, it allows to check whether a given string is streamable or seekable.
analyze-string
($input as xs:string?, $pattern as xs:string) as array()
Analyzes a string using a regular expression, returning sequence of JSON objects that identify which parts of the input string matched or failed to match the regular expression; and in the case of matched substrings, which substrings matched each capturing group in the regular expression. |
analyze-string
($input as xs:string?, $pattern as xs:string, $flags as xs:string) as array() external
Analyzes a string using a regular expression, returning sequence of JSON objects that identify which parts of the input string matched or failed to match the regular expression; and in the case of matched substrings, which substrings matched each capturing group in the regular expression. |
is-seekable
($s as string) as boolean external
This function checks whether a given string item is a seekable stream string. |
is-streamable
($s as string) as boolean external
This function checks whether a given string item is implemented by a streamable string. |
materialize
($s as string) as string external
This function materializes a streamable string. |
split
($s as string, $separator as string) as string* external
Returns a sequence of strings constructed by splitting the input wherever the given separator is found. |
declare function string:analyze-string($input as xs:string?, $pattern as xs:string) as array()
This function behaves like
fn:analyze-string
but returns a JSON array rather than an XML element.
$input
were a zero-length string.match
or non-match
. For non-match
, the value is a string that is the part of $input
that did not match; for match
, the value is either a string that is the part of $input
that matched (when $pattern
contains no capturing groups) or an array containing values for both capturing groups and other matches. Capturing group matches are themselves arrays where the first element is the group number (1-based) and subsequent elements are either a string that is the part of $input
that matched or sub-arrays for nested capturing groups.
declare function string:analyze-string($input as xs:string?, $pattern as xs:string, $flags as xs:string) as array() external
This function behaves like
fn:analyze-string
but returns a JSON array rather than an XML element.
$input
were a zero-length string.fn:matches
function.match
or non-match
. For non-match
, the value is a string that is the part of $input
that did not match; for match
, the value is either a string that is the part of $input
that matched (when $pattern
contains no capturing groups) or an array containing values for both capturing groups and other matches. Capturing group matches are themselves arrays where the first element is the group number (1-based) and subsequent elements are either a string that is the part of $input
that matched or sub-arrays for nested capturing groups.
declare function string:is-seekable($s as string) as boolean external
This function checks whether a given string item is a seekable stream string.
For example, a seekable streamable string is returned by the file module.
declare function string:is-streamable($s as string) as boolean external
This function checks whether a given string item is implemented by a streamable string.
A streamable string is produced by some functions of a module. It's an optimized implementation of an string to handle arbitrary sized data. The drawback is that its value can only be consumed once. That is, only one function can access the value of a streamable string item.
declare function string:materialize($s as string) as string external
This function materializes a streamable string.
The drawback of a streamable (non-seekable) string is that its value can only be consumed once. That is, only one function can access the value of astreamable string item.
In order to remedy this situation, this function can be used to convert a streamable string into its non-streamable counterpart. As a result, the string returned by this function has the same value as its input but is materialized and, hence, can be consumed multiple times.
declare function string:split($s as string, $separator as string) as string* external
Returns a sequence of strings constructed by splitting the input wherever the given separator is found.
The function is different from tokenize. It doesn't allow the separator to be a regular expression. This restriction allows for more performant implementation. Specifically, the function processes streamable strings as input in a streamable way which is particularly useful to tokenize huge strings.