Strings

From MemCP
Revision as of 08:24, 27 August 2026 by Carli (talk | contribs)
Jump to navigation Jump to search

Strings

The Strings module provides comprehensive string manipulation and processing functions for the SCM programming language. This module includes:

  • String validation: Functions to check string types and properties (string?, strlen)
  • String manipulation: Concatenation (concat), substring extraction (substr), and case conversion (toLower, toUpper)
  • Pattern matching: Wildcard pattern matching (strlike) and string replacement (replace)
  • String parsing: Splitting strings (split) and data type simplification (simplify)
  • Encoding/Decoding: URL encoding/decoding, HTML entities, JSON processing, and binary conversion
  • Internationalization: Collation support for natural sorting and language-specific comparisons

These functions provide the essential tools for text processing, data formatting, and string-based operations in SCM programs.

← Back to Full SCM API documentation


string?

tells if the value is a string

Allowed number of parameters: 1–1

Parameters

  • value (any): value

Returns

bool

concat

concatenates stringable values and returns a string

Allowed number of parameters: 1–10000

Parameters

  • value (any): first value to concat
  • more... (any): additional values to concat (variadic)

Returns

string

sql_concat

SQL CONCAT semantics: returns NULL if any argument is NULL

Allowed number of parameters: 1–10000

Parameters

  • value (any): first value to concat
  • more... (any): additional values to concat (variadic)

Returns

any

substr

returns a substring (0-based index)

Allowed number of parameters: 2–3

Parameters

  • value (string): string to cut
  • start (number): first character index (0-based)
  • len (number): optional length (optional)

Returns

string

sql_substr

SQL SUBSTR/SUBSTRING with 1-based index and bounds checking

Allowed number of parameters: 2–3

Parameters

  • value (string): string to cut
  • start (number): first character position (1-based)
  • len (number): optional length (optional)

Returns

string

simplify

turns a stringable input value in the easiest-most value (e.g. turn strings into numbers if they are numeric

Allowed number of parameters: 1–1

Parameters

  • value (any): value to simplify

Returns

any

strlen

returns the length of a string

Allowed number of parameters: 1–1

Parameters

  • value (string): input string

Returns

int

strlike

matches the string against a wildcard pattern using SQL NULL semantics

Allowed number of parameters: 2–3

Parameters

  • value (string): input string
  • pattern (string): pattern with % and _ in them
  • collation (string): collation in which to compare them (optional)

Returns

bool

strlike_cs

matches the string against a wildcard pattern case-sensitively using SQL NULL semantics

Allowed number of parameters: 2–3

Parameters

  • value (string): input string
  • pattern (string): pattern with % and _ in them
  • collation (string): ignored (present for parser compatibility) (optional)

Returns

bool

toLower

turns a string into lower case

Allowed number of parameters: 1–1

Parameters

  • value (string): input string

Returns

string

toUpper

turns a string into upper case

Allowed number of parameters: 1–1

Parameters

  • value (string): input string

Returns

string

replace

replaces all occurances in a string with another string

Allowed number of parameters: 3–3

Parameters

  • s (string): input string
  • find (string): search string
  • replace (string): replace string

Returns

string

strtrim

trims whitespace from both ends of a string

Allowed number of parameters: 1–1

Parameters

  • value (string): input string

Returns

string

strltrim

trims whitespace from the left of a string

Allowed number of parameters: 1–1

Parameters

  • value (string): input string

Returns

string

strrtrim

trims whitespace from the right of a string

Allowed number of parameters: 1–1

Parameters

  • value (string): input string

Returns

string

sql_trim

SQL TRIM(): NULL-safe trim of whitespace from both ends

Allowed number of parameters: 1–1

Parameters

  • value (string): input string

Returns

string

sql_ltrim

SQL LTRIM(): NULL-safe trim of whitespace from left

Allowed number of parameters: 1–1

Parameters

  • value (string): input string

Returns

string

sql_rtrim

SQL RTRIM(): NULL-safe trim of whitespace from right

Allowed number of parameters: 1–1

Parameters

  • value (string): input string

Returns

string

split

splits a string using a separator or space

Allowed number of parameters: 1–2

Parameters

  • value (string): input string
  • separator (string): (optional) parameter, defaults to " " (optional)

Returns

list

string_repeat

repeats a string n times

Allowed number of parameters: 2–2

Parameters

  • value (string): string to repeat
  • count (number): number of repetitions

Returns

string

collate

returns a canonical order relation for a collation and direction. MemCP allows natural sorting of numeric literals.

Allowed number of parameters: 1–2

Parameters

  • collation (string): collation string of the form LANG or LANG_cs or LANG_ci where LANG is a BCP 47 code, for compatibility to MySQL, a CHARSET_ prefix is allowed and ignored as well as the aliases bin, danish, general, german1, german2, spanish and swedish are allowed for language codes
  • reverse (bool): whether to reverse the order like in ORDER BY DESC (optional)

Returns

func(a:any, b:any) -> bool

htmlentities

escapes the string for use in HTML

Allowed number of parameters: 1–1

Parameters

  • value (string): input string

Returns

string

urlencode

encodes a string according to URI coding schema

Allowed number of parameters: 1–1

Parameters

  • value (string): string to encode

Returns

string

urldecode

decodes a string according to URI coding schema

Allowed number of parameters: 1–1

Parameters

  • value (string): string to decode

Returns

string

json_encode

encodes a value in JSON, treats lists as lists

Allowed number of parameters: 1–1

Parameters

  • value (any): value to encode

Returns

string

json_quote

quotes a string as JSON

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_encode_assoc

encodes a value in JSON, treats lists as associative arrays

Allowed number of parameters: 1–1

Parameters

  • value (any): value to encode

Returns

string

json_decode

parses JSON into a map

Allowed number of parameters: 1–1

Parameters

  • value (string): string to decode

Returns

any

json_decode_scmer

parses JSON produced by json_encode and preserves Scheme symbols and lists

Allowed number of parameters: 1–1

Parameters

  • value (string): Scmer JSON to decode

Returns

any

base64_encode

encodes a string as Base64 (standard encoding)

Allowed number of parameters: 1–1

Parameters

  • value (string): binary string to encode

Returns

string

base64_decode

decodes a Base64 string (standard encoding)

Allowed number of parameters: 1–1

Parameters

  • value (string): base64-encoded string

Returns

string

sql_unescape

unescapes the inner part of a sql string

Allowed number of parameters: 1–1

Parameters

  • value (string): string to decode

Returns

string

bin2hex

turns binary data into hex with lowercase letters

Allowed number of parameters: 1–1

Parameters

  • value (string): string to encode

Returns

string

bin2hex

turns binary data into hex with lowercase letters

Allowed number of parameters: 1–1

Parameters

  • value (string): string to encode

Returns

string

hex2bin

decodes a hex string into binary data

Allowed number of parameters: 1–1

Parameters

  • value (string): hex string (even length)

Returns

string

uuid

generates a new random UUID v4 string

Allowed number of parameters: 0–0

Parameters

This function has no parameters.

Returns

string

randomBytes

returns a string with numBytes cryptographically secure random bytes

Allowed number of parameters: 1–1

Parameters

  • numBytes (number): number of random bytes

Returns

string

regexp_replace

replaces matches of a regex pattern in a string

Allowed number of parameters: 3–3

Parameters

  • str (string): input string
  • pattern (string): regex pattern
  • replacement (string): replacement string

Returns

string

fnv_hash

computes a fast non-cryptographic 64-bit FNV-1a hash of a string, returns a 16-character hex string

Allowed number of parameters: 1–1

Parameters

  • str (string): input string to hash

Returns

string

stable_structural_hash

streams the string or serialized representation of a Scheme value into stable FNV-1a without constructing the complete representation

Allowed number of parameters: 1–2

Parameters

  • value (any): value to hash
  • serialize (bool): use the Scheme serializer instead of string rendering (optional)

Returns

string

sha1

computes the SHA-1 digest of a string, returns a 40-character lowercase hex string

Allowed number of parameters: 1–1

Parameters

  • str (string): input string to hash

Returns

string

sha256

computes the SHA-256 digest of a string, returns a 64-character lowercase hex string

Allowed number of parameters: 1–1

Parameters

  • str (string): input string to hash

Returns

string

regexp_test

tests if a string matches a regex pattern, returns true/false

Allowed number of parameters: 2–2

Parameters

  • str (string): input string
  • pattern (string): regex pattern

Returns

bool

json_parse_bson

validates JSON and returns a BSON-backed value

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_array

creates a MySQL-compatible JSON array

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_object

creates a MySQL-compatible JSON object

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_quote

quotes a string as JSON

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_unquote

unquotes a JSON string

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_valid

tests whether a value contains valid JSON

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_type

returns the MySQL JSON type name

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_depth

returns maximum JSON document depth

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_length

returns JSON object or array length

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_extract

extracts one or more JSON paths

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_keys

returns object member names

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_contains_path

tests whether one or all JSON paths exist

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_contains

tests JSON containment

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_overlaps

tests whether JSON values overlap

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_member_of

tests whether a JSON scalar is a member of an array

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_pretty

pretty-prints JSON

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_storage_size

returns BSON payload size

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_storage_free

returns unused BSON storage space

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_schema_valid

validates a document against a MySQL Draft 4 JSON schema

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_schema_validation_report

reports MySQL Draft 4 JSON schema validation

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_set

sets or inserts JSON path values

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_insert

inserts missing JSON path values

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_replace

replaces existing JSON path values

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_remove

removes JSON path values

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_array_append

appends values to JSON arrays

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_array_insert

inserts values into JSON arrays

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_merge_patch

merges documents using RFC 7396 semantics

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_merge_preserve

merges documents while preserving values

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_search

searches JSON string values

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_value

extracts a scalar JSON value

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_to_json

implements PostgreSQL to_json and to_jsonb

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_row_to_json

implements PostgreSQL row_to_json

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_build_array

implements PostgreSQL JSON array builders

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_array_absent

implements SQL/JSON ARRAY ABSENT ON NULL

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_build_object

implements PostgreSQL JSON object builders

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_object

implements PostgreSQL json_object and jsonb_object array forms

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_serialize

implements PostgreSQL json_serialize

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_array_length

implements PostgreSQL json_array_length

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_extract_path

implements PostgreSQL json_extract_path

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_extract_path_text

implements PostgreSQL json_extract_path_text

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_set

implements PostgreSQL jsonb_set

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_set_lax

implements PostgreSQL jsonb_set_lax

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_insert

implements PostgreSQL jsonb_insert

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_strip_nulls

implements PostgreSQL json_strip_nulls

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_typeof

implements PostgreSQL json_typeof

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_populate_record_valid

validates PostgreSQL jsonb_populate_record input shape

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_concat

implements PostgreSQL jsonb concatenation

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_delete

implements PostgreSQL jsonb deletion

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_delete_path

implements PostgreSQL jsonb path deletion

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_subtract

dispatches PostgreSQL numeric and jsonb subtraction

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_exists

implements PostgreSQL jsonb top-level existence

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_path_exists

implements PostgreSQL jsonb_path_exists

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_path_match

implements PostgreSQL jsonb_path_match

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_path_query_array

implements PostgreSQL jsonb_path_query_array

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_jsonb_path_query_first

implements PostgreSQL jsonb_path_query_first

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_value

implements PostgreSQL SQL/JSON JSON_VALUE

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_get

implements PostgreSQL JSON object and array extraction

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_arrayagg_entry

wraps one JSON_ARRAYAGG input value

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_arrayagg_reduce

JSON_ARRAYAGG reducer

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_arrayagg_finalize

builds one BSON array from a collected JSON_ARRAYAGG value list

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_objectagg_entry

constructs a JSON_OBJECTAGG key/value entry

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

json_objectagg_reduce

JSON_OBJECTAGG reducer

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any

pg_json_table_rows

materializes a PostgreSQL JSON table function as rows

Allowed number of parameters: 0–10000

Parameters

  • arguments (any): (variadic)

Returns

any