No matching definitions.

tur/string-slice

stdlib/string-slice.tur

StringSlice: a zero-copy, bounds-checked view into a String.

Since: v2 (owned-string-type-plan -- String slices)

defopaque

StringSlice

(StringSlice)
defn

string/slice

(string/slice [s : String off : int len : int] :)

a zero-copy view of String s over bytes [off, off+len).

sthe parent String (retained by the slice)
offstart byte offset (clamped into [0, len s])
lennumber of bytes (clamped so off+len <= len s)

A StringSlice viewing the requested range.

(slice/to-cstr (string/slice (string/from-cstr "hello world") 6 5))  ; => "world"

Since: v2

defn

string/slice-cstr

(string/slice-cstr [s : cstr off : int len : int] :)

slice a raw cstr safely by copying it into an owned

Since: v2

defn

slice/retain

(slice/retain [sl : StringSlice] :)

increment the slice's refcount, returning a second handle.

Since: v2

defn

slice/release

(slice/release [sl : StringSlice] :)

decrement the slice's refcount; at zero, release the parent.

Since: v2

defn

slice/len

(slice/len [sl : StringSlice] :)

byte length of the slice.

Since: v2

defn

slice/empty?

(slice/empty? [sl : StringSlice] :)

true iff the slice has length zero.

Since: v2

defn

slice/byte-at

(slice/byte-at [sl : StringSlice i : int] :)

the byte (0..255) at index i, or -1 if out of range.

Since: v2

defn

slice/compare

(slice/compare [a : StringSlice b : StringSlice] :)

lexicographic byte compare of two slices: -1, 0, or 1.

Since: v2

defn

slice/eq?

(slice/eq? [a : StringSlice b : StringSlice] :)

content equality of two slices.

Since: v2

defn

slice/hash

(slice/hash [sl : StringSlice] :)

content hash over the slice's byte range.

Since: v2

defn

slice/sub

(slice/sub [sl : StringSlice off : int len : int] :)

a sub-view [off, off+len) RELATIVE to this slice (clamped).

(let [w (string/slice (string/from-cstr "hello world") 6 5)]  ; "world"
    (slice/to-cstr (slice/sub w 0 3)))                          ; => "wor"

Since: v2

defn

slice/to-string

(slice/to-string [sl : StringSlice] :)

copy the slice's range into a fresh owned String.

Since: v2

defn

slice/to-cstr

(slice/to-cstr [sl : StringSlice] :)

copy the slice's range into a fresh NUL-terminated cstr.

Since: v2

definstance

Eq[StringSlice]

(definstance Eq [StringSlice])

content equality (no allocation).

definstance

Ord[StringSlice]

(definstance Ord [StringSlice])

lexicographic byte ordering.

definstance

Show[StringSlice]

(definstance Show [StringSlice])

the slice content as a fresh owned String.

definstance

Hash[StringSlice]

(definstance Hash [StringSlice])

content hash over the byte range.