/* common */
+#include "check.h"
#include "gentype.h"
#include "strbuf.h"
* NOT add the element type!
*/
{
- unsigned I;
+ unsigned SizeBytes;
+
+ /* Remember the current position */
+ unsigned Pos = SB_GetLen (Type);
- /* Add the array token */
+ /* Add a dummy array token */
SB_AppendChar (Type, GT_TYPE_ARRAY);
/* Add the size. */
- for (I = 0; I < 4; ++I) {
+ SizeBytes = 0;
+ do {
SB_AppendChar (Type, ArraySize & 0xFF);
ArraySize >>= 8;
- }
+ ++SizeBytes;
+ } while (ArraySize);
+
+ /* Write the correct array token */
+ SB_GetBuf (Type)[Pos] = GT_ARRAY (SizeBytes);
}
-unsigned GT_GetArraySize (StrBuf* Type)
-/* Retrieve the size of an array stored in Type at the current index position.
- * The index position will get moved past the array size.
+unsigned GT_GetElementCount (StrBuf* Type)
+/* Retrieve the element count of an array stored in Type at the current index
+ * position. Note: Index must point to the array token itself, since the size
+ * of the element count is encoded there. The index position will get moved
+ * past the array.
*/
{
- unsigned Size;
- Size = (unsigned)SB_Get (Type);
- Size |= (unsigned)SB_Get (Type) << 8;
- Size |= (unsigned)SB_Get (Type) << 16;
- Size |= (unsigned)SB_Get (Type) << 24;
+ /* Get the number of bytes for the element count */
+ unsigned SizeBytes = GT_GET_SIZE (SB_Get (Type));
+
+ /* Read the size */
+ unsigned Size = 0;
+ const char* Buf = SB_GetConstBuf (Type) + SB_GetLen (Type);
+ while (SizeBytes--) {
+ Size <<= 8;
+ Size |= Buf[SizeBytes];
+ }
+
+ /* Return it */
return Size;
}
}
/* Terminate the string so it can be used with string functions */
- SB_Terminate (String);
+ SB_Terminate (String);
/* Return the contents of String */
return SB_GetConstBuf (String);
}
-
-
-
-
-
-