Struct std::String
struct String {
&heap char data;
unsigned long len;
unsigned long cap;
}Fields
NUL-terminated heap buffer
byte length (not including NUL)
allocated buffer size (including NUL slot)
Methods
empty
copy of a C string
copy of the bytes (need not be NUL-terminated)
empty, room for cap bytes
s repeated n times
parts concatenated, sep between each (null sep: none)
NUL-terminated C string
the len bytes (no NUL); valid until the next change
-1 if OOB
ensure room for len + additional bytes
reduce cap to len + 1
append the bytes (need not be NUL-terminated)
first occurrence
Single left-to-right pass into a freshly-sized buffer — O(n). The previous implementation called index_of() (a full O(n) scan from the start of the string, not from the current position) once per match, then shifted the whole remaining tail via remove_range()+insert() for each one — O(matches * n) overall, quadratic for a string with many matches.
in-place byte reversal
remove last byte, return it (-1 if empty)
index of first c, or -1
index of last c, or -1
remove prefix if present, else clone
remove suffix if present, else clone
repeat content n times
uppercase first byte, lowercase rest
All split methods write into the caller's out slots (out.len of them).
Return value = number of items written.
If splits exceed out.len, the last slot receives the remainder.
<0, 0, >0
frees the buffer (Drop)
= drop()