Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
string.c File Reference

String built-ins wrappers used by VM opcodes. More...

#include "value.h"
#include <stdlib.h>
Include dependency graph for string.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

Value bi_split (const Value *str, const Value *sep)
 Split a string by a separator into an array Value.
Value bi_join (const Value *arr, const Value *sep)
 Join an array of strings with a separator into a single string Value.
Value bi_substr (const Value *str, int start, int len)
 Extract a substring from a string Value.
int bi_find (const Value *hay, const Value *needle)
 Find the first occurrence of a needle inside a haystack string.

Detailed Description

String built-ins wrappers used by VM opcodes.

Provides small wrapper functions around core string utilities to operate on the Value type used by the VM (split, join, substr, find).

Definition in file string.c.

Function Documentation

◆ bi_find()

int bi_find(const Value *hay,
const Value *needle )

Find the first occurrence of a needle inside a haystack string.

If either argument is not a VAL_STRING or is NULL, it is treated as an empty string (""). The search is performed by string_find.

Parameters
hayHaystack string (VAL_STRING). May be NULL.
needleNeedle string (VAL_STRING). May be NULL.
Returns
The zero-based index of the first occurrence of needle in hay, or -1 if not found. Exact semantics are delegated to string_find.

Definition at line 96 of file string.c.

Here is the call graph for this function:

◆ bi_join()

Value bi_join(const Value *arr,
const Value *sep )

Join an array of strings with a separator into a single string Value.

Extracts the separator C string from sep if it is a VAL_STRING, otherwise uses an empty string (""). The join operation is performed by array_join_with_sep.

Parameters
arrArray Value expected to contain strings. Semantics for non-string elements are defined by array_join_with_sep.
sepSeparator string (VAL_STRING). May be NULL; defaults to empty.
Returns
A VAL_STRING Value with the joined result. Never returns a NULL Value; if joining fails, an empty string is returned.

Definition at line 56 of file string.c.

Here is the call graph for this function:

◆ bi_split()

Value bi_split(const Value *str,
const Value *sep )

Split a string by a separator into an array Value.

Safely extracts C strings from the provided Value arguments. If either argument is NULL, not of type VAL_STRING, or has a NULL s pointer, an empty string ("") is used instead.

Parameters
strInput string (VAL_STRING) to split. May be NULL.
sepSeparator string (VAL_STRING). May be NULL. If empty, behavior is defined by string_split_to_array.
Returns
A Value representing an array of substrings (each a VAL_STRING). The exact array layout and split semantics are delegated to string_split_to_array.

Definition at line 37 of file string.c.

Here is the call graph for this function:

◆ bi_substr()

Value bi_substr(const Value *str,
intstart,
intlen )

Extract a substring from a string Value.

If str is not a VAL_STRING or is NULL, an empty source string is used. The actual substring extraction semantics (e.g., handling of negative or out-of-range indices) are delegated to string_substr.

Parameters
strSource string (VAL_STRING). May be NULL.
startZero-based start index.
lenMaximum number of characters to include in the substring.
Returns
A VAL_STRING Value containing the substring. Returns an empty string if extraction fails or inputs are treated as empty.

Definition at line 77 of file string.c.

Here is the call graph for this function: