tur/string-slice
StringSlice: a zero-copy, bounds-checked view into a String.
Since: v2 (owned-string-type-plan -- String slices)
StringSlice
(StringSlice)
string/slice
(string/slice [s :String off :int len :int] :StringSlice)
a zero-copy view of String s over bytes [off, off+len).
| s | the parent String (retained by the slice) | |
| off | start byte offset (clamped into [0, len s]) | |
| len | number 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
string/slice-cstr
(string/slice-cstr [s :cstr off :int len :int] :StringSlice)
slice a raw cstr safely by copying it into an owned
Since: v2
slice/retain
(slice/retain [sl :StringSlice] :StringSlice)
increment the slice's refcount, returning a second handle.
Since: v2
slice/release
(slice/release [sl :StringSlice] :void)
decrement the slice's refcount; at zero, release the parent.
Since: v2
slice/len
(slice/len [sl :StringSlice] :int)
byte length of the slice.
Since: v2
slice/empty?
(slice/empty? [sl :StringSlice] :bool)
true iff the slice has length zero.
Since: v2
slice/byte-at
(slice/byte-at [sl :StringSlice i :int] :int)
the byte (0..255) at index i, or -1 if out of range.
Since: v2
slice/compare
(slice/compare [a :StringSlice b :StringSlice] :int)
lexicographic byte compare of two slices: -1, 0, or 1.
Since: v2
slice/eq?
(slice/eq? [a :StringSlice b :StringSlice] :bool)
content equality of two slices.
Since: v2
slice/hash
(slice/hash [sl :StringSlice] :int)
content hash over the slice's byte range.
Since: v2
slice/sub
(slice/sub [sl :StringSlice off :int len :int] :StringSlice)
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
slice/to-string
(slice/to-string [sl :StringSlice] :String)
copy the slice's range into a fresh owned String.
Since: v2
slice/to-cstr
(slice/to-cstr [sl :StringSlice] :cstr)
copy the slice's range into a fresh NUL-terminated cstr.
Since: v2
Eq[StringSlice]
(definstance Eq [StringSlice])
content equality (no allocation).
Ord[StringSlice]
(definstance Ord [StringSlice])
lexicographic byte ordering.
Show[StringSlice]
(definstance Show [StringSlice])
the slice content as a fresh owned String.
Hash[StringSlice]
(definstance Hash [StringSlice])
content hash over the byte range.