This currently fails:
---
void main()
{
string s = "0123";
auto c = &s[2];
s = "0";
s = s ~ "1";
assert(*c == '\0');
}
---
this would be a enhacement to support this. Example: add an extension and pass the .ptr property directly to a C style API, without having to call toUTFz / toStringz
Comment #1 by nick — 2023-07-14T13:22:46Z
The assert would fail anyway, because "0123" is immutable data. When you assign "0" to s, that is different memory and cannot affect c.
Presumably this request is for:
s = "0";
s = s ~ "1";
assert(s.ptr[2] == '\0');
That would cause unnecessary writes when appending a (short) string in a loop and each null byte is not read.
Comment #2 by b2.temp — 2023-07-14T15:16:52Z
More simply: the result of `LHS ~ RHS` should be guaranteed to be zero terminated when RHS is a StringExp.
Comment #3 by robert.schadek — 2024-12-13T19:10:02Z