x-engine-c v0.2.13
The C engine for x-lang
Loading...
Searching...
No Matches
str.h File Reference

String type for the x-lang type system. More...

#include "x-type.h"

Go to the source code of this file.

Macros

#define X_TYPE_STR_NAME   "STRING"
 
#define x_obj_type_isstr(B, X)   x_obj_is_type((B), (X), X_TYPE_STR_NAME)
 
#define x_strval(X)   x_firststr((X))
 
#define x_strlen(X)   x_lib_strlen(x_strval((X)))
 
#define x_mkstr(B, S)   x_make_str((B), X_OBJ_FLAG_NONE, (S))
 
#define x_mkfstr(B, F, S)   x_make_str((B), (F), (S))
 
#define x_mkstrown(B, S)   x_make_str((B), X_OBJ_FLAG_OWN, (S))
 
#define x_mkfstrown(B, F, S)   x_make_str((B), X_OBJ_FLAG_OWN | (F), (S))
 

Functions

x_obj_tx_make_str (x_obj_t *p_base, x_obj_flag_t flags, x_char_t *s)
 
x_obj_tx_type_str_struct (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_str_register (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_str_make (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_str_length (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_str_read (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_str_write (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_str_call (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_str_proc (x_obj_t *p_base, x_obj_t *p_args)
 

Detailed Description

String type for the x-lang type system.

Author
Jon Ruttan (jonru.nosp@m.ttan.nosp@m.@gmai.nosp@m.l.co.nosp@m.m)

Macro Definition Documentation

◆ x_mkfstr

#define x_mkfstr (   B,
  F,
 
)    x_make_str((B), (F), (S))

Make a string with explicit flags F.

◆ x_mkfstrown

#define x_mkfstrown (   B,
  F,
 
)    x_make_str((B), X_OBJ_FLAG_OWN | (F), (S))

Make an owning string with additional flags F.

◆ x_mkstr

#define x_mkstr (   B,
 
)    x_make_str((B), X_OBJ_FLAG_NONE, (S))

Make a string with default flags (non-owning).

◆ x_mkstrown

#define x_mkstrown (   B,
 
)    x_make_str((B), X_OBJ_FLAG_OWN, (S))

Make a string that owns its buffer (will be freed by GC).

◆ x_obj_type_isstr

#define x_obj_type_isstr (   B,
 
)    x_obj_is_type((B), (X), X_TYPE_STR_NAME)

Test whether object X is a string on base B.

◆ x_strlen

#define x_strlen (   X)    x_lib_strlen(x_strval((X)))

Compute the length of a string object.

◆ x_strval

#define x_strval (   X)    x_firststr((X))

Extract the C string pointer from a string object.

◆ X_TYPE_STR_NAME

#define X_TYPE_STR_NAME   "STRING"

Type-system symbol name

Function Documentation

◆ x_make_str()

x_obj_t * x_make_str ( x_obj_t p_base,
x_obj_flag_t  flags,
x_char_t s 
)

Allocate a heap string object wrapping C string s.

Allocate a heap string object wrapping a C string pointer.

Builds a stack-based argument list and delegates to x_type_str_make.

Parameters
p_basex_obj_t* – Base (execution context)
flagsx_obj_flag_t – Object flags (e.g. X_OBJ_FLAG_OWN)
sx_char_t* – C string pointer to wrap
Returns
x_obj_t* – New heap-allocated string object

◆ x_type_str_call()

x_obj_t * x_type_str_call ( x_obj_t p_base,
x_obj_t p_args 
)

Type-system call callback – index/slice into the string.

Type-system call callback – string as callable.

Supports three calling conventions:

  • No args: returns the string length as an integer.
  • One arg (index): returns the character at that position. Negative indices count from the end.
  • Two args (start, len): returns a substring.
Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – (string-object . evaluated-args)
Returns
x_obj_t* – Integer (length), character, or substring
See also
x_type_str_length

◆ x_type_str_length()

x_obj_t * x_type_str_length ( x_obj_t p_base,
x_obj_t p_args 
)

Type-system length callback for string.

Type-system length callback – returns string length as an integer.

Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – (string-object . ...)
Returns
x_obj_t* – Integer object with string length

◆ x_type_str_make()

x_obj_t * x_type_str_make ( x_obj_t p_base,
x_obj_t p_args 
)

Type-system make callback for string.

Type-system make callback for string objects.

Extracts the string pointer and optional flags from p_args, then allocates a heap object via x_obj_make.

Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – (str-value . (flags | nil))
Returns
x_obj_t* – New heap-allocated string object

◆ x_type_str_proc()

x_obj_t * x_type_str_proc ( x_obj_t p_base,
x_obj_t p_args 
)

String procedure callback.

◆ x_type_str_read()

x_obj_t * x_type_str_read ( x_obj_t p_base,
x_obj_t p_args 
)

Tokenizer read callback for string literals.

◆ x_type_str_register()

x_obj_t * x_type_str_register ( x_obj_t p_base,
x_obj_t p_args 
)

Register (or retrieve) the string type struct on p_base.

Register or retrieve the string type on the base context.

Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – Unused
Returns
x_obj_t* – Registered type object

◆ x_type_str_struct()

x_obj_t * x_type_str_struct ( x_obj_t p_base,
x_obj_t p_args 
)

Build the string type descriptor struct.

◆ x_type_str_write()

x_obj_t * x_type_str_write ( x_obj_t p_base,
x_obj_t p_args 
)

Type-system write callback for string (quoted output).