Created
August 19, 2010 21:57
-
-
Save JensAyton/539041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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