131 :(unsigned)inIndentation errorDescription:(NSString **)outErrorDescription
132{
133 const uint8_t *srcBytes;
134 uint8_t *dstBytes, *curr;
135 NSUInteger i, j, srcLength, dstLength;
136 const char hexTable[] = "0123456789ABCDEF";
137 NSString *result;
138
139 srcBytes = [self bytes];
140 srcLength = [self length];
141
142 dstLength = 2 * srcLength + srcLength/8 + 2 + (srcLength/64 * (1 + inIndentation));
143
144 dstBytes = malloc(dstLength);
145 if (dstBytes == NULL)
146 {
147 if (NULL != outErrorDescription)
148 {
149 *outErrorDescription = [NSString stringWithFormat:@"failed to allocate space (%lu bytes) for conversion of NSData to old-school property list representation", dstLength];
150 }
152 }
153
154 curr = dstBytes;
155 *curr++ = '<';
156 for (i = 0; i != srcLength; ++i)
157 {
158 if (0 != i && 0 == (i & 3))
159 {
160 if (0 == (i & 31))
161 {
162 *curr++ = '\n';
163 j = inIndentation;
164 while (--j) *curr++ = '\t';
165 }
166 *curr++ = ' ';
167 }
168 *curr++ = hexTable[srcBytes[i] >> 4];
169 *curr++ = hexTable[srcBytes[i] & 0xF];
170 }
171 *curr = '>';
172
173 assert((size_t)(curr - dstBytes) <= dstLength);
174
175 result = [[NSString alloc] initWithBytesNoCopy:dstBytes length:dstLength encoding:NSASCIIStringEncoding freeWhenDone:YES];
176 return [result autorelease];
177}