Add FlagBitsToString - Converts a bit string to a string of flag characters (#377)

* Add new method - Converts a bit string to a string of flag characters

* New syntax

* Set tags

* Fix tags

* Change method name

* Remove for - set null only once
This commit is contained in:
Sebastian K 2021-06-17 13:44:50 +02:00 committed by GitHub
parent d01c72f79b
commit 8075ce8371
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -773,3 +773,32 @@ stock bool BitToFlag(int bit, AdminFlag &flag)
return false;
}
/**
* Converts a bit string to a string of flag characters.
*
* @param bits Bit string containing the flags.
* @param flags Output array to write a string of flag characters.
* @param maxSize Maximum size of the string array.
* @return Number of flag characters written.
*/
stock int FlagBitsToString(const int bits, char[] flags, const int maxSize)
{
AdminFlag array[AdminFlags_TOTAL];
int numFlags = FlagBitsToArray(bits, array, AdminFlags_TOTAL);
if (numFlags > maxSize)
{
numFlags = maxSize;
}
int i, c, numId = 0;
for (i = 0; i < numFlags; ++i)
{
if(FindFlagChar(array[i], c))
{
flags[numId++] = c;
}
}
flags[numId] = '\0';
return numId;
}