tur/string
owned, immutable, refcounted String.
Since: v2 (owned-string-type-plan)
String
(String)
StringBuilder
(StringBuilder)
string/from-cstr
(string/from-cstr [s :cstr] :String)
copy a NUL-terminated C string into a fresh owned String.
| s | the source cstr (a literal or borrowed buffer); its bytes are copied |
A new String (refcount 1) owning a private copy of s's bytes.
(string/from-cstr "hello") ; => String "hello"
Since: v2
string/to-cstr
(string/to-cstr [s :String] :cstr)
borrow the String's NUL-terminated bytes (O(1), no copy).
| s | the String to borrow from |
A borrowed cstr view of the same bytes.
(string/to-cstr (string/from-cstr "hi")) ; => "hi"
Since: v2
string/adopt-cstr
(string/adopt-cstr [s :cstr] :String)
take ownership of a freshly-allocated cstr as a String.
| s | a freshly heap-allocated NUL-terminated cstr; consumed (freed) |
A new owned String holding a copy of s's bytes.
Since: v2 (string-adoption-stdlib-plan, batch 1)
int->string
(int->string [v :int] :String)
format a signed integer as a fresh owned decimal String.
| v | the integer to render |
A new owned String, e.g. (int->string -7) => String "-7".
(string/to-cstr (int->string 42)) ; => "42"
Since: v2 (string-adoption-stdlib-plan, batch 1)
string/retain
(string/retain [s :String] :String)
increment the refcount, returning a second owning handle.
Since: v2
string/release
(string/release [s :String] :void)
decrement the refcount; free the payload at zero.
Since: v2
string/len
(string/len [s :String] :int)
byte length of the String (not counting the NUL).
Since: v2
string/empty?
(string/empty? [s :String] :bool)
true iff the String has length zero.
Since: v2
string/byte-at
(string/byte-at [s :String i :int] :int)
the byte (0..255) at index i, or -1 if out of range.
Since: v2
string/eq?
(string/eq? [a :String b :String] :bool)
content equality (length then byte compare).
Since: v2
string/compare
(string/compare [a :String b :String] :int)
lexicographic byte compare: -1, 0, or 1.
Since: v2
string/hash
(string/hash [s :String] :int)
content hash over the exact byte range (length-aware).
Since: v2
string/starts-with?
(string/starts-with? [s :String prefix :String] :bool)
true iff s begins with prefix.
Since: v2
string/ends-with?
(string/ends-with? [s :String suffix :String] :bool)
true iff s ends with suffix.
Since: v2
string/contains?
(string/contains? [s :String needle :String] :bool)
true iff needle occurs as a substring of s.
Since: v2
string/concat
(string/concat [a :String b :String] :String)
concatenate two Strings into a fresh String.
Since: v2
string/substring
(string/substring [s :String start :int len :int] :String)
fresh String of len bytes starting at start (clamped).
Since: v2
string/to-upper
(string/to-upper [s :String] :String)
ASCII-uppercased copy.
Since: v2
string/to-lower
(string/to-lower [s :String] :String)
ASCII-lowercased copy.
Since: v2
string/trim
(string/trim [s :String] :String)
copy with ASCII leading/trailing whitespace removed.
Since: v2
builder/new
(builder/new :StringBuilder)
a fresh empty StringBuilder (mutable, growable byte buffer).
Since: v2
builder/push-cstr!
(builder/push-cstr! [b :StringBuilder s :cstr] :void)
append a cstr's bytes to the builder.
Since: v2
builder/push-string!
(builder/push-string! [b :StringBuilder s :String] :void)
append a String's bytes to the builder.
Since: v2
builder/push-byte!
(builder/push-byte! [b :StringBuilder c :int] :void)
append a single byte (0..255) to the builder.
Since: v2
builder/len
(builder/len [b :StringBuilder] :int)
number of bytes accumulated so far.
Since: v2
builder/finish
(builder/finish [b :StringBuilder] :String)
freeze the accumulated bytes into an immutable String.
(let [b (builder/new)]
(do (builder/push-cstr! b "a")
(builder/push-cstr! b "b")
(builder/finish b))) ; => String "ab"
Since: v2
Eq[String]
(definstance Eq [String])
content equality.
Ord[String]
(definstance Ord [String])
lexicographic byte ordering.
Hash[String]
(definstance Hash [String])
content hash over the byte range.
Clone[String]
(definstance Clone [String])
O(1) retain (refcount++), returning a second owning handle.
Drop[String]
(definstance Drop [String])
release one owning handle (refcount--), freeing at zero.
Since: v2 (Model R)
MapKey[String]
(definstance MapKey [String])
owned key: the map copies the bytes into a boxed key it
Internal definitions
string/autolink-hint-- internal marker triggering tur_string.c compilation.