Files
plxml/doc/stl.md
2022-06-05 00:26:52 +02:00

5.1 KiB

Standard Library

The PL/XML Standard Library allows access to system functions such as input/output, file access and array manipulation.

Table of Contents

Functions

PRINT

Writes a string as-is to the standard output

Arguments

  • string value to print

Returns

Nothing

Minimal example

<call function="print">
    <arguments>
        <string value="hello world!&#xD;&#xA;" />
    </arguments>
</call>

PRINT-LINE

Writes a string to the standard output, appending a new line

Arguments

  • string value to print

Returns

Nothing

Minimal example

<call function="print-line">
    <arguments>
        <string value="hello world!" />
    </arguments>
</call>

INPUT

Reads from the standard input

Arguments

Nothing

Returns

string value read

Minimal example

<call function="input">
    <arguments />
</call>

STRING-SPLIT

Splits a string into a vector of single-character strings

Arguments

  • string value to split

Returns

array value of strings

Minimal examples

<call function="string-split">
    <arguments>
        <string value="abcdef" />
        <string value="" />
    </arguments>
</call>
<call function="string-split">
    <arguments>
        <string value="id,name,type,value" />
        <string value="," />
    </arguments>
</call>

ARRAY-SET

Sets a value at a specific index of an array.

Arguments

  • array to update
  • integer index
  • any value to set

Returns

Nothing

Minimal example

<assign variable="arr">
    <array>
        <string value="hello">
    </array>
</assign>
<call function="array-set">
    <arguments>
        <value variable="arr" />
        <integer value="0" />
        <string value="world">
    </arguments>
</call>

ARRAY-PUSH

Pushes a value at the end of an array

Arguments

  • array to update
  • any value to push

Returns

Nothing

Minimal example

<assign variable="arr">
    <array>
        <string value="hello">
    </array>
</assign>
<call function="array-push">
    <arguments>
        <value variable="arr" />
        <string value="world">
    </arguments>
</call>

ARRAY-POP

Removes and returns the value at the end of an array

Arguments

  • array to update

Returns

any value

Minimal example

<assign variable="arr">
    <array>
        <string value="hello">
    </array>
</assign>
<call function="array-pop">
    <arguments>
        <value variable="arr" />
    </arguments>
</call>

ARRAY-GET

Returns the value at index of an array

Arguments

  • array to query
  • integer index

Returns

any value

Minimal example

<assign variable="arr">
    <array>
        <string value="hello">
    </array>
</assign>
<call function="array-get">
    <arguments>
        <value variable="arr" />
        <integer value="0" />
    </arguments>
</call>

ARRAY-LENGTH

Returns the length of an array

Arguments

  • array to query

Returns

integer length

Minimal example

<assign variable="arr">
    <array>
        <string value="hello">
    </array>
</assign>
<call function="array-length">
    <arguments>
        <value variable="arr" />
    </arguments>
</call>

TO-ASCII

Converts an integer value into an ASCII character string

Arguments

  • integer to convert

Returns

string corresponding ASCII character

Minimal example

<call function="to-ascii">
    <arguments>
        <integer value="65" />
    </arguments>
</call>

FROM-ASCII

Converts a one-character string into its ASCII integer value

Arguments

  • string character to convert

Returns

integer ASCII value

Minimal example

<call function="from-ascii">
    <arguments>
        <string value="a" />
    </arguments>
</call>

GET-ARGS

Returns an array of arguments passed to the program

Arguments

Nothing

Returns

array of strings

Minimal example

<call function="get-args">
    <arguments />
</call>

WRITE-FILE

Writes a string to a file, optionally appending

Arguments

  • string filename
  • string to write
  • any falsy to replace, truthy to append

Returns

Nothing

Minimal example

<call function="write-file">
    <arguments>
        <string value="file.txt" />
        <string value="Hello world!" />
        <integer value="0" />
    </arguments>
</call>

READ-FILE

Reads a file into a string

Arguments

  • string filename

Returns

  • string file contents

Minimal example

<call function="read-file">
    <arguments>
        <string value="file.txt" />
    </arguments>
</call>