forked from pret/pokeemerald
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdynamic_placeholder_text_util.c
56 lines (50 loc) · 1.13 KB
/
dynamic_placeholder_text_util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "global.h"
#include "text.h"
#include "dynamic_placeholder_text_util.h"
#include "string_util.h"
static EWRAM_DATA const u8 *sStringPointers[8] = {};
void DynamicPlaceholderTextUtil_Reset(void)
{
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);
}
void DynamicPlaceholderTextUtil_SetPlaceholderPtr(u8 idx, const u8 *ptr)
{
if (idx < ARRAY_COUNT(sStringPointers))
{
sStringPointers[idx] = ptr;
}
}
u8 *DynamicPlaceholderTextUtil_ExpandPlaceholders(u8 *dest, const u8 *src)
{
while (*src != EOS)
{
if (*src != CHAR_DYNAMIC)
{
*dest++ = *src++;
}
else
{
src++;
if (sStringPointers[*src] != NULL)
{
dest = StringCopy(dest, sStringPointers[*src]);
}
src++;
}
}
*dest = EOS;
return dest;
}
const u8 *DynamicPlaceholderTextUtil_GetPlaceholderPtr(u8 idx)
{
return sStringPointers[idx];
}