pokeemerald/gflib/string_util.c

771 lines
15 KiB
C
Raw Normal View History

2017-01-14 20:53:20 +01:00
#include "global.h"
#include "string_util.h"
#include "text.h"
2019-12-05 21:33:36 +01:00
#include "strings.h"
2017-01-14 20:53:20 +01:00
2018-11-19 01:03:14 +01:00
EWRAM_DATA u8 gStringVar1[0x100] = {0};
EWRAM_DATA u8 gStringVar2[0x100] = {0};
EWRAM_DATA u8 gStringVar3[0x100] = {0};
EWRAM_DATA u8 gStringVar4[0x3E8] = {0};
EWRAM_DATA static u8 sUnknownStringVar[16] = {0};
2017-01-14 20:53:20 +01:00
2017-02-01 06:31:28 +01:00
static const u8 sDigits[] = __("0123456789ABCDEF");
2017-01-14 20:53:20 +01:00
2017-01-15 00:17:51 +01:00
static const s32 sPowersOfTen[] =
{
1,
10,
100,
1000,
10000,
100000,
1000000,
10000000,
100000000,
1000000000,
};
2017-01-14 20:53:20 +01:00
u8 *StringCopy10(u8 *dest, const u8 *src)
{
u8 i;
u32 limit = 10;
for (i = 0; i < limit; i++)
{
dest[i] = src[i];
if (dest[i] == EOS)
return &dest[i];
}
dest[i] = EOS;
return &dest[i];
}
u8 *StringGetEnd10(u8 *str)
{
u8 i;
u32 limit = 10;
for (i = 0; i < limit; i++)
if (str[i] == EOS)
return &str[i];
str[i] = EOS;
return &str[i];
}
u8 *StringCopy7(u8 *dest, const u8 *src)
{
s32 i;
s32 limit = 7;
for (i = 0; i < limit; i++)
{
dest[i] = src[i];
if (dest[i] == EOS)
return &dest[i];
}
dest[i] = EOS;
return &dest[i];
}
u8 *StringCopy(u8 *dest, const u8 *src)
{
while (*src != EOS)
{
*dest = *src;
dest++;
src++;
}
*dest = EOS;
return dest;
}
u8 *StringAppend(u8 *dest, const u8 *src)
{
while (*dest != EOS)
dest++;
return StringCopy(dest, src);
}
u8 *StringCopyN(u8 *dest, const u8 *src, u8 n)
{
u16 i;
for (i = 0; i < n; i++)
dest[i] = src[i];
return &dest[n];
}
u8 *StringAppendN(u8 *dest, const u8 *src, u8 n)
{
while (*dest != EOS)
dest++;
return StringCopyN(dest, src, n);
}
u16 StringLength(const u8 *str)
{
u16 length = 0;
while (str[length] != EOS)
length++;
return length;
}
s32 StringCompare(const u8 *str1, const u8 *str2)
{
while (*str1 == *str2)
{
if (*str1 == EOS)
return 0;
str1++;
str2++;
}
return *str1 - *str2;
}
s32 StringCompareN(const u8 *str1, const u8 *str2, u32 n)
{
while (*str1 == *str2)
{
if (*str1 == EOS)
return 0;
str1++;
str2++;
if (--n == 0)
return 0;
}
return *str1 - *str2;
}
bool8 IsStringLengthAtLeast(const u8 *str, s32 n)
{
u8 i;
for (i = 0; i < n; i++)
if (str[i] && str[i] != EOS)
return TRUE;
return FALSE;
}
u8 *ConvertIntToDecimalStringN(u8 *dest, s32 value, enum StringConvertMode mode, u8 n)
{
enum { WAITING_FOR_NONZERO_DIGIT, WRITING_DIGITS, WRITING_SPACES } state;
s32 powerOfTen;
s32 largestPowerOfTen = sPowersOfTen[n - 1];
state = WAITING_FOR_NONZERO_DIGIT;
if (mode == STR_CONV_MODE_RIGHT_ALIGN)
state = WRITING_SPACES;
if (mode == STR_CONV_MODE_LEADING_ZEROS)
state = WRITING_DIGITS;
for (powerOfTen = largestPowerOfTen; powerOfTen > 0; powerOfTen /= 10)
{
u8 c;
u16 digit = value / powerOfTen;
s32 temp = value - (powerOfTen * digit);
if (state == WRITING_DIGITS)
{
u8 *out = dest++;
if (digit <= 9)
c = sDigits[digit];
else
c = CHAR_QUESTION_MARK;
*out = c;
}
else if (digit != 0 || powerOfTen == 1)
{
u8 *out;
state = WRITING_DIGITS;
out = dest++;
if (digit <= 9)
c = sDigits[digit];
else
c = CHAR_QUESTION_MARK;
*out = c;
}
else if (state == WRITING_SPACES)
{
*dest++ = 0x77;
}
value = temp;
}
*dest = EOS;
return dest;
}
u8 *ConvertUIntToDecimalStringN(u8 *dest, u32 value, enum StringConvertMode mode, u8 n)
{
enum { WAITING_FOR_NONZERO_DIGIT, WRITING_DIGITS, WRITING_SPACES } state;
s32 powerOfTen;
s32 largestPowerOfTen = sPowersOfTen[n - 1];
state = WAITING_FOR_NONZERO_DIGIT;
if (mode == STR_CONV_MODE_RIGHT_ALIGN)
state = WRITING_SPACES;
if (mode == STR_CONV_MODE_LEADING_ZEROS)
state = WRITING_DIGITS;
for (powerOfTen = largestPowerOfTen; powerOfTen > 0; powerOfTen /= 10)
{
u8 c;
u16 digit = value / powerOfTen;
u32 temp = value - (powerOfTen * digit);
if (state == WRITING_DIGITS)
{
u8 *out = dest++;
if (digit <= 9)
c = sDigits[digit];
else
c = CHAR_QUESTION_MARK;
*out = c;
}
else if (digit != 0 || powerOfTen == 1)
{
u8 *out;
state = WRITING_DIGITS;
out = dest++;
if (digit <= 9)
c = sDigits[digit];
else
c = CHAR_QUESTION_MARK;
*out = c;
}
else if (state == WRITING_SPACES)
{
*dest++ = 0x77;
}
value = temp;
}
*dest = EOS;
return dest;
}
u8 *ConvertIntToHexStringN(u8 *dest, s32 value, enum StringConvertMode mode, u8 n)
{
enum { WAITING_FOR_NONZERO_DIGIT, WRITING_DIGITS, WRITING_SPACES } state;
u8 i;
s32 powerOfSixteen;
s32 largestPowerOfSixteen = 1;
for (i = 1; i < n; i++)
largestPowerOfSixteen *= 16;
state = WAITING_FOR_NONZERO_DIGIT;
if (mode == STR_CONV_MODE_RIGHT_ALIGN)
state = WRITING_SPACES;
if (mode == STR_CONV_MODE_LEADING_ZEROS)
state = WRITING_DIGITS;
for (powerOfSixteen = largestPowerOfSixteen; powerOfSixteen > 0; powerOfSixteen /= 16)
{
u8 c;
u32 digit = value / powerOfSixteen;
s32 temp = value % powerOfSixteen;
if (state == WRITING_DIGITS)
{
char *out = dest++;
if (digit <= 0xF)
c = sDigits[digit];
else
c = CHAR_QUESTION_MARK;
*out = c;
}
else if (digit != 0 || powerOfSixteen == 1)
{
char *out;
state = WRITING_DIGITS;
out = dest++;
if (digit <= 0xF)
c = sDigits[digit];
else
c = CHAR_QUESTION_MARK;
*out = c;
}
else if (state == WRITING_SPACES)
{
*dest++ = 0x77;
}
value = temp;
}
*dest = EOS;
return dest;
}
u8 *StringExpandPlaceholders(u8 *dest, const u8 *src)
{
for (;;)
{
u8 c = *src++;
u8 placeholderId;
2018-10-14 15:04:25 +02:00
const u8 *expandedString;
2017-01-14 20:53:20 +01:00
switch (c)
{
2017-03-28 02:30:49 +02:00
case PLACEHOLDER_BEGIN:
placeholderId = *src++;
expandedString = GetExpandedPlaceholder(placeholderId);
dest = StringExpandPlaceholders(dest, expandedString);
2017-01-14 20:53:20 +01:00
break;
2017-03-28 02:30:49 +02:00
case EXT_CTRL_CODE_BEGIN:
*dest++ = c;
c = *src++;
*dest++ = c;
switch (c)
{
case 0x07:
case 0x09:
case 0x0F:
case 0x15:
case 0x16:
case 0x17:
case 0x18:
break;
case 0x04:
*dest++ = *src++;
case 0x0B:
*dest++ = *src++;
default:
*dest++ = *src++;
}
break;
case EOS:
*dest = EOS;
return dest;
2018-10-14 15:04:25 +02:00
case CHAR_PROMPT_SCROLL:
case CHAR_PROMPT_CLEAR:
case CHAR_NEWLINE:
2017-01-14 20:53:20 +01:00
default:
2017-03-28 02:30:49 +02:00
*dest++ = c;
2017-01-14 20:53:20 +01:00
}
}
}
u8 *StringBraille(u8 *dest, const u8 *src)
{
2018-10-14 15:04:25 +02:00
u8 setBrailleFont[] = { EXT_CTRL_CODE_BEGIN, 0x06, 0x06, EOS };
u8 gotoLine2[] = { CHAR_NEWLINE, EXT_CTRL_CODE_BEGIN, 0x0E, 0x02, EOS };
2017-01-14 20:53:20 +01:00
dest = StringCopy(dest, setBrailleFont);
for (;;)
{
u8 c = *src++;
switch (c)
{
2017-03-28 02:30:49 +02:00
case EOS:
*dest = c;
return dest;
2018-10-14 15:04:25 +02:00
case CHAR_NEWLINE:
2017-03-28 02:30:49 +02:00
dest = StringCopy(dest, gotoLine2);
break;
default:
*dest++ = c;
*dest++ = c + 0x40;
break;
2017-01-14 20:53:20 +01:00
}
}
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_UnknownStringVar(void)
2017-01-14 20:53:20 +01:00
{
2018-11-19 01:03:14 +01:00
return sUnknownStringVar;
2017-01-14 20:53:20 +01:00
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_PlayerName(void)
2017-01-14 20:53:20 +01:00
{
return gSaveBlock2Ptr->playerName;
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_StringVar1(void)
2017-01-14 20:53:20 +01:00
{
return gStringVar1;
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_StringVar2(void)
2017-01-14 20:53:20 +01:00
{
return gStringVar2;
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_StringVar3(void)
2017-01-14 20:53:20 +01:00
{
return gStringVar3;
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_KunChan(void)
2017-01-14 20:53:20 +01:00
{
if (gSaveBlock2Ptr->playerGender == MALE)
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_Kun;
2017-01-14 20:53:20 +01:00
else
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_Chan;
2017-01-14 20:53:20 +01:00
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_RivalName(void)
2017-01-14 20:53:20 +01:00
{
if (gSaveBlock2Ptr->playerGender == MALE)
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_May;
2017-01-14 20:53:20 +01:00
else
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_Brendan;
2017-01-14 20:53:20 +01:00
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_Version(void)
2017-01-14 20:53:20 +01:00
{
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_Emerald;
2017-01-14 20:53:20 +01:00
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_Aqua(void)
2017-01-14 20:53:20 +01:00
{
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_Aqua;
2017-01-14 20:53:20 +01:00
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_Magma(void)
2017-01-14 20:53:20 +01:00
{
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_Magma;
2017-01-14 20:53:20 +01:00
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_Archie(void)
2017-01-14 20:53:20 +01:00
{
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_Archie;
2017-01-14 20:53:20 +01:00
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_Maxie(void)
2017-01-14 20:53:20 +01:00
{
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_Maxie;
2017-01-14 20:53:20 +01:00
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_Kyogre(void)
2017-01-14 20:53:20 +01:00
{
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_Kyogre;
2017-01-14 20:53:20 +01:00
}
2018-10-14 15:04:25 +02:00
static const u8 *ExpandPlaceholder_Groudon(void)
2017-01-14 20:53:20 +01:00
{
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_Groudon;
2017-01-14 20:53:20 +01:00
}
2018-10-14 15:04:25 +02:00
const u8 *GetExpandedPlaceholder(u32 id)
2017-01-14 20:53:20 +01:00
{
2018-10-14 15:04:25 +02:00
typedef const u8 *(*ExpandPlaceholderFunc)(void);
2017-01-15 00:17:51 +01:00
static const ExpandPlaceholderFunc funcs[] =
{
2019-09-20 01:23:24 +02:00
[PLACEHOLDER_ID_UNKNOWN] = ExpandPlaceholder_UnknownStringVar,
[PLACEHOLDER_ID_PLAYER] = ExpandPlaceholder_PlayerName,
[PLACEHOLDER_ID_STRING_VAR_1] = ExpandPlaceholder_StringVar1,
[PLACEHOLDER_ID_STRING_VAR_2] = ExpandPlaceholder_StringVar2,
[PLACEHOLDER_ID_STRING_VAR_3] = ExpandPlaceholder_StringVar3,
[PLACEHOLDER_ID_KUN] = ExpandPlaceholder_KunChan,
[PLACEHOLDER_ID_RIVAL] = ExpandPlaceholder_RivalName,
[PLACEHOLDER_ID_VERSION] = ExpandPlaceholder_Version,
[PLACEHOLDER_ID_AQUA] = ExpandPlaceholder_Aqua,
[PLACEHOLDER_ID_MAGMA] = ExpandPlaceholder_Magma,
[PLACEHOLDER_ID_ARCHIE] = ExpandPlaceholder_Archie,
[PLACEHOLDER_ID_MAXIE] = ExpandPlaceholder_Maxie,
[PLACEHOLDER_ID_KYOGRE] = ExpandPlaceholder_Kyogre,
[PLACEHOLDER_ID_GROUDON] = ExpandPlaceholder_Groudon,
2017-01-15 00:17:51 +01:00
};
if (id >= ARRAY_COUNT(funcs))
2019-12-05 21:33:36 +01:00
return gText_ExpandedPlaceholder_Empty;
2017-01-14 20:53:20 +01:00
else
2017-01-15 00:17:51 +01:00
return funcs[id]();
2017-01-14 20:53:20 +01:00
}
u8 *StringFill(u8 *dest, u8 c, u16 n)
{
u16 i;
for (i = 0; i < n; i++)
*dest++ = c;
*dest = EOS;
return dest;
}
u8 *StringCopyPadded(u8 *dest, const u8 *src, u8 c, u16 n)
{
while (*src != EOS)
{
*dest++ = *src++;
if (n)
n--;
}
n--;
while (n != (u16)-1)
{
*dest++ = c;
n--;
}
*dest = EOS;
return dest;
}
u8 *StringFillWithTerminator(u8 *dest, u16 n)
{
return StringFill(dest, EOS, n);
}
2017-01-15 00:17:51 +01:00
u8 *StringCopyN_Multibyte(u8 *dest, u8 *src, u32 n)
{
2017-01-15 23:05:54 +01:00
u32 i;
for (i = n - 1; i != (u32)-1; i--)
{
if (*src == EOS)
{
break;
}
else
{
*dest++ = *src++;
2018-10-14 15:04:25 +02:00
if (*(src - 1) == CHAR_SPECIAL_F9)
2017-01-15 23:15:38 +01:00
*dest++ = *src++;
2017-01-15 23:05:54 +01:00
}
}
*dest = EOS;
return dest;
2017-01-15 00:17:51 +01:00
}
2019-01-26 20:56:06 +01:00
u32 StringLength_Multibyte(const u8 *str)
2017-01-15 00:17:51 +01:00
{
u32 length = 0;
while (*str != EOS)
{
2018-10-14 15:04:25 +02:00
if (*str == CHAR_SPECIAL_F9)
2017-01-15 00:17:51 +01:00
str++;
str++;
length++;
}
return length;
}
u8 *WriteColorChangeControlCode(u8 *dest, u32 colorType, u8 color)
{
2018-10-14 15:04:25 +02:00
*dest = EXT_CTRL_CODE_BEGIN;
2017-01-15 00:17:51 +01:00
dest++;
switch (colorType)
{
case 0:
*dest = 1;
dest++;
break;
case 1:
*dest = 3;
dest++;
break;
case 2:
*dest = 2;
dest++;
break;
}
*dest = color;
dest++;
*dest = EOS;
return dest;
}
Decompile TV (#80) * ClearTVShowData * special_0x44 * DoTVShow (nonmatching because align) * DoTVShowBravoTrainerPokemonProfile * Update field names * DoTVShowBravoTrainerBattleTower * Renaming of struct fields * sub_80EBFF4 and UpdateTVScreensOnMap * SetTVMetatilesOnMap * Power buttons for the TV screens on the map * special_0x45 * sub_80EC18C * special_0x4a * ResetGabbyAndTy * GabbyAndTyBeforeInterview * GabbyAndTyAfterInterview * Through IsTVShowInSearchOfTrainersAiring * GabbyAndTyGetLastQuote * GabbyAndTyGetLastBattleTrivia * GabbyAndTySetScriptVarsToFieldObjectLocalIds * InterviewAfter; use TVShow as a precursor for making the individual show structs anonymous * Make TV structs anonymous within the union * Move the TV union to its own subheader * Move TV show enums to the global.tv.h subheader * Funcion renaming * Apply static attributes where able * PutPokemonTodayCaughtOnAir * sub_80EC8A4 * PutPokemonTodayFailedOnTheAir * sub_80EC9E8, sub_80ECA10 * sub_80ECA38 * sub_80ECB00 * Put3CheersForPokeblocksOnTheAir * PutFanClubSpecialOnTheAir * ContestLiveUpdates_BeforeInterview * Other before-interview Contest Live Updates functions * ContestLiveUpdates_BeforeInterview_5 * InterviewAfter_BravoTrainerPokemonProfile * BravoTrainerPokemonProfile_BeforeInterview1 * BravoTrainerPokemonProfile_BeforeInterview2 * Disassemble TV data * Decompile TV data * InterviewAfter_BravoTrainerBattleTowerProfile * SaveRecordedItemPurchasesForTVShow * PutNameRaterShowOnTheAir * StartMassOutbreak * PutLilycoveContestLadyShowOnTheAir * InterviewAfter_FanClubLetter * Rip TV strings * InterviewAfter_RecentHappenings * InterviewAfter_PkmnFanClubOpinions * sub_80ED718 * EndMassOutbreak * sub_80ED888 * sub_80ED8B4 * UpdateMassOutbreakTimeLeft * sub_80ED950 * PutFishingAdviceShowOnTheAir * through sub_80EDA80 * ewram and common syms are now fetched from the object files * BSS symbols are taken from the tv.o file * through sub_80EDC60 * sub_80EDCE8 * sub_80EDD78 * through sub_80EDE84 * nomatching sub_80EDE98 * sub_80EDFB4 * sub_80EE104 * sub_80EE104 * sub_80EE184 * sub_80EE2CC * sub_80EE35C * sub_80EE44C * sub_80EE4DC * sub_80EE5A4 * sub_80EE69C * sub_80EE72C * sub_80EE7C0 * sub_80EE818 * sub_80EE8C8 * sub_80EEA70 * sub_80EEB98 * sub_80EEBF4 * through sub_80EED60 * Functions relating to Pokemon News * sub_80EEF6C * GetPriceReduction * IsPriceDiscounted * sub_80EF120 * through sub_80EF370 * sub_80EF40C * HasMixableShowAlreadyBeenSpawnedWithPlayerID * TV_SortPurchasesByQuantity * FindActiveBroadcastByShowType_SetScriptResult * InterviewBefore * through sub_80EF88C * through sub_80EF93C * through sub_80EFA24 * through TV_BernoulliTrial * sub_80EFB58 * sub_80EFBA4 * sub_80EFBDC * through sub_80EFD98 * ChangePokemonNickname * ChangeBoxPokemonNickname * sub_80EFF9C * through player_id_to_dword * CheckForBigMovieOrEmergencyNewsOnTV * GetMomOrDadStringForTVMessage * sub_80F01E8 * sub_80F0358 * sub_80F049C * TV record mixing functions * sub_80F06D0 * sub_80F0708 nonmatching * through sub_80F0B24 * sub_80F0B64 * through sub_80F0C04 * sub_80F0C7C * sub_80F0D60 * sub_80F0E58 * sub_80F0E84 * through sub_80F0F24 * sub_80F0F64 * sub_80F1208 * sub_80F1254 * sub_80F1290 * sub_80F12A4 * sub_80F14F8 * DoTVShowTodaysSmartShopper * DoTVShowTheNameRaterShow * DoTVShowPokemonTodaySuccessfulCapture * DoTVShowPokemonTodayFailedCapture * DoTVShowPokemonFanClubLetter * DoTVShowRecentHappenings * DoTVShowPokemonFanClubOpinions * DoTVShowPokemonNewsMassOutbreak * DoTVShowPokemonContestLiveUpdates * DoTVShowPokemonBattleUpdate * DoTVShow3CheersForPokeblocks * DoTVShowInSearchOfTrainers * Label GabbyAndTyData fields; remove ddump comments from data/text/tv.inc * DoTVShowPokemonAngler * DoTVShowTheWorldOfMasters; update RAM symbols and field names * Decorate static functions * DoTVShowTodaysRivalTrainer; region map enums * TVDewfordTrendWatcherNetworkTextGroup * DoTVShowHoennTreasureInvestigators * DoTVShowFindThatGamer * DoTVShowBreakingNewsTV * DoTVShowSecretBaseVisit * DoTVShowPokemonLotterWinnerFlashReport * DoTVShowThePokemonBattleSeminar * DoTVShowTrainerFanClubSpecial, DoTVShowTrainerFanClub * DoTVShowSpotTheCuties * DoTVShowPokemonNewsBattleFrontier * DoTVShowWhatsNo1InHoennToday * Helpers for DoTVShowSecretBaseSecrets * DoTVShowSecretBaseSecrets * DoTVShowSafariFanClub * Finish decompilation of tv.s * Some renaming * Rename text group pointers * revoke statis; pokenews enums * Labels are number one * Label all TV struct fields * Make data/text/tv.inc more readable * Split data/text/tv.inc * Rename pokenews text pointers * Frontier Symbol constants; indicate static rodata objects with 's' prefix * Fix leading spaces/tabs F*** CLion sometimes * Fix inconsequential warning
2017-10-13 17:09:36 +02:00
bool32 IsStringJapanese(u8 *str)
2017-01-15 00:17:51 +01:00
{
while (*str != EOS)
{
if (*str <= 0xA0)
2018-10-14 15:04:25 +02:00
if (*str != CHAR_SPACE)
2017-01-15 00:17:51 +01:00
return TRUE;
str++;
}
return FALSE;
}
bool32 sub_800924C(u8 *str, s32 n)
{
s32 i;
for (i = 0; *str != EOS && i < n; i++)
{
if (*str <= 0xA0)
2018-10-14 15:04:25 +02:00
if (*str != CHAR_SPACE)
2017-01-15 00:17:51 +01:00
return TRUE;
str++;
}
return FALSE;
}
u8 GetExtCtrlCodeLength(u8 code)
{
static const u8 lengths[] =
{
1,
2,
2,
2,
4,
2,
2,
1,
2,
1,
1,
3,
2,
2,
2,
1,
3,
2,
2,
2,
2,
1,
1,
1,
1,
};
u8 length = 0;
if (code < ARRAY_COUNT(lengths))
length = lengths[code];
return length;
}
static const u8 *SkipExtCtrlCode(const u8 *s)
{
2018-10-14 15:04:25 +02:00
while (*s == EXT_CTRL_CODE_BEGIN)
2017-01-15 00:17:51 +01:00
{
s++;
s += GetExtCtrlCodeLength(*s);
}
return s;
}
s32 StringCompareWithoutExtCtrlCodes(const u8 *str1, const u8 *str2)
{
s32 retVal = 0;
while (1)
{
str1 = SkipExtCtrlCode(str1);
str2 = SkipExtCtrlCode(str2);
if (*str1 > *str2)
break;
if (*str1 < *str2)
{
retVal = -1;
2018-10-14 15:04:25 +02:00
if (*str2 == EOS)
2017-01-15 00:17:51 +01:00
retVal = 1;
}
2018-10-14 15:04:25 +02:00
if (*str1 == EOS)
2017-01-15 00:17:51 +01:00
return retVal;
str1++;
str2++;
}
retVal = 1;
2018-10-14 15:04:25 +02:00
if (*str1 == EOS)
2017-01-15 00:17:51 +01:00
retVal = -1;
return retVal;
}
void ConvertInternationalString(u8 *s, u8 language)
{
if (language == LANGUAGE_JAPANESE)
{
u8 i;
StripExtCtrlCodes(s);
i = StringLength(s);
2018-10-14 15:04:25 +02:00
s[i++] = EXT_CTRL_CODE_BEGIN;
2017-01-15 00:17:51 +01:00
s[i++] = 22;
2018-10-14 15:04:25 +02:00
s[i++] = EOS;
2017-01-15 00:17:51 +01:00
i--;
while (i != (u8)-1)
{
s[i + 2] = s[i];
i--;
}
2018-10-14 15:04:25 +02:00
s[0] = EXT_CTRL_CODE_BEGIN;
2017-01-15 00:17:51 +01:00
s[1] = 21;
}
}
void StripExtCtrlCodes(u8 *str)
{
u16 srcIndex = 0;
u16 destIndex = 0;
2018-10-14 15:04:25 +02:00
while (str[srcIndex] != EOS)
2017-01-15 00:17:51 +01:00
{
2018-10-14 15:04:25 +02:00
if (str[srcIndex] == EXT_CTRL_CODE_BEGIN)
2017-01-15 00:17:51 +01:00
{
srcIndex++;
srcIndex += GetExtCtrlCodeLength(str[srcIndex]);
}
else
{
str[destIndex++] = str[srcIndex++];
}
}
2018-10-14 15:04:25 +02:00
str[destIndex] = EOS;
2017-01-15 00:17:51 +01:00
}