tur/str
UTF-8 string view (pointer + length).
Since: Phase B1
str-from-cstr
(str-from-cstr [cstr])
create a str view from a NUL-terminated C string.
| cstr | NUL-terminated C string pointer |
Pointer to a newly allocated str struct (p + len). Does not copy the underlying string data; the caller retains ownership of the original buffer.
(str-from-cstr "hello") ; => <str ptr>
str-len
(str-len [s] :int)
return the length of a str in bytes.
| s | str pointer returned by str-from-cstr |
Length of the string in bytes (not characters).
(str-len (str-from-cstr "hello")) ; => 5
str-eq?
(str-eq? [s1 s2] :bool)
check whether two str values have identical byte contents.
| s1 | first str pointer | |
| s2 | second str pointer |
true if both strings have the same length and identical bytes.
(str-eq? (str-from-cstr "hi") (str-from-cstr "hi")) ; => true
Since: Phase E1
str-free
(str-free [s])
free the str struct (does not free the underlying string data).
| s | str pointer to free |
(str-free my-str)
str-concat
(str-concat [a :cstr b :cstr] :cstr)
concatenate two NUL-terminated strings into a new heap buffer.
| a | first :cstr (NUL-terminated) | |
| b | second :cstr (NUL-terminated) |
A newly heap-allocated :cstr containing the bytes of a followed by b, NUL-terminated. The caller is responsible for freeing the returned pointer.
(str-concat "Hello, " "world") ; => "Hello, world"
Since: Phase B1
Eq[str]
(definstance Eq [str])
eq? delegates to str-eq? for byte-level string equality.
str->int
(str->int [s :cstr] :int)
parse a NUL-terminated :cstr to int64 (decimal).
| s | :cstr string to parse |
Parsed integer value, or 0 if s is NULL or non-numeric.
(str->int "42") ; => 42
Since: Phase B1
cstr->parse-int
(cstr->parse-int [s :int] :int)
parse a raw int (cstr pointer stored as int64) to int64.
| s | raw :int holding a char* pointer |
Parsed integer value, or 0 if pointer is NULL.
(cstr->parse-int some-int-ptr) ; => parsed int
Since: Phase B1