Rewrite FourCCString

This commit is contained in:
Iliyas Jorio
2021-04-17 12:35:29 +02:00
parent 5eb35908ae
commit 1b5625e28e

View File

@@ -39,20 +39,27 @@ void ImplementMe(const char* fn, std::string msg, int severity)
} }
} }
std::string Pomme::FourCCString(uint32_t t, char filler) std::string Pomme::FourCCString(uint32_t fourCC, char filler)
{ {
char b[5]; char stringBuffer[5];
*(uint32_t*) b = t;
#if !(TARGET_RT_BIGENDIAN) int shift = 24;
std::reverse(b, b + 4);
#endif
// Replace any non-alphanumeric character with the filler character.
// This ensures that the resulting string is suitable for use as a filename.
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
if (!isalnum(b[i])) char c = (fourCC >> shift) & 0xFF;
b[i] = filler;
// Replace any non-alphanumeric character with the filler character.
// This ensures that the resulting string is suitable for use as a filename.
if (!isalnum(c))
c = filler;
stringBuffer[i] = c;
shift -= 8;
} }
b[4] = '\0';
return b; stringBuffer[4] = '\0';
return stringBuffer;
} }