mirror of
https://github.com/jorio/Pomme.git
synced 2025-02-05 23:29:58 +00:00
Rewrite FourCCString
This commit is contained in:
parent
5eb35908ae
commit
1b5625e28e
@ -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];
|
||||
*(uint32_t*) b = t;
|
||||
#if !(TARGET_RT_BIGENDIAN)
|
||||
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.
|
||||
char stringBuffer[5];
|
||||
|
||||
int shift = 24;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (!isalnum(b[i]))
|
||||
b[i] = filler;
|
||||
char c = (fourCC >> shift) & 0xFF;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user