Skip to content

Instantly share code, notes, and snippets.

@JensAyton
Created August 19, 2010 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JensAyton/539041 to your computer and use it in GitHub Desktop.
Save JensAyton/539041 to your computer and use it in GitHub Desktop.
// Struct handler from an @encode() string parser for a debug printer.
#import <objc/runtime.h> // For @encode syntax constants.
static void DecodeStruct(const char * const encoding, size_t * const cursor, const void ** const buffer, NSMutableString *string)
{
NSCParameterAssert(encoding != NULL && encoding[*cursor] == _C_STRUCT_B && cursor != NULL && buffer != NULL);
#if INCLUDE_STRUCT_NAMES
size_t nameStart = *cursor + 1;
#endif
while (encoding[*cursor] != '=')
{
(*cursor)++;
ASSERT_NOT_END_OF_ENCODING(encoding, cursor);
}
#if INCLUDE_STRUCT_NAMES
size_t nameLength = *cursor - nameStart;
if (nameLength != 1 || encoding[nameStart] != '\?')
{
NSString *name = [[NSString alloc] initWithBytes:encoding + nameStart
length:nameLength
encoding:NSUTF8StringEncoding];
if (name != nil)
{
[string appendFormat:@"(%@)", name];
[name release];
}
}
#endif
// Skip "="
(*cursor)++;
ASSERT_NOT_END_OF_ENCODING(encoding, cursor);
[string appendString:@"{"];
BOOL first = YES;
while (encoding[*cursor] != _C_STRUCT_E)
{
if (!first)
{
[string appendString:@", "];
}
else
{
first = NO;
}
DecodeValue(encoding, cursor, buffer, string);
}
[string appendString:@"}"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment