Skip to main content

Module string

Module string 

Source
Expand description

string submodule. String manipulation utilities for zshrs

Direct port of Src/string.c (201 lines, 11 ported).

Duplicate string on heap when length is known // c:44 Append a string to an allocated string, reallocating to make room. // c:182

C zsh distinguishes two allocation lanes — zalloc (permanent storage, freed by zsfree) and zhalloc (heap-arena, bulk- freed at the end of the current dispatch). Rust’s String always owns its allocation and Drops when it falls out of scope, so the two lanes collapse into one. The function names below are kept verbatim for caller-side parity with the C source — passing through to a single owned String regardless of whether C would have used zalloc or zhalloc.

Byte-faithfulness: C’s memcpy(r, s, len) copies bytes without regard for UTF-8 boundaries. The Rust ports use as_bytes slicing plus from_utf8_lossy so a len that lands mid-codepoint doesn’t panic — matching the C behavior of producing a possibly-truncated byte string.

Functions§

appstr
Port of appstr(char *base, char const *append) from Src/string.c:186.
bicat
Port of bicat(const char *s1, const char *s2) from Src/string.c:145.
dupstring
Port of dupstring(const char *s) from Src/string.c:33.
dupstring_wlen
Port of dupstring_wlen(const char *s, unsigned len) from Src/string.c:48.
dupstrpfx
Port of dupstrpfx(const char *s, int len) from Src/string.c:161.
dyncat
Port of dyncat(const char *s1, const char *s2) from Src/string.c:131.
strend
Port of strend(char *str) from Src/string.c:196.
tricat
Port of tricat(char const *s1, char const *s2, char const *s3) from Src/string.c:98.
wcs_ztrdup
Port of wcs_ztrdup(const wchar_t *s) from Src/string.c:77.
zhtricat
Port of zhtricat(char const *s1, char const *s2, char const *s3) from Src/string.c:114.
ztrdup
Port of ztrdup(const char *s) from Src/string.c:62.
ztrduppfx
Port of ztrduppfx(const char *s, int len) from Src/string.c:172.