parent
1f66f0d9a2
commit
d5aab98ac9
22
src/text.c
22
src/text.c
@ -1102,24 +1102,26 @@ unsigned int TextLength(const char *text)
|
||||
}
|
||||
|
||||
// Formatting of text with variables to 'embed'
|
||||
// WARNING: the string returned will expire after this function is called MAX_TEXT_BUFFERS times
|
||||
// WARNING: String returned will expire after this function is called MAX_TEXTFORMAT_BUFFERS times
|
||||
const char *TextFormat(const char *text, ...)
|
||||
{
|
||||
#define MAX_TEXT_BUFFERS 8
|
||||
// We create an array of buffers so strings don't expire until MAX_TEXT_BUFFERS invocations
|
||||
static char cache[MAX_TEXT_BUFFERS][MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
#define MAX_TEXTFORMAT_BUFFERS 4
|
||||
|
||||
// We create an array of buffers so strings don't expire until MAX_TEXTFORMAT_BUFFERS invocations
|
||||
static char buffers[MAX_TEXTFORMAT_BUFFERS][MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
static int index = 0;
|
||||
char *buffer = cache[index];
|
||||
index += 1;
|
||||
index %= MAX_TEXT_BUFFERS;
|
||||
|
||||
char *currentBuffer = buffers[index];
|
||||
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
vsprintf(buffer, text, args);
|
||||
vsprintf(currentBuffer, text, args);
|
||||
va_end(args);
|
||||
|
||||
index += 1; // Move to next buffer for next function call
|
||||
if (index >= MAX_TEXTFORMAT_BUFFERS) index = 0;
|
||||
|
||||
return buffer;
|
||||
#undef MAX_TEXT_BUFFERS
|
||||
return currentBuffer;
|
||||
}
|
||||
|
||||
// Get a piece of a text string
|
||||
|
Loading…
Reference in New Issue
Block a user