2017-11-23 17:23:05 +01:00
|
|
|
#include "global.h"
|
|
|
|
#include "text.h"
|
2018-07-25 06:18:23 +02:00
|
|
|
#include "dynamic_placeholder_text_util.h"
|
2017-11-23 17:23:05 +01:00
|
|
|
#include "string_util.h"
|
|
|
|
|
|
|
|
static EWRAM_DATA const u8 *sStringPointers[8] = {};
|
|
|
|
|
2018-07-25 06:18:23 +02:00
|
|
|
void DynamicPlaceholderTextUtil_Reset(void)
|
2017-11-23 17:23:05 +01:00
|
|
|
{
|
|
|
|
const u8 **ptr;
|
|
|
|
u8 *fillval;
|
|
|
|
const u8 **ptr2;
|
|
|
|
|
|
|
|
ptr = sStringPointers;
|
|
|
|
fillval = NULL;
|
|
|
|
ptr2 = ptr + (ARRAY_COUNT(sStringPointers) - 1);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*ptr2-- = fillval;
|
|
|
|
} while ((int)ptr2 >= (int)ptr);
|
|
|
|
}
|
|
|
|
|
2018-07-25 06:18:23 +02:00
|
|
|
void DynamicPlaceholderTextUtil_SetPlaceholderPtr(u8 idx, const u8 *ptr)
|
2017-11-23 17:23:05 +01:00
|
|
|
{
|
|
|
|
if (idx < ARRAY_COUNT(sStringPointers))
|
|
|
|
{
|
|
|
|
sStringPointers[idx] = ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 06:18:23 +02:00
|
|
|
u8 *DynamicPlaceholderTextUtil_ExpandPlaceholders(u8 *dest, const u8 *src)
|
2017-11-23 17:23:05 +01:00
|
|
|
{
|
|
|
|
while (*src != EOS)
|
|
|
|
{
|
2020-08-11 05:50:49 +02:00
|
|
|
if (*src != CHAR_DYNAMIC)
|
2017-11-23 17:23:05 +01:00
|
|
|
{
|
|
|
|
*dest++ = *src++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src++;
|
|
|
|
if (sStringPointers[*src] != NULL)
|
|
|
|
{
|
|
|
|
dest = StringCopy(dest, sStringPointers[*src]);
|
|
|
|
}
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*dest = EOS;
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2018-07-25 06:18:23 +02:00
|
|
|
const u8 *DynamicPlaceholderTextUtil_GetPlaceholderPtr(u8 idx)
|
2017-11-23 17:23:05 +01:00
|
|
|
{
|
|
|
|
return sStringPointers[idx];
|
|
|
|
}
|