tur/string
owned, immutable, refcounted String.
Since: v2 (owned-string-type-plan)
String
(String)
StringBuilder
(StringBuilder)
string/from-cstr
(string/from-cstr [s : cstr] :)
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] :)
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] :)
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] :)
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] :)
increment the refcount, returning a second owning handle.
Since: v2
string/release
(string/release [s : String] :)
decrement the refcount; free the payload at zero.
Since: v2
string/len
(string/len [s : String] :)
byte length of the String (not counting the NUL).
Since: v2
string/empty?
(string/empty? [s : String] :)
true iff the String has length zero.
Since: v2
string/byte-at
(string/byte-at [s : String i : int] :)
the byte (0..255) at index i, or -1 if out of range.
Since: v2
string/eq?
(string/eq? [a : String b : String] :)
content equality (length then byte compare).
Since: v2
string/compare
(string/compare [a : String b : String] :)
lexicographic byte compare: -1, 0, or 1.
Since: v2
string/hash
(string/hash [s : String] :)
content hash over the exact byte range (length-aware).
Since: v2
string/starts-with?
(string/starts-with? [s : String prefix : String] :)
true iff s begins with prefix.
Since: v2
string/ends-with?
(string/ends-with? [s : String suffix : String] :)
true iff s ends with suffix.
Since: v2
string/contains?
(string/contains? [s : String needle : String] :)
true iff needle occurs as a substring of s.
Since: v2
string/concat
(string/concat [a : String b : String] :)
concatenate two Strings into a fresh String.
Since: v2
string/substring
(string/substring [s : String start : int len : int] :)
fresh String of len bytes starting at start (clamped).
Since: v2
string/to-upper
(string/to-upper [s : String] :)
ASCII-uppercased copy.
Since: v2
string/to-lower
(string/to-lower [s : String] :)
ASCII-lowercased copy.
Since: v2
string/trim
(string/trim [s : String] :)
copy with ASCII leading/trailing whitespace removed.
Since: v2
builder/new
(builder/new :)
a fresh empty StringBuilder (mutable, growable byte buffer).
Since: v2
builder/push-cstr!
(builder/push-cstr! [b : StringBuilder s : cstr] :)
append a cstr's bytes to the builder.
Since: v2
builder/push-string!
(builder/push-string! [b : StringBuilder s : String] :)
append a String's bytes to the builder.
Since: v2
builder/push-byte!
(builder/push-byte! [b : StringBuilder c : int] :)
append a single byte (0..255) to the builder.
Since: v2
builder/len
(builder/len [b : StringBuilder] :)
number of bytes accumulated so far.
Since: v2
builder/finish
(builder/finish [b : StringBuilder] :)
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.