mirror of
https://github.com/jorio/Pomme.git
synced 2025-08-11 01:25:05 +00:00
Rewrite FourCCString
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user