mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
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:
@@ -45,6 +45,28 @@ void VVV_fillstring(
|
||||
puts(message); \
|
||||
}
|
||||
|
||||
/* Don't call this directly; use the VVV_between macro. */
|
||||
void _VVV_between(
|
||||
const char* original,
|
||||
const size_t left_length,
|
||||
char* middle,
|
||||
const size_t right_length,
|
||||
const size_t middle_size
|
||||
);
|
||||
|
||||
/* If original is "LEFTMIDDLERIGHT", VVV_between(original, "LEFT", buffer, "RIGHT")
|
||||
* will put "MIDDLE" into buffer - assuming that sizeof(buffer) refers to length
|
||||
* of buffer and not length of pointer to buffer.
|
||||
*/
|
||||
#define VVV_between(original, left, middle, right) \
|
||||
_VVV_between( \
|
||||
original, \
|
||||
SDL_arraysize(left) - 1, \
|
||||
middle, \
|
||||
SDL_arraysize(right) - 1, \
|
||||
sizeof(middle) \
|
||||
)
|
||||
|
||||
|
||||
//helperClass
|
||||
class UtilityClass
|
||||
|
||||
Reference in New Issue
Block a user