libsnobol4 1.0.2
High-performance SNOBOL4-style pattern matching library
Loading...
Searching...
No Matches
type_fn.h File Reference

SNOBOL4 built-in comparison and type-checking functions. More...

#include <stdbool.h>
#include "snobol/c23_compat.h"
#include <stddef.h>
Include dependency graph for type_fn.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

double snobol_str_to_double (const char *s, size_t len)
bool snobol_eq (const char *a, size_t a_len, const char *b, size_t b_len)
bool snobol_ne (const char *a, size_t a_len, const char *b, size_t b_len)
bool snobol_lt (const char *a, size_t a_len, const char *b, size_t b_len)
bool snobol_gt (const char *a, size_t a_len, const char *b, size_t b_len)
bool snobol_le (const char *a, size_t a_len, const char *b, size_t b_len)
bool snobol_ge (const char *a, size_t a_len, const char *b, size_t b_len)
bool snobol_ident (const char *a, size_t a_len, const char *b, size_t b_len)
bool snobol_differ (const char *a, size_t a_len, const char *b, size_t b_len)
bool snobol_lexeq (const char *a, size_t a_len, const char *b, size_t b_len)
bool snobol_lexlt (const char *a, size_t a_len, const char *b, size_t b_len)
bool snobol_lexgt (const char *a, size_t a_len, const char *b, size_t b_len)
bool snobol_integer (const char *str, size_t len)
bool snobol_real (const char *str, size_t len)
bool snobol_numeric (const char *str, size_t len)

Detailed Description

SNOBOL4 built-in comparison and type-checking functions.

Comparison functions use lexicographic (byte-level) ordering. Type predicates check string format for numeric types.

All predicates return true (succeed) or false (fail), matching SNOBOL4 semantics where a failing function causes the enclosing pattern to fail.

Definition in file type_fn.h.

Function Documentation

◆ snobol_differ()

bool snobol_differ ( const char * a,
size_t a_len,
const char * b,
size_t b_len )

DIFFER: difference predicate – succeeds if two strings differ. Logical inverse of IDENT.

Parameters
aFirst string
a_lenByte length of first string
bSecond string
b_lenByte length of second string
Returns
true if strings differ, false if identical

◆ snobol_eq()

bool snobol_eq ( const char * a,
size_t a_len,
const char * b,
size_t b_len )

EQ: numeric equality – succeeds if a == b numerically. Both strings are converted to double before comparison.

Parameters
aFirst string
a_lenByte length
bSecond string
b_lenByte length
Returns
true if numeric values are equal

◆ snobol_ge()

bool snobol_ge ( const char * a,
size_t a_len,
const char * b,
size_t b_len )

GE: greater-than-or-equal – succeeds if a >= b numerically.

Parameters
aFirst string
a_lenByte length
bSecond string
b_lenByte length
Returns
true if numeric value of a is >= b

◆ snobol_gt()

bool snobol_gt ( const char * a,
size_t a_len,
const char * b,
size_t b_len )

GT: greater-than – succeeds if a > b numerically.

Parameters
aFirst string
a_lenByte length
bSecond string
b_lenByte length
Returns
true if numeric value of a is greater than b

◆ snobol_ident()

bool snobol_ident ( const char * a,
size_t a_len,
const char * b,
size_t b_len )

IDENT: identity predicate – succeeds if two strings are identical. Equivalent to strcmp == 0 on strings.

Parameters
aFirst string (UTF-8)
a_lenByte length of first string
bSecond string (UTF-8)
b_lenByte length of second string
Returns
true if strings are identical, false otherwise

◆ snobol_integer()

bool snobol_integer ( const char * str,
size_t len )

INTEGER: type predicate – succeeds if the string represents an integer. Valid format: optional +/- sign followed by one or more decimal digits.

Parameters
strInput string
lenByte length
Returns
true if string is a valid integer representation

◆ snobol_le()

bool snobol_le ( const char * a,
size_t a_len,
const char * b,
size_t b_len )

LE: less-than-or-equal – succeeds if a <= b numerically.

Parameters
aFirst string
a_lenByte length
bSecond string
b_lenByte length
Returns
true if numeric value of a is <= b

◆ snobol_lexeq()

bool snobol_lexeq ( const char * a,
size_t a_len,
const char * b,
size_t b_len )

LEXEQ: lexical equality – succeeds if a == b lexicographically. Uses memcmp with length comparison.

Parameters
aFirst string
a_lenByte length
bSecond string
b_lenByte length
Returns
true if a == b lexicographically

◆ snobol_lexgt()

bool snobol_lexgt ( const char * a,
size_t a_len,
const char * b,
size_t b_len )

LEXGT: lexical greater-than – succeeds if a > b lexicographically.

Parameters
aFirst string
a_lenByte length
bSecond string
b_lenByte length
Returns
true if a > b lexicographically

◆ snobol_lexlt()

bool snobol_lexlt ( const char * a,
size_t a_len,
const char * b,
size_t b_len )

LEXLT: lexical less-than – succeeds if a < b lexicographically.

Parameters
aFirst string
a_lenByte length
bSecond string
b_lenByte length
Returns
true if a < b lexicographically

◆ snobol_lt()

bool snobol_lt ( const char * a,
size_t a_len,
const char * b,
size_t b_len )

LT: less-than – succeeds if a < b numerically.

Parameters
aFirst string
a_lenByte length
bSecond string
b_lenByte length
Returns
true if numeric value of a is less than b

◆ snobol_ne()

bool snobol_ne ( const char * a,
size_t a_len,
const char * b,
size_t b_len )

NE: numeric inequality – succeeds if a != b numerically.

Parameters
aFirst string
a_lenByte length
bSecond string
b_lenByte length
Returns
true if numeric values differ

◆ snobol_numeric()

bool snobol_numeric ( const char * str,
size_t len )

NUMERIC: union type predicate – succeeds if the string is INTEGER or REAL. Equivalent to: snobol_integer(str, len) || snobol_real(str, len)

Parameters
strInput string
lenByte length
Returns
true if string represents any numeric value

◆ snobol_real()

bool snobol_real ( const char * str,
size_t len )

REAL: type predicate – succeeds if the string represents a real number. Valid format: optional sign, digits, optional decimal point + digits, optional exponent (e/E with optional sign and digits). Example: "12.34", "1.23e-4", "-0.5", "+1E10"

Parameters
strInput string
lenByte length
Returns
true if string is a valid real number representation

◆ snobol_str_to_double()

double snobol_str_to_double ( const char * s,
size_t len )

Convert a length-bounded string to double, following SNOBOL4 numeric conversion semantics (non-numeric strings yield 0.0).

Parameters
sInput string (UTF-8, not necessarily null-terminated)
lenByte length of input
Returns
Numeric value, or 0.0 if no numeric prefix is found