This module defines a type str_t
(as a synonym for const char *
)
which is always used for null-termined constant character arrays
in the SLP-system.
Also a constant STR_NIL is defined.
Furthermore, there are a few utility functions for strings.
void str_cpy(char* buf, int len, str_t str)
;strcpy
standard library function.
It copies the characters of str
one by one into the buffer buf
,
just as strcpy
does.
However, the size size
of the buffer is respected.
If it is too small,
as many as possible characters are copied,
and the buffer contents is ended in "...".
Also,
the routine doesn't crash if buf
or str
are NIL.
If str
is NIL, but buf
is not,
"<NIL>" is written into the buffer.
void str_cat(char* buf, int len, str_t str)
;str
one by one into the buffer buf
,
but after the string which is already contained in buf
.
So it concatenates both strings,
just as the standard library function strcat
does.
However, it is more secure
(see the explanation under str_cpy
,
which is used internally for copying the characters).
bool_t str_eq(str_t str1, str_t str2)
;str1
and str2
character by character.
If the strings are equal,
BOOL_TRUE
is returned,
otherwise BOOL_FALSE
.
This function is related to the standard library function
strcmp
,
but it avoids the possible trap
that strcmp
always returns the wrong value
if interpreted as boolean value.
bool_t str_contains(char c, str_t str)
;BOOL_TRUE
if str
contains c
,
and BOOL_FALSE
otherwise.
If str
is NIL,
the function doesn't crash, but returns BOOL_FALSE
.
If str
is not NIL,
but c
is the null character,
the function currently returns BOOL_TRUE
(this might change in future versions).