dom/ownstr
owned String surface shared by tur-xml and tur-html.
Since: 0.1.0
String
(String)
an owned, refcounted, immutable string (ABI: ptr<void>).
ownstr-autolink
(ownstr-autolink :)
internal: pull src/runtime/tur_string.c into the link.
from-cstr
(from-cstr [s : cstr] :)
copy a borrowed cstr into a new owned String.
| s | any NUL-terminated cstr (borrowed; not freed) |
String -- a fresh String with refcount 1; release it when done.
(let [s (from-cstr "item")]
(println (to-cstr s)) ; prints item
(release s))
Since: 0.1.0
adopt-cstr
(adopt-cstr [s : cstr] :)
take ownership of a freshly heap-allocated cstr as a String.
| s | a malloc'd NUL-terminated cstr; consumed (freed) |
String -- a new owned String holding a copy of s's bytes.
(adopt-cstr (some-fn-returning-malloc-cstr))
Since: 0.1.0
to-cstr
(to-cstr [s : String] :)
borrow the String's NUL-terminated bytes (O(1), no copy).
| s | the String to borrow from |
cstr -- a borrowed view of the same bytes.
(println (to-cstr s))
Since: 0.1.0
retain
(retain [s : String] :)
take an extra reference to a String and return it.
| s | the String to keep |
String -- the same String, now owned once more by the caller.
(StartElement name _) (do (set! last (retain name)) (Continue))
Since: 0.1.0
release
(release [s : String] :)
drop one reference; the payload is freed at zero.
| s | the String whose owning reference is being dropped |
(release (node-text n))
Since: 0.1.0
str-len
(str-len [s : String] :)
byte length of the String (not counting the NUL).
| s | the String to measure |
int -- the byte length.
(str-len (from-cstr "abc")) ; => 3
Since: 0.1.0
Internal definitions
__from-cstr-raw-- internal: copy a cstr into a fresh String, as a carrier.__adopt-cstr-raw-- internal: adopt a heap cstr, as a carrier.__retain-raw-- internal: bump the refcount.string-- does the String hold exactly the bytes of `c`?