http://zorba.io/modules/string

View as XML or JSON.

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.

Function Summary

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.

Functions

analyze-string#2

declare  function string: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.

This function behaves like fn:analyze-string but returns a JSON array rather than an XML element.

Parameters

input as xs:string
The string to analyze. If the empty sequence, the function behaves as if $input were a zero-length string.
pattern as xs:string
The regular expression.

Returns

array()
a JSON array of objects where each object contains a single key/value pair. Each key is either 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.

analyze-string#3

declare  function string: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.

This function behaves like fn:analyze-string but returns a JSON array rather than an XML element.

Parameters

input as xs:string
The string to analyze. If the empty sequence, the function behaves as if $input were a zero-length string.
pattern as xs:string
The regular expression.
flags as xs:string
The argument is interpreted in the same way as for the fn:matches function.

Returns

array()
a JSON array of objects where each object contains a single key/value pair. Each key is either 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.

is-seekable#1

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.

Parameters

s as string
the string to check

Returns

boolean
true if the given item is a seekable stream string or false otherwise.

is-streamable#1

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.

Parameters

s as string
the string to check

Returns

boolean
true if the given item is implemented using a streamable string or false otherwise.

materialize#1

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.

Parameters

s as string
the streamable string item to materialize

Returns

string
a materialized string of its input or the input if the input item was not a streamable string.

split#2

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.

Parameters

s as string
the input string to split
separator as string
the separator used for splitting the input string $s

Returns

string*
a sequence of strings constructed by splitting the input