Factor out "between" calculation to macro and func

FILESYSTEM_mountAssets() has a big comment describing the magic numbers
needed to grab FILENAME from a string that looks like
"levels/FILENAME.vvvvvv".

Instead of doing that (and having to write a comment every time the
similar happens), I've written a macro (and helper function) instead
that does the same thing, but clearly conveys the intent.

I mean, just look at the diff. Using VVV_between() is much better than
having to read that comment, and the corresponding SDL_strlcpy().
This commit is contained in:
Misa
2021-05-20 14:14:08 -07:00
committed by Ethan Lee
parent 29d2637abd
commit 153a5c4c3a
3 changed files with 38 additions and 14 deletions

View File

@@ -344,3 +344,18 @@ void VVV_fillstring(
SDL_memset(buffer, fillchar, buffer_size - 1);
buffer[buffer_size - 1] = '\0';
}
void _VVV_between(
const char* original,
const size_t left_length,
char* middle,
const size_t right_length,
const size_t middle_size
) {
size_t middle_length = SDL_strlen(original);
middle_length -= left_length + right_length;
SDL_strlcpy(
middle,
&original[left_length],
VVV_min(middle_length + 1, middle_size)
);
}