rgbds
rgbds copied to clipboard
Don't terminate RGBDS strings with a NUL
The man page mentions that a NUL truncates a string; this is because RGBDS maps transparently to C strings. People may want to use other terminators (hello Pokémon and its $50, though there 0 is a mostly useless char anyways), or just use 0 in the middle of their strings. Thus, and especially as fixed-size buffers are mostly being used anyways, RGBDS should use Pascal strings instead.
AFAIK, Pascal strings store their length in a single byte just before the contents. This has the disadvantage of limiting the maximum length of a string. I'd like to suggest Rust-style strings instead, where strings are essentially manipulated as a pair of (pointer to start, length). Apart from removing the string length limit, this also allows to pass substrings around much more efficiently.
Okay, I wasn't intending exactly on using a byte, but the more general idea of storing the length separately. Wasn't aware of Rust's behavior, which is basically what I'm shooting for.
If you're using C99, you can just use a flexible array member to store the data, which makes the Pascal-like approach a lot simpler:
struct string {
unsigned length;
char data[];
};