summaryrefslogtreecommitdiff
path: root/src/dynamic_placeholder_text_util.c
diff options
context:
space:
mode:
authorDiegoisawesome <Diegoisawesome@users.noreply.github.com>2018-07-25 08:10:18 -0700
committerGitHub <noreply@github.com>2018-07-25 08:10:18 -0700
commit919e7b4387556ce59e2d3a3bcb2ad44fe76ee8ee (patch)
tree345f52571b2d6c5505441e914f73d576acff7c9a /src/dynamic_placeholder_text_util.c
parent5883f867f00b8cc3f3630a8ab4aa2e9d21406949 (diff)
parent7270e73fee332d53c4f30069af4525d89cd165b0 (diff)
Merge pull request #279 from Diegoisawesome/master
Move strings to C, misc cleanup
Diffstat (limited to 'src/dynamic_placeholder_text_util.c')
-rw-r--r--src/dynamic_placeholder_text_util.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/dynamic_placeholder_text_util.c b/src/dynamic_placeholder_text_util.c
new file mode 100644
index 000000000..bdfcf6653
--- /dev/null
+++ b/src/dynamic_placeholder_text_util.c
@@ -0,0 +1,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_SPECIAL_F7)
+ {
+ *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];
+}