tur/str
stdlib/str.tur
defn
str-from-cstr
(str-from-cstr [cstr])
create a str view from a NUL-terminated C string.
Parameters
| cstr | NUL-terminated C string pointer |
Example
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>
defn
str-len
(str-len [s] :int)
return the length of a str in bytes.
Parameters
| s | str pointer returned by str-from-cstr |
Example
Length of the string in bytes (not characters). (str-len (str-from-cstr "hello")) ; => 5
defn
str-eq?
(str-eq? [s1 s2] :bool)
check whether two str values have identical byte contents.
Parameters
| s1 | first str pointer | |
| s2 | second str pointer |
Since: Phase E1
defn
str-free
(str-free [s])
free the str struct (does not free the underlying string data).
Parameters
| s | str pointer to free |
Example
(str-free my-str)
definstance
Eq[str]
(definstance Eq [str])
eq? delegates to str-eq? for byte-level string equality.