-
Notifications
You must be signed in to change notification settings - Fork 0
Built‐in Functions (Standard Library)
Andreas Wagner edited this page Nov 16, 2025
·
2 revisions
XTML comes with a standard library of built-in functions under the std namespace. These functions can be used inside <xtml> blocks with the native keyword to perform common tasks such as string manipulation, array handling, random values, and printing.
| Function | Arguments | Description |
|---|---|---|
std::toUpper(str) |
1 string | Converts the given string to uppercase. |
std::toLower(str) |
1 string | Converts the given string to lowercase. |
std::len(str) |
1 string | Returns the length of the string as a number. |
std::trim(str) |
1 string | Trims leading and trailing whitespace from the string. |
std::trimQuotes(str) |
1 string | Removes surrounding quotes from the string. |
std::toInt(str) |
1 numeric string | Converts a string containing a number into a numeric type. |
std::toStr(value) |
1 value | Converts a numeric or boolean value to a string. |
| Function | Arguments | Description |
|---|---|---|
std::get(array, index) |
1 array, 1 number | Returns the element at the given index. Index must be within bounds. |
std::count(array) |
1 array | Returns the number of elements in the array. |
| Function | Arguments | Description |
|---|---|---|
std::isInt(value) |
1 value | Returns 1 if the value is numeric, 0 otherwise. |
std::isStr(value) |
1 value | Returns 1 if the value is a string, 0 otherwise. |
| Function | Arguments | Description |
|---|---|---|
std::randStr(length) |
1 number | Generates a random alphanumeric string of the given length. |
std::uuid([seed]) |
0 or 1 number | Generates a UUID. Optionally, a numeric seed can be provided. |
std::print(value) |
1 value | Prints a value to the output (captured in EvalResult.output). |
<xtml>
var name = "XTML";
var upperName = native std::toUpper(name); // "XTML"
var len = native std::len(name); // 4
var randomStr = native std::randStr(8); // e.g. "fJ3kL9pQ"
var array = [10, 20, 30];
var second = native std::get(array, 1); // 20
var count = native std::count(array); // 3
var id = native std::uuid(); // e.g. "3f2504e0-4f89-11d3-9a0c-0305e82c3301"
</xtml>
Notes
- All function calls must be inside
<xtml>blocks with thenativekeyword. - Functions will validate argument types; invalid calls return an empty value and print an error.
- The std namespace is automatically available in XTML templates.