diff options
Diffstat (limited to 'src/string_util.c')
-rw-r--r-- | src/string_util.c | 135 |
1 files changed, 57 insertions, 78 deletions
diff --git a/src/string_util.c b/src/string_util.c index a7f9c3d1f..9686256a1 100644 --- a/src/string_util.c +++ b/src/string_util.c @@ -1,30 +1,14 @@ #include "global.h" #include "string_util.h" +#include "strings.h" #include "text.h" -#define MAX_PLACEHOLDER_ID 0xD - -static u8 *ExpandPlaceholder_UnknownStringVar(void); -static u8 *ExpandPlaceholder_PlayerName(void); -static u8 *ExpandPlaceholder_StringVar1(void); -static u8 *ExpandPlaceholder_StringVar2(void); -static u8 *ExpandPlaceholder_StringVar3(void); -static u8 *ExpandPlaceholder_KunChan(void); -static u8 *ExpandPlaceholder_RivalName(void); -static u8 *ExpandPlaceholder_Version(void); -static u8 *ExpandPlaceholder_EvilTeam(void); -static u8 *ExpandPlaceholder_GoodTeam(void); -static u8 *ExpandPlaceholder_EvilLeader(void); -static u8 *ExpandPlaceholder_GoodLeader(void); -static u8 *ExpandPlaceholder_EvilLegendary(void); -static u8 *ExpandPlaceholder_GoodLegendary(void); - u8 gUnknownStringVar[16]; -const u8 gEmptyString_81E72B0[] = _""; -const u8 gRightPointingTriangleString[] = _"▶"; +const u8 gEmptyString_81E72B0[] = _(""); +const u8 gRightPointingTriangleString[] = _("▶"); -static const u8 sDigits[] = @"0123456789ABCDEF"; +static const u8 sDigits[] = __("0123456789ABCDEF"); static const s32 sPowersOfTen[] = { @@ -40,43 +24,6 @@ static const s32 sPowersOfTen[] = 1000000000, }; -static const u8 sSetBrailleFont[] = { 0xFC, 0x06, 0x06, 0xFF }; -static const u8 sGotoLine2[] = { 0xFE, 0xFC, 0x0E, 0x02, 0xFF }; - -typedef u8 *(*ExpandPlaceholderFunc)(void); - -static const ExpandPlaceholderFunc sExpandPlaceholderFuncs[] = -{ - ExpandPlaceholder_UnknownStringVar, - ExpandPlaceholder_PlayerName, - ExpandPlaceholder_StringVar1, - ExpandPlaceholder_StringVar2, - ExpandPlaceholder_StringVar3, - ExpandPlaceholder_KunChan, - ExpandPlaceholder_RivalName, - ExpandPlaceholder_Version, - ExpandPlaceholder_EvilTeam, - ExpandPlaceholder_GoodTeam, - ExpandPlaceholder_EvilLeader, - ExpandPlaceholder_GoodLeader, - ExpandPlaceholder_EvilLegendary, - ExpandPlaceholder_GoodLegendary, -}; - -extern u8 gExpandedPlaceholder_Empty[]; -extern u8 gExpandedPlaceholder_Kun[]; -extern u8 gExpandedPlaceholder_Chan[]; -extern u8 gExpandedPlaceholder_Sapphire[]; -extern u8 gExpandedPlaceholder_Ruby[]; -extern u8 gExpandedPlaceholder_Aqua[]; -extern u8 gExpandedPlaceholder_Magma[]; -extern u8 gExpandedPlaceholder_Archie[]; -extern u8 gExpandedPlaceholder_Maxie[]; -extern u8 gExpandedPlaceholder_Kyogre[]; -extern u8 gExpandedPlaceholder_Groudon[]; -extern u8 gExpandedPlaceholder_Brendan[]; -extern u8 gExpandedPlaceholder_May[]; - u8 *StringCopy10(u8 *dest, const u8 *src) { u8 i; @@ -177,6 +124,21 @@ u16 StringLength(const u8 *str) return length; } +#ifdef GERMAN +s32 StringLengthN(const u8 *str, s32 n) +{ + s32 i; + + for (i = 0; i < n && str[i] != EOS; i++) + ; + + if (i == n) + i = 0; + + return i; +} +#endif + s32 StringCompare(const u8 *str1, const u8 *str2) { while (*str1 == *str2) @@ -445,11 +407,8 @@ u8 *StringExpandPlaceholders(u8 *dest, const u8 *src) u8 *StringBraille(u8 *dest, const u8 *src) { - u8 setBrailleFont[4]; - u8 gotoLine2[5]; - - memcpy(setBrailleFont, sSetBrailleFont, 4); - memcpy(gotoLine2, sGotoLine2, 5); + u8 setBrailleFont[] = { 0xFC, 0x06, 0x06, 0xFF }; + u8 gotoLine2[] = { 0xFE, 0xFC, 0x0E, 0x02, 0xFF }; dest = StringCopy(dest, setBrailleFont); @@ -473,45 +432,45 @@ u8 *StringBraille(u8 *dest, const u8 *src) } } -u8 *ExpandPlaceholder_UnknownStringVar(void) +static u8 *ExpandPlaceholder_UnknownStringVar(void) { return gUnknownStringVar; } -u8 *ExpandPlaceholder_PlayerName(void) +static u8 *ExpandPlaceholder_PlayerName(void) { return gSaveBlock2.playerName; } -u8 *ExpandPlaceholder_StringVar1(void) +static u8 *ExpandPlaceholder_StringVar1(void) { return gStringVar1; } -u8 *ExpandPlaceholder_StringVar2(void) +static u8 *ExpandPlaceholder_StringVar2(void) { return gStringVar2; } -u8 *ExpandPlaceholder_StringVar3(void) +static u8 *ExpandPlaceholder_StringVar3(void) { return gStringVar3; } -u8 *ExpandPlaceholder_KunChan(void) +static u8 *ExpandPlaceholder_KunChan(void) { if (gSaveBlock2.playerGender == MALE) - return gExpandedPlaceholder_Kun; + return (u8 *) gExpandedPlaceholder_Kun; else - return gExpandedPlaceholder_Chan; + return (u8 *) gExpandedPlaceholder_Chan; } -u8 *ExpandPlaceholder_RivalName(void) +static u8 *ExpandPlaceholder_RivalName(void) { if (gSaveBlock2.playerGender == MALE) - return gExpandedPlaceholder_May; + return (u8 *) gExpandedPlaceholder_May; else - return gExpandedPlaceholder_Brendan; + return (u8 *) gExpandedPlaceholder_Brendan; } #define VERSION_DEPENDENT_PLACEHOLDER_LIST \ @@ -525,11 +484,11 @@ u8 *ExpandPlaceholder_RivalName(void) #ifdef SAPPHIRE #define X(ph, r, s) \ -static u8 *ExpandPlaceholder_##ph(void) { return gExpandedPlaceholder_##s; } +static u8 *ExpandPlaceholder_##ph(void) { return (u8 *) gExpandedPlaceholder_##s; } VERSION_DEPENDENT_PLACEHOLDER_LIST #else #define X(ph, r, s) \ -static u8 *ExpandPlaceholder_##ph(void) { return gExpandedPlaceholder_##r; } +static u8 *ExpandPlaceholder_##ph(void) { return (u8 *) gExpandedPlaceholder_##r; } VERSION_DEPENDENT_PLACEHOLDER_LIST #endif @@ -537,10 +496,30 @@ VERSION_DEPENDENT_PLACEHOLDER_LIST u8 *GetExpandedPlaceholder(u32 id) { - if (id > MAX_PLACEHOLDER_ID) - return gExpandedPlaceholder_Empty; + typedef u8 *(*ExpandPlaceholderFunc)(void); + + static const ExpandPlaceholderFunc funcs[] = + { + ExpandPlaceholder_UnknownStringVar, + ExpandPlaceholder_PlayerName, + ExpandPlaceholder_StringVar1, + ExpandPlaceholder_StringVar2, + ExpandPlaceholder_StringVar3, + ExpandPlaceholder_KunChan, + ExpandPlaceholder_RivalName, + ExpandPlaceholder_Version, + ExpandPlaceholder_EvilTeam, + ExpandPlaceholder_GoodTeam, + ExpandPlaceholder_EvilLeader, + ExpandPlaceholder_GoodLeader, + ExpandPlaceholder_EvilLegendary, + ExpandPlaceholder_GoodLegendary, + }; + + if (id >= ARRAY_COUNT(funcs)) + return (u8 *) gExpandedPlaceholder_Empty; else - return sExpandPlaceholderFuncs[id](); + return funcs[id](); } u8 *StringFill(u8 *dest, u8 c, u16 n) |