No matching definitions.

tur/str

stdlib/str.tur

UTF-8 string view (pointer + length).

Since: Phase B1

defn

str-from-cstr

(str-from-cstr [cstr])

create a str view from a NUL-terminated C string.

cstrNUL-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>
defn

str-len

(str-len [s] :int)

return the length of a str in bytes.

sstr pointer returned by str-from-cstr

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.

s1first str pointer
s2second 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

defn

str-free

(str-free [s])

free the str struct (does not free the underlying string data).

sstr pointer to free
(str-free my-str)
defn

str-concat

(str-concat [a :cstr b :cstr] :cstr)

concatenate two NUL-terminated strings into a new heap buffer.

afirst :cstr (NUL-terminated)
bsecond :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

definstance

Eq[str]

(definstance Eq [str])

eq? delegates to str-eq? for byte-level string equality.

defn

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

defn

cstr->parse-int

(cstr->parse-int [s :int] :int)

parse a raw int (cstr pointer stored as int64) to int64.

sraw :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