Skip to content
Browse files

Made indent style universal

  • Loading branch information...
1 parent 0ba7d3d commit cfe1f37507fb81d63255ed9433dfbbf177dc3840 @schwa schwa committed Feb 11, 2011
View
460 Source/CDataScanner.m
@@ -37,304 +37,304 @@ @interface CDataScanner ()
#pragma mark -
inline static unichar CharacterAtPointer(void *start, void *end)
-{
-#pragma unused(end)
+ {
+ #pragma unused(end)
-const u_int8_t theByte = *(u_int8_t *)start;
-if (theByte & 0x80)
- {
- // TODO -- UNICODE!!!! (well in theory nothing todo here)
- }
-const unichar theCharacter = theByte;
-return(theCharacter);
-}
+ const u_int8_t theByte = *(u_int8_t *)start;
+ if (theByte & 0x80)
+ {
+ // TODO -- UNICODE!!!! (well in theory nothing todo here)
+ }
+ const unichar theCharacter = theByte;
+ return(theCharacter);
+ }
-static NSCharacterSet *sDoubleCharacters = NULL;
+ static NSCharacterSet *sDoubleCharacters = NULL;
-@implementation CDataScanner
+ @implementation CDataScanner
- (id)init
-{
-if ((self = [super init]) != NULL)
- {
- }
-return(self);
-}
+ {
+ if ((self = [super init]) != NULL)
+ {
+ }
+ return(self);
+ }
- (id)initWithData:(NSData *)inData;
-{
-if ((self = [self init]) != NULL)
- {
- [self setData:inData];
- }
-return(self);
-}
-
-+ (void)initialize
-{
-if (sDoubleCharacters == NULL)
{
- sDoubleCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789eE-+."] retain];
+ if ((self = [self init]) != NULL)
+ {
+ [self setData:inData];
+ }
+ return(self);
+ }
+
+ + (void)initialize
+ {
+ if (sDoubleCharacters == NULL)
+ {
+ sDoubleCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789eE-+."] retain];
+ }
}
-}
- (void)dealloc
-{
-[data release];
-data = NULL;
-//
-[super dealloc];
-}
+ {
+ [data release];
+ data = NULL;
+ //
+ [super dealloc];
+ }
- (NSUInteger)scanLocation
-{
-return(current - start);
-}
+ {
+ return(current - start);
+ }
- (NSUInteger)bytesRemaining
-{
-return(end - current);
-}
-
-- (NSData *)data
-{
-return(data);
-}
-
-- (void)setData:(NSData *)inData
-{
-if (data != inData)
- {
- [data release];
- data = [inData retain];
+ {
+ return(end - current);
}
-if (data)
+- (NSData *)data
{
- start = (u_int8_t *)data.bytes;
- end = start + data.length;
- current = start;
- length = data.length;
+ return(data);
}
-else
+
+- (void)setData:(NSData *)inData
{
- start = NULL;
- end = NULL;
- current = NULL;
- length = 0;
+ if (data != inData)
+ {
+ [data release];
+ data = [inData retain];
+ }
+
+ if (data)
+ {
+ start = (u_int8_t *)data.bytes;
+ end = start + data.length;
+ current = start;
+ length = data.length;
+ }
+ else
+ {
+ start = NULL;
+ end = NULL;
+ current = NULL;
+ length = 0;
+ }
}
-}
- (void)setScanLocation:(NSUInteger)inScanLocation
-{
-current = start + inScanLocation;
-}
+ {
+ current = start + inScanLocation;
+ }
- (BOOL)isAtEnd
-{
-return(self.scanLocation >= length);
-}
+ {
+ return(self.scanLocation >= length);
+ }
- (unichar)currentCharacter
-{
-return(CharacterAtPointer(current, end));
-}
+ {
+ return(CharacterAtPointer(current, end));
+ }
#pragma mark -
- (unichar)scanCharacter
-{
-const unichar theCharacter = CharacterAtPointer(current++, end);
-return(theCharacter);
-}
+ {
+ const unichar theCharacter = CharacterAtPointer(current++, end);
+ return(theCharacter);
+ }
- (BOOL)scanCharacter:(unichar)inCharacter
-{
-unichar theCharacter = CharacterAtPointer(current, end);
-if (theCharacter == inCharacter)
- {
- ++current;
- return(YES);
- }
-else
- return(NO);
-}
+ {
+ unichar theCharacter = CharacterAtPointer(current, end);
+ if (theCharacter == inCharacter)
+ {
+ ++current;
+ return(YES);
+ }
+ else
+ return(NO);
+ }
- (BOOL)scanUTF8String:(const char *)inString intoString:(NSString **)outValue
-{
-const size_t theLength = strlen(inString);
-if ((size_t)(end - current) < theLength)
- return(NO);
-if (strncmp((char *)current, inString, theLength) == 0)
- {
- current += theLength;
- if (outValue)
- *outValue = [NSString stringWithUTF8String:inString];
- return(YES);
- }
-return(NO);
-}
+ {
+ const size_t theLength = strlen(inString);
+ if ((size_t)(end - current) < theLength)
+ return(NO);
+ if (strncmp((char *)current, inString, theLength) == 0)
+ {
+ current += theLength;
+ if (outValue)
+ *outValue = [NSString stringWithUTF8String:inString];
+ return(YES);
+ }
+ return(NO);
+ }
- (BOOL)scanString:(NSString *)inString intoString:(NSString **)outValue
-{
-if ((size_t)(end - current) < inString.length)
- return(NO);
-if (strncmp((char *)current, [inString UTF8String], inString.length) == 0)
- {
- current += inString.length;
- if (outValue)
- *outValue = inString;
- return(YES);
- }
-return(NO);
-}
+ {
+ if ((size_t)(end - current) < inString.length)
+ return(NO);
+ if (strncmp((char *)current, [inString UTF8String], inString.length) == 0)
+ {
+ current += inString.length;
+ if (outValue)
+ *outValue = inString;
+ return(YES);
+ }
+ return(NO);
+ }
- (BOOL)scanCharactersFromSet:(NSCharacterSet *)inSet intoString:(NSString **)outValue
-{
-u_int8_t *P;
-for (P = current; P < end && [inSet characterIsMember:*P] == YES; ++P)
- ;
+ {
+ u_int8_t *P;
+ for (P = current; P < end && [inSet characterIsMember:*P] == YES; ++P)
+ ;
-if (P == current)
- {
- return(NO);
- }
+ if (P == current)
+ {
+ return(NO);
+ }
-if (outValue)
- {
- *outValue = [[[NSString alloc] initWithBytes:current length:P - current encoding:NSUTF8StringEncoding] autorelease];
- }
+ if (outValue)
+ {
+ *outValue = [[[NSString alloc] initWithBytes:current length:P - current encoding:NSUTF8StringEncoding] autorelease];
+ }
-current = P;
+ current = P;
-return(YES);
-}
+ return(YES);
+ }
- (BOOL)scanUpToString:(NSString *)inString intoString:(NSString **)outValue
-{
-const char *theToken = [inString UTF8String];
-const char *theResult = strnstr((char *)current, theToken, end - current);
-if (theResult == NULL)
- {
- return(NO);
- }
+ {
+ const char *theToken = [inString UTF8String];
+ const char *theResult = strnstr((char *)current, theToken, end - current);
+ if (theResult == NULL)
+ {
+ return(NO);
+ }
-if (outValue)
- {
- *outValue = [[[NSString alloc] initWithBytes:current length:theResult - (char *)current encoding:NSUTF8StringEncoding] autorelease];
- }
+ if (outValue)
+ {
+ *outValue = [[[NSString alloc] initWithBytes:current length:theResult - (char *)current encoding:NSUTF8StringEncoding] autorelease];
+ }
-current = (u_int8_t *)theResult;
+ current = (u_int8_t *)theResult;
-return(YES);
-}
+ return(YES);
+ }
- (BOOL)scanUpToCharactersFromSet:(NSCharacterSet *)inSet intoString:(NSString **)outValue
-{
-u_int8_t *P;
-for (P = current; P < end && [inSet characterIsMember:*P] == NO; ++P)
- ;
+ {
+ u_int8_t *P;
+ for (P = current; P < end && [inSet characterIsMember:*P] == NO; ++P)
+ ;
-if (P == current)
- {
- return(NO);
- }
+ if (P == current)
+ {
+ return(NO);
+ }
-if (outValue)
- {
- *outValue = [[[NSString alloc] initWithBytes:current length:P - current encoding:NSUTF8StringEncoding] autorelease];
- }
+ if (outValue)
+ {
+ *outValue = [[[NSString alloc] initWithBytes:current length:P - current encoding:NSUTF8StringEncoding] autorelease];
+ }
-current = P;
+ current = P;
-return(YES);
-}
+ return(YES);
+ }
- (BOOL)scanNumber:(NSNumber **)outValue
- {
- NSString *theString = NULL;
- if ([self scanCharactersFromSet:sDoubleCharacters intoString:&theString])
- {
- if ([theString rangeOfString:@"."].location != NSNotFound)
- {
- if (outValue)
- {
- *outValue = [NSDecimalNumber decimalNumberWithString:theString];
- }
- return(YES);
- }
- else if ([theString rangeOfString:@"-"].location != NSNotFound)
- {
- if (outValue != NULL)
- {
- *outValue = [NSNumber numberWithLongLong:[theString longLongValue]];
- }
- return(YES);
- }
- else
- {
- if (outValue != NULL)
- {
- *outValue = [NSNumber numberWithUnsignedLongLong:strtoull([theString UTF8String], NULL, 0)];
- }
- return(YES);
- }
-
- }
- return(NO);
- }
-
-- (BOOL)scanDecimalNumber:(NSDecimalNumber **)outValue;
- {
- NSString *theString = NULL;
- if ([self scanCharactersFromSet:sDoubleCharacters intoString:&theString])
- {
- if (outValue)
- {
- *outValue = [NSDecimalNumber decimalNumberWithString:theString];
- }
- return(YES);
- }
- return(NO);
- }
-
-- (BOOL)scanDataOfLength:(NSUInteger)inLength intoData:(NSData **)outData;
- {
- if (self.bytesRemaining < inLength)
{
+ NSString *theString = NULL;
+ if ([self scanCharactersFromSet:sDoubleCharacters intoString:&theString])
+ {
+ if ([theString rangeOfString:@"."].location != NSNotFound)
+ {
+ if (outValue)
+ {
+ *outValue = [NSDecimalNumber decimalNumberWithString:theString];
+ }
+ return(YES);
+ }
+ else if ([theString rangeOfString:@"-"].location != NSNotFound)
+ {
+ if (outValue != NULL)
+ {
+ *outValue = [NSNumber numberWithLongLong:[theString longLongValue]];
+ }
+ return(YES);
+ }
+ else
+ {
+ if (outValue != NULL)
+ {
+ *outValue = [NSNumber numberWithUnsignedLongLong:strtoull([theString UTF8String], NULL, 0)];
+ }
+ return(YES);
+ }
+
+ }
return(NO);
}
-
- if (outData)
+
+- (BOOL)scanDecimalNumber:(NSDecimalNumber **)outValue;
{
- *outData = [NSData dataWithBytes:current length:inLength];
+ NSString *theString = NULL;
+ if ([self scanCharactersFromSet:sDoubleCharacters intoString:&theString])
+ {
+ if (outValue)
+ {
+ *outValue = [NSDecimalNumber decimalNumberWithString:theString];
+ }
+ return(YES);
+ }
+ return(NO);
}
- current += inLength;
- return(YES);
- }
+- (BOOL)scanDataOfLength:(NSUInteger)inLength intoData:(NSData **)outData;
+ {
+ if (self.bytesRemaining < inLength)
+ {
+ return(NO);
+ }
+
+ if (outData)
+ {
+ *outData = [NSData dataWithBytes:current length:inLength];
+ }
+
+ current += inLength;
+ return(YES);
+ }
- (void)skipWhitespace
-{
-u_int8_t *P;
-for (P = current; P < end && (isspace(*P)); ++P)
- ;
+ {
+ u_int8_t *P;
+ for (P = current; P < end && (isspace(*P)); ++P)
+ ;
-current = P;
-}
+ current = P;
+ }
- (NSString *)remainingString
-{
-NSData *theRemainingData = [NSData dataWithBytes:current length:end - current];
-NSString *theString = [[[NSString alloc] initWithData:theRemainingData encoding:NSUTF8StringEncoding] autorelease];
-return(theString);
-}
+ {
+ NSData *theRemainingData = [NSData dataWithBytes:current length:end - current];
+ NSString *theString = [[[NSString alloc] initWithData:theRemainingData encoding:NSUTF8StringEncoding] autorelease];
+ return(theString);
+ }
- (NSData *)remainingData;
-{
-NSData *theRemainingData = [NSData dataWithBytes:current length:end - current];
-return(theRemainingData);
-}
+ {
+ NSData *theRemainingData = [NSData dataWithBytes:current length:end - current];
+ return(theRemainingData);
+ }
-@end
+ @end
View
82 Source/Experimental/CFilteringJSONSerializer.m
@@ -14,57 +14,57 @@ @implementation CFilteringJSONSerializer
@synthesize convertersByName;
- (void)dealloc
-{
-[tests release];
-tests = NULL;
-//
-[convertersByName release];
-convertersByName = NULL;
-//
-[super dealloc];
-}
+ {
+ [tests release];
+ tests = NULL;
+ //
+ [convertersByName release];
+ convertersByName = NULL;
+ //
+ [super dealloc];
+ }
- (NSData *)serializeObject:(id)inObject error:(NSError **)outError
-{
-NSData *theData = NULL;
-for (JSONConversionTest theTest in self.tests)
- {
- NSString *theName = theTest(inObject);
- if (theName != NULL)
- {
- id theObject = NULL;
- JSONConversionConverter theConverter = [self.convertersByName objectForKey:theName];
- if (theConverter)
+ {
+ NSData *theData = NULL;
+ for (JSONConversionTest theTest in self.tests)
+ {
+ NSString *theName = theTest(inObject);
+ if (theName != NULL)
{
- theObject = theConverter(inObject);
- }
-
- if (theObject)
- {
- if ([theObject isKindOfClass:[NSData class]])
+ id theObject = NULL;
+ JSONConversionConverter theConverter = [self.convertersByName objectForKey:theName];
+ if (theConverter)
{
- theData = theObject;
- break;
+ theObject = theConverter(inObject);
}
- else
+
+ if (theObject)
{
- NSError *theError = NULL;
- theData = [super serializeObject:theObject error:&theError];
- if (theData != NULL)
+ if ([theObject isKindOfClass:[NSData class]])
{
+ theData = theObject;
break;
}
+ else
+ {
+ NSError *theError = NULL;
+ theData = [super serializeObject:theObject error:&theError];
+ if (theData != NULL)
+ {
+ break;
+ }
+ }
}
- }
+ }
+ }
+
+ if (theData == NULL)
+ {
+ theData = [super serializeObject:inObject error:outError];
}
- }
-
-if (theData == NULL)
- {
- theData = [super serializeObject:inObject error:outError];
- }
-
-return(theData);
-}
+
+ return(theData);
+ }
@end
View
96 Source/Extensions/CDataScanner_Extensions.m
@@ -64,72 +64,72 @@ - (BOOL)scanCStyleComment:(NSString **)outComment
}
- (BOOL)scanCPlusPlusStyleComment:(NSString **)outComment
-{
-if ([self scanString:@"//" intoString:NULL] == YES)
- {
- unichar theCharacters[] = { LF, FF, CR, NEL, LS, PS, };
- NSCharacterSet *theLineBreaksCharacterSet = [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithCharacters:theCharacters length:sizeof(theCharacters) / sizeof(*theCharacters)]];
+ {
+ if ([self scanString:@"//" intoString:NULL] == YES)
+ {
+ unichar theCharacters[] = { LF, FF, CR, NEL, LS, PS, };
+ NSCharacterSet *theLineBreaksCharacterSet = [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithCharacters:theCharacters length:sizeof(theCharacters) / sizeof(*theCharacters)]];
- NSString *theComment = NULL;
- [self scanUpToCharactersFromSet:theLineBreaksCharacterSet intoString:&theComment];
- [self scanCharactersFromSet:theLineBreaksCharacterSet intoString:NULL];
+ NSString *theComment = NULL;
+ [self scanUpToCharactersFromSet:theLineBreaksCharacterSet intoString:&theComment];
+ [self scanCharactersFromSet:theLineBreaksCharacterSet intoString:NULL];
- if (outComment != NULL)
- *outComment = theComment;
+ if (outComment != NULL)
+ *outComment = theComment;
- return(YES);
- }
-else
- {
- return(NO);
- }
-}
+ return(YES);
+ }
+ else
+ {
+ return(NO);
+ }
+ }
- (NSUInteger)lineOfScanLocation
-{
-NSUInteger theLine = 0;
-for (const u_int8_t *C = start; C < current; ++C)
{
- // TODO: JIW What about MS-DOS line endings you bastard! (Also other unicode line endings)
- if (*C == '\n' || *C == '\r')
+ NSUInteger theLine = 0;
+ for (const u_int8_t *C = start; C < current; ++C)
{
- ++theLine;
+ // TODO: JIW What about MS-DOS line endings you bastard! (Also other unicode line endings)
+ if (*C == '\n' || *C == '\r')
+ {
+ ++theLine;
+ }
}
+ return(theLine);
}
-return(theLine);
-}
- (NSDictionary *)userInfoForScanLocation
-{
-NSUInteger theLine = 0;
-const u_int8_t *theLineStart = start;
-for (const u_int8_t *C = start; C < current; ++C)
{
- if (*C == '\n' || *C == '\r')
+ NSUInteger theLine = 0;
+ const u_int8_t *theLineStart = start;
+ for (const u_int8_t *C = start; C < current; ++C)
{
- theLineStart = C - 1;
- ++theLine;
+ if (*C == '\n' || *C == '\r')
+ {
+ theLineStart = C - 1;
+ ++theLine;
+ }
}
- }
-NSUInteger theCharacter = current - theLineStart;
+ NSUInteger theCharacter = current - theLineStart;
-NSRange theStartRange = NSIntersectionRange((NSRange){ .location = MAX((NSInteger)self.scanLocation - 20, 0), .length = 20 + (NSInteger)self.scanLocation - 20 }, (NSRange){ .location = 0, .length = self.data.length });
-NSRange theEndRange = NSIntersectionRange((NSRange){ .location = self.scanLocation, .length = 20 }, (NSRange){ .location = 0, .length = self.data.length });
+ NSRange theStartRange = NSIntersectionRange((NSRange){ .location = MAX((NSInteger)self.scanLocation - 20, 0), .length = 20 + (NSInteger)self.scanLocation - 20 }, (NSRange){ .location = 0, .length = self.data.length });
+ NSRange theEndRange = NSIntersectionRange((NSRange){ .location = self.scanLocation, .length = 20 }, (NSRange){ .location = 0, .length = self.data.length });
-NSString *theSnippet = [NSString stringWithFormat:@"%@!HERE>!%@",
- [[[NSString alloc] initWithData:[self.data subdataWithRange:theStartRange] encoding:NSUTF8StringEncoding] autorelease],
- [[[NSString alloc] initWithData:[self.data subdataWithRange:theEndRange] encoding:NSUTF8StringEncoding] autorelease]
- ];
+ NSString *theSnippet = [NSString stringWithFormat:@"%@!HERE>!%@",
+ [[[NSString alloc] initWithData:[self.data subdataWithRange:theStartRange] encoding:NSUTF8StringEncoding] autorelease],
+ [[[NSString alloc] initWithData:[self.data subdataWithRange:theEndRange] encoding:NSUTF8StringEncoding] autorelease]
+ ];
-NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithUnsignedInteger:theLine], @"line",
- [NSNumber numberWithUnsignedInteger:theCharacter], @"character",
- [NSNumber numberWithUnsignedInteger:self.scanLocation], @"location",
- theSnippet, @"snippet",
- NULL];
-return(theUserInfo);
-}
+ NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithUnsignedInteger:theLine], @"line",
+ [NSNumber numberWithUnsignedInteger:theCharacter], @"character",
+ [NSNumber numberWithUnsignedInteger:self.scanLocation], @"location",
+ theSnippet, @"snippet",
+ NULL];
+ return(theUserInfo);
+ }
@end
View
172 Source/JSON/CJSONDeserializer.m
@@ -42,119 +42,119 @@ @implementation CJSONDeserializer
@synthesize scanner;
+ (id)deserializer
-{
-return([[[self alloc] init] autorelease]);
-}
+ {
+ return([[[self alloc] init] autorelease]);
+ }
- (id)init
-{
-if ((self = [super init]) != NULL)
{
+ if ((self = [super init]) != NULL)
+ {
+ }
+ return(self);
}
-return(self);
-}
- (void)dealloc
-{
-[scanner release];
-scanner = NULL;
-//
-[super dealloc];
-}
+ {
+ [scanner release];
+ scanner = NULL;
+ //
+ [super dealloc];
+ }
#pragma mark -
- (CJSONScanner *)scanner
-{
-if (scanner == NULL)
- {
- scanner = [[CJSONScanner alloc] init];
- }
-return(scanner);
-}
-
-- (id)nullObject
{
- return(self.scanner.nullObject);
+ if (scanner == NULL)
+ {
+ scanner = [[CJSONScanner alloc] init];
+ }
+ return(scanner);
}
+- (id)nullObject
+ {
+ return(self.scanner.nullObject);
+ }
+
- (void)setNullObject:(id)inNullObject
- {
- self.scanner.nullObject = inNullObject;
- }
+ {
+ self.scanner.nullObject = inNullObject;
+ }
#pragma mark -
- (NSStringEncoding)allowedEncoding
- {
- return(self.scanner.allowedEncoding);
- }
+ {
+ return(self.scanner.allowedEncoding);
+ }
- (void)setAllowedEncoding:(NSStringEncoding)inAllowedEncoding
- {
- self.scanner.allowedEncoding = inAllowedEncoding;
- }
+ {
+ self.scanner.allowedEncoding = inAllowedEncoding;
+ }
#pragma mark -
- (id)deserialize:(NSData *)inData error:(NSError **)outError
-{
-if (inData == NULL || [inData length] == 0)
- {
- if (outError)
- *outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL];
-
- return(NULL);
- }
-if ([self.scanner setData:inData error:outError] == NO)
- {
- return(NULL);
- }
-id theObject = NULL;
-if ([self.scanner scanJSONObject:&theObject error:outError] == YES)
- return(theObject);
-else
- return(NULL);
-}
+ {
+ if (inData == NULL || [inData length] == 0)
+ {
+ if (outError)
+ *outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL];
+
+ return(NULL);
+ }
+ if ([self.scanner setData:inData error:outError] == NO)
+ {
+ return(NULL);
+ }
+ id theObject = NULL;
+ if ([self.scanner scanJSONObject:&theObject error:outError] == YES)
+ return(theObject);
+ else
+ return(NULL);
+ }
- (id)deserializeAsDictionary:(NSData *)inData error:(NSError **)outError
-{
-if (inData == NULL || [inData length] == 0)
- {
- if (outError)
- *outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL];
-
- return(NULL);
- }
-if ([self.scanner setData:inData error:outError] == NO)
- {
- return(NULL);
- }
-NSDictionary *theDictionary = NULL;
-if ([self.scanner scanJSONDictionary:&theDictionary error:outError] == YES)
- return(theDictionary);
-else
- return(NULL);
-}
+ {
+ if (inData == NULL || [inData length] == 0)
+ {
+ if (outError)
+ *outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL];
+
+ return(NULL);
+ }
+ if ([self.scanner setData:inData error:outError] == NO)
+ {
+ return(NULL);
+ }
+ NSDictionary *theDictionary = NULL;
+ if ([self.scanner scanJSONDictionary:&theDictionary error:outError] == YES)
+ return(theDictionary);
+ else
+ return(NULL);
+ }
- (id)deserializeAsArray:(NSData *)inData error:(NSError **)outError
-{
-if (inData == NULL || [inData length] == 0)
- {
- if (outError)
- *outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL];
-
- return(NULL);
- }
-if ([self.scanner setData:inData error:outError] == NO)
- {
- return(NULL);
- }
-NSArray *theArray = NULL;
-if ([self.scanner scanJSONArray:&theArray error:outError] == YES)
- return(theArray);
-else
- return(NULL);
-}
+ {
+ if (inData == NULL || [inData length] == 0)
+ {
+ if (outError)
+ *outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL];
+
+ return(NULL);
+ }
+ if ([self.scanner setData:inData error:outError] == NO)
+ {
+ return(NULL);
+ }
+ NSArray *theArray = NULL;
+ if ([self.scanner scanJSONArray:&theArray error:outError] == YES)
+ return(theArray);
+ else
+ return(NULL);
+ }
@end
View
1,034 Source/JSON/CJSONScanner.m
@@ -38,13 +38,13 @@
NSString *const kJSONScannerErrorDomain = @"CJSONScannerErrorDomain";
inline static int HexToInt(char inCharacter)
-{
-int theValues[] = { 0x0 /* 48 '0' */, 0x1 /* 49 '1' */, 0x2 /* 50 '2' */, 0x3 /* 51 '3' */, 0x4 /* 52 '4' */, 0x5 /* 53 '5' */, 0x6 /* 54 '6' */, 0x7 /* 55 '7' */, 0x8 /* 56 '8' */, 0x9 /* 57 '9' */, -1 /* 58 ':' */, -1 /* 59 ';' */, -1 /* 60 '<' */, -1 /* 61 '=' */, -1 /* 62 '>' */, -1 /* 63 '?' */, -1 /* 64 '@' */, 0xa /* 65 'A' */, 0xb /* 66 'B' */, 0xc /* 67 'C' */, 0xd /* 68 'D' */, 0xe /* 69 'E' */, 0xf /* 70 'F' */, -1 /* 71 'G' */, -1 /* 72 'H' */, -1 /* 73 'I' */, -1 /* 74 'J' */, -1 /* 75 'K' */, -1 /* 76 'L' */, -1 /* 77 'M' */, -1 /* 78 'N' */, -1 /* 79 'O' */, -1 /* 80 'P' */, -1 /* 81 'Q' */, -1 /* 82 'R' */, -1 /* 83 'S' */, -1 /* 84 'T' */, -1 /* 85 'U' */, -1 /* 86 'V' */, -1 /* 87 'W' */, -1 /* 88 'X' */, -1 /* 89 'Y' */, -1 /* 90 'Z' */, -1 /* 91 '[' */, -1 /* 92 '\' */, -1 /* 93 ']' */, -1 /* 94 '^' */, -1 /* 95 '_' */, -1 /* 96 '`' */, 0xa /* 97 'a' */, 0xb /* 98 'b' */, 0xc /* 99 'c' */, 0xd /* 100 'd' */, 0xe /* 101 'e' */, 0xf /* 102 'f' */, };
-if (inCharacter >= '0' && inCharacter <= 'f')
- return(theValues[inCharacter - '0']);
-else
- return(-1);
-}
+ {
+ int theValues[] = { 0x0 /* 48 '0' */, 0x1 /* 49 '1' */, 0x2 /* 50 '2' */, 0x3 /* 51 '3' */, 0x4 /* 52 '4' */, 0x5 /* 53 '5' */, 0x6 /* 54 '6' */, 0x7 /* 55 '7' */, 0x8 /* 56 '8' */, 0x9 /* 57 '9' */, -1 /* 58 ':' */, -1 /* 59 ';' */, -1 /* 60 '<' */, -1 /* 61 '=' */, -1 /* 62 '>' */, -1 /* 63 '?' */, -1 /* 64 '@' */, 0xa /* 65 'A' */, 0xb /* 66 'B' */, 0xc /* 67 'C' */, 0xd /* 68 'D' */, 0xe /* 69 'E' */, 0xf /* 70 'F' */, -1 /* 71 'G' */, -1 /* 72 'H' */, -1 /* 73 'I' */, -1 /* 74 'J' */, -1 /* 75 'K' */, -1 /* 76 'L' */, -1 /* 77 'M' */, -1 /* 78 'N' */, -1 /* 79 'O' */, -1 /* 80 'P' */, -1 /* 81 'Q' */, -1 /* 82 'R' */, -1 /* 83 'S' */, -1 /* 84 'T' */, -1 /* 85 'U' */, -1 /* 86 'V' */, -1 /* 87 'W' */, -1 /* 88 'X' */, -1 /* 89 'Y' */, -1 /* 90 'Z' */, -1 /* 91 '[' */, -1 /* 92 '\' */, -1 /* 93 ']' */, -1 /* 94 '^' */, -1 /* 95 '_' */, -1 /* 96 '`' */, 0xa /* 97 'a' */, 0xb /* 98 'b' */, 0xc /* 99 'c' */, 0xd /* 100 'd' */, 0xe /* 101 'e' */, 0xf /* 102 'f' */, };
+ if (inCharacter >= '0' && inCharacter <= 'f')
+ return(theValues[inCharacter - '0']);
+ else
+ return(-1);
+ }
@interface CJSONScanner ()
- (BOOL)scanNotQuoteCharactersIntoString:(NSString **)outValue;
@@ -59,583 +59,583 @@ @implementation CJSONScanner
@synthesize allowedEncoding;
- (id)init
-{
-if ((self = [super init]) != NULL)
- {
- strictEscapeCodes = NO;
- nullObject = [[NSNull null] retain];
- }
-return(self);
-}
+ {
+ if ((self = [super init]) != NULL)
+ {
+ strictEscapeCodes = NO;
+ nullObject = [[NSNull null] retain];
+ }
+ return(self);
+ }
- (void)dealloc
-{
-[nullObject release];
-nullObject = NULL;
-//
-[super dealloc];
-}
+ {
+ [nullObject release];
+ nullObject = NULL;
+ //
+ [super dealloc];
+ }
#pragma mark -
- (BOOL)setData:(NSData *)inData error:(NSError **)outError;
-{
-NSData *theData = inData;
-if (theData && theData.length >= 4)
- {
- // This code is lame, but it works. Because the first character of any JSON string will always be a (ascii) control character we can work out the Unicode encoding by the bit pattern. See section 3 of http://www.ietf.org/rfc/rfc4627.txt
- const char *theChars = theData.bytes;
- NSStringEncoding theEncoding = NSUTF8StringEncoding;
- if (theChars[0] != 0 && theChars[1] == 0)
- {
- if (theChars[2] != 0 && theChars[3] == 0)
- theEncoding = NSUTF16LittleEndianStringEncoding;
- else if (theChars[2] == 0 && theChars[3] == 0)
- theEncoding = NSUTF32LittleEndianStringEncoding;
- }
- else if (theChars[0] == 0 && theChars[2] == 0 && theChars[3] != 0)
- {
- if (theChars[1] == 0)
- theEncoding = NSUTF32BigEndianStringEncoding;
- else if (theChars[1] != 0)
- theEncoding = NSUTF16BigEndianStringEncoding;
- }
-
- NSString *theString = [[NSString alloc] initWithData:theData encoding:theEncoding];
- if (theString == NULL && self.allowedEncoding != 0)
- {
- theString = [[NSString alloc] initWithData:theData encoding:self.allowedEncoding];
- }
- theData = [theString dataUsingEncoding:NSUTF8StringEncoding];
- [theString release];
- }
-
-if (theData)
- {
- [super setData:theData];
- return(YES);
- }
-else
- {
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan data. Data wasn't encoded properly?", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-1 userInfo:theUserInfo];
- }
- return(NO);
- }
-}
+ {
+ NSData *theData = inData;
+ if (theData && theData.length >= 4)
+ {
+ // This code is lame, but it works. Because the first character of any JSON string will always be a (ascii) control character we can work out the Unicode encoding by the bit pattern. See section 3 of http://www.ietf.org/rfc/rfc4627.txt
+ const char *theChars = theData.bytes;
+ NSStringEncoding theEncoding = NSUTF8StringEncoding;
+ if (theChars[0] != 0 && theChars[1] == 0)
+ {
+ if (theChars[2] != 0 && theChars[3] == 0)
+ theEncoding = NSUTF16LittleEndianStringEncoding;
+ else if (theChars[2] == 0 && theChars[3] == 0)
+ theEncoding = NSUTF32LittleEndianStringEncoding;
+ }
+ else if (theChars[0] == 0 && theChars[2] == 0 && theChars[3] != 0)
+ {
+ if (theChars[1] == 0)
+ theEncoding = NSUTF32BigEndianStringEncoding;
+ else if (theChars[1] != 0)
+ theEncoding = NSUTF16BigEndianStringEncoding;
+ }
+
+ NSString *theString = [[NSString alloc] initWithData:theData encoding:theEncoding];
+ if (theString == NULL && self.allowedEncoding != 0)
+ {
+ theString = [[NSString alloc] initWithData:theData encoding:self.allowedEncoding];
+ }
+ theData = [theString dataUsingEncoding:NSUTF8StringEncoding];
+ [theString release];
+ }
+
+ if (theData)
+ {
+ [super setData:theData];
+ return(YES);
+ }
+ else
+ {
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan data. Data wasn't encoded properly?", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-1 userInfo:theUserInfo];
+ }
+ return(NO);
+ }
+ }
- (void)setData:(NSData *)inData
-{
-[self setData:inData error:NULL];
-}
+ {
+ [self setData:inData error:NULL];
+ }
#pragma mark -
- (BOOL)scanJSONObject:(id *)outObject error:(NSError **)outError
-{
-BOOL theResult = YES;
-
-[self skipWhitespace];
-
-id theObject = NULL;
-
-const unichar C = [self currentCharacter];
-switch (C)
- {
- case 't':
- if ([self scanUTF8String:"true" intoString:NULL])
- {
- theObject = [NSNumber numberWithBool:YES];
- }
- break;
- case 'f':
- if ([self scanUTF8String:"false" intoString:NULL])
- {
- theObject = [NSNumber numberWithBool:NO];
- }
- break;
- case 'n':
- if ([self scanUTF8String:"null" intoString:NULL])
- {
- theObject = self.nullObject;
- }
- break;
- case '\"':
- case '\'':
- theResult = [self scanJSONStringConstant:&theObject error:outError];
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '-':
- theResult = [self scanJSONNumberConstant:&theObject error:outError];
- break;
- case '{':
- theResult = [self scanJSONDictionary:&theObject error:outError];
- break;
- case '[':
- theResult = [self scanJSONArray:&theObject error:outError];
- break;
- default:
- theResult = NO;
+ {
+ BOOL theResult = YES;
+
+ [self skipWhitespace];
+
+ id theObject = NULL;
+
+ const unichar C = [self currentCharacter];
+ switch (C)
+ {
+ case 't':
+ if ([self scanUTF8String:"true" intoString:NULL])
+ {
+ theObject = [NSNumber numberWithBool:YES];
+ }
+ break;
+ case 'f':
+ if ([self scanUTF8String:"false" intoString:NULL])
+ {
+ theObject = [NSNumber numberWithBool:NO];
+ }
+ break;
+ case 'n':
+ if ([self scanUTF8String:"null" intoString:NULL])
+ {
+ theObject = self.nullObject;
+ }
+ break;
+ case '\"':
+ case '\'':
+ theResult = [self scanJSONStringConstant:&theObject error:outError];
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ case '-':
+ theResult = [self scanJSONNumberConstant:&theObject error:outError];
+ break;
+ case '{':
+ theResult = [self scanJSONDictionary:&theObject error:outError];
+ break;
+ case '[':
+ theResult = [self scanJSONArray:&theObject error:outError];
+ break;
+ default:
+ theResult = NO;
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan object. Character not a valid JSON character.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-1 userInfo:theUserInfo];
+ }
+ break;
+ }
+
+ if (outObject != NULL)
+ *outObject = theObject;
+
+ return(theResult);
+ }
+
+- (BOOL)scanJSONDictionary:(NSDictionary **)outDictionary error:(NSError **)outError
+ {
+ NSUInteger theScanLocation = [self scanLocation];
+
+ [self skipWhitespace];
+
+ if ([self scanCharacter:'{'] == NO)
+ {
if (outError)
{
NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan object. Character not a valid JSON character.", NSLocalizedDescriptionKey,
+ @"Could not scan dictionary. Dictionary that does not start with '{' character.", NSLocalizedDescriptionKey,
NULL];
[theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
*outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-1 userInfo:theUserInfo];
}
- break;
- }
+ return(NO);
+ }
-if (outObject != NULL)
- *outObject = theObject;
+ NSMutableDictionary *theDictionary = [[NSMutableDictionary alloc] init];
-return(theResult);
-}
+ while ([self currentCharacter] != '}')
+ {
+ [self skipWhitespace];
+
+ if ([self currentCharacter] == '}')
+ break;
-- (BOOL)scanJSONDictionary:(NSDictionary **)outDictionary error:(NSError **)outError
-{
-NSUInteger theScanLocation = [self scanLocation];
-
-[self skipWhitespace];
-
-if ([self scanCharacter:'{'] == NO)
- {
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan dictionary. Dictionary that does not start with '{' character.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-1 userInfo:theUserInfo];
- }
- return(NO);
- }
-
-NSMutableDictionary *theDictionary = [[NSMutableDictionary alloc] init];
-
-while ([self currentCharacter] != '}')
- {
- [self skipWhitespace];
-
- if ([self currentCharacter] == '}')
- break;
-
- NSString *theKey = NULL;
- if ([self scanJSONStringConstant:&theKey error:outError] == NO)
- {
- [self setScanLocation:theScanLocation];
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan dictionary. Failed to scan a key.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-2 userInfo:theUserInfo];
- }
- [theDictionary release];
- return(NO);
- }
-
- [self skipWhitespace];
-
- if ([self scanCharacter:':'] == NO)
- {
- [self setScanLocation:theScanLocation];
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan dictionary. Key was not terminated with a ':' character.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-3 userInfo:theUserInfo];
- }
- [theDictionary release];
- return(NO);
- }
-
- id theValue = NULL;
- if ([self scanJSONObject:&theValue error:outError] == NO)
- {
- [self setScanLocation:theScanLocation];
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan dictionary. Failed to scan a value.", NSLocalizedDescriptionKey,
- NULL];
-
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-4 userInfo:theUserInfo];
- }
- [theDictionary release];
- return(NO);
- }
+ NSString *theKey = NULL;
+ if ([self scanJSONStringConstant:&theKey error:outError] == NO)
+ {
+ [self setScanLocation:theScanLocation];
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan dictionary. Failed to scan a key.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-2 userInfo:theUserInfo];
+ }
+ [theDictionary release];
+ return(NO);
+ }
- if (theValue == NULL && self.nullObject == NULL)
- {
- // If the value is a null and nullObject is also null then we're skipping this key/value pair.
+ [self skipWhitespace];
+
+ if ([self scanCharacter:':'] == NO)
+ {
+ [self setScanLocation:theScanLocation];
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan dictionary. Key was not terminated with a ':' character.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-3 userInfo:theUserInfo];
+ }
+ [theDictionary release];
+ return(NO);
+ }
+
+ id theValue = NULL;
+ if ([self scanJSONObject:&theValue error:outError] == NO)
+ {
+ [self setScanLocation:theScanLocation];
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan dictionary. Failed to scan a value.", NSLocalizedDescriptionKey,
+ NULL];
+
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-4 userInfo:theUserInfo];
+ }
+ [theDictionary release];
+ return(NO);
+ }
+
+ if (theValue == NULL && self.nullObject == NULL)
+ {
+ // If the value is a null and nullObject is also null then we're skipping this key/value pair.
+ }
+ else
+ {
+ [theDictionary setValue:theValue forKey:theKey];
+ }
+
+ [self skipWhitespace];
+ if ([self scanCharacter:','] == NO)
+ {
+ if ([self currentCharacter] != '}')
+ {
+ [self setScanLocation:theScanLocation];
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan dictionary. Key value pairs not delimited with a ',' character.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-5 userInfo:theUserInfo];
+ }
+ [theDictionary release];
+ return(NO);
+ }
+ break;
+ }
+ else
+ {
+ [self skipWhitespace];
+ if ([self currentCharacter] == '}')
+ break;
+ }
}
- else
+
+ if ([self scanCharacter:'}'] == NO)
{
- [theDictionary setValue:theValue forKey:theKey];
+ [self setScanLocation:theScanLocation];
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan dictionary. Dictionary not terminated by a '}' character.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-6 userInfo:theUserInfo];
+ }
+ [theDictionary release];
+ return(NO);
}
- [self skipWhitespace];
- if ([self scanCharacter:','] == NO)
- {
- if ([self currentCharacter] != '}')
- {
- [self setScanLocation:theScanLocation];
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan dictionary. Key value pairs not delimited with a ',' character.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-5 userInfo:theUserInfo];
- }
- [theDictionary release];
- return(NO);
- }
- break;
- }
- else
- {
- [self skipWhitespace];
- if ([self currentCharacter] == '}')
- break;
- }
- }
-
-if ([self scanCharacter:'}'] == NO)
- {
- [self setScanLocation:theScanLocation];
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan dictionary. Dictionary not terminated by a '}' character.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-6 userInfo:theUserInfo];
- }
- [theDictionary release];
- return(NO);
- }
-
-if (outDictionary != NULL)
- *outDictionary = [[theDictionary copy] autorelease];
-
-[theDictionary release];
-
-return(YES);
-}
+ if (outDictionary != NULL)
+ *outDictionary = [[theDictionary copy] autorelease];
+
+ [theDictionary release];
+
+ return(YES);
+ }
- (BOOL)scanJSONArray:(NSArray **)outArray error:(NSError **)outError
-{
-NSUInteger theScanLocation = [self scanLocation];
-
-[self skipWhitespace];
-
-if ([self scanCharacter:'['] == NO)
- {
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan array. Array not started by a '[' character.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-7 userInfo:theUserInfo];
- }
- return(NO);
- }
-
-NSMutableArray *theArray = [[NSMutableArray alloc] init];
-
-[self skipWhitespace];
-while ([self currentCharacter] != ']')
- {
- NSString *theValue = NULL;
- if ([self scanJSONObject:&theValue error:outError] == NO)
- {
- [self setScanLocation:theScanLocation];
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan array. Could not scan a value.", NSLocalizedDescriptionKey,
- NULL];
+ {
+ NSUInteger theScanLocation = [self scanLocation];
+
+ [self skipWhitespace];
+
+ if ([self scanCharacter:'['] == NO)
+ {
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan array. Array not started by a '[' character.", NSLocalizedDescriptionKey,
+ NULL];
[theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-8 userInfo:theUserInfo];
- }
- [theArray release];
- return(NO);
- }
-
- if (theValue == NULL)
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-7 userInfo:theUserInfo];
+ }
+ return(NO);
+ }
+
+ NSMutableArray *theArray = [[NSMutableArray alloc] init];
+
+ [self skipWhitespace];
+ while ([self currentCharacter] != ']')
{
- if (self.nullObject != NULL)
+ NSString *theValue = NULL;
+ if ([self scanJSONObject:&theValue error:outError] == NO)
{
+ [self setScanLocation:theScanLocation];
if (outError)
{
NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan array. Value is NULL.", NSLocalizedDescriptionKey,
+ @"Could not scan array. Could not scan a value.", NSLocalizedDescriptionKey,
NULL];
[theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-9 userInfo:theUserInfo];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-8 userInfo:theUserInfo];
}
[theArray release];
return(NO);
}
+
+ if (theValue == NULL)
+ {
+ if (self.nullObject != NULL)
+ {
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan array. Value is NULL.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-9 userInfo:theUserInfo];
+ }
+ [theArray release];
+ return(NO);
+ }
+ }
+ else
+ {
+ [theArray addObject:theValue];
+ }
+
+ [self skipWhitespace];
+ if ([self scanCharacter:','] == NO)
+ {
+ [self skipWhitespace];
+ if ([self currentCharacter] != ']')
+ {
+ [self setScanLocation:theScanLocation];
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan array. Array not terminated by a ']' character.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-9 userInfo:theUserInfo];
+ }
+ [theArray release];
+ return(NO);
+ }
+
+ break;
+ }
+ [self skipWhitespace];
}
- else
+
+ [self skipWhitespace];
+
+ if ([self scanCharacter:']'] == NO)
{
- [theArray addObject:theValue];
+ [self setScanLocation:theScanLocation];
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan array. Array not terminated by a ']' character.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-10 userInfo:theUserInfo];
+ }
+ [theArray release];
+ return(NO);
}
-
- [self skipWhitespace];
- if ([self scanCharacter:','] == NO)
- {
- [self skipWhitespace];
- if ([self currentCharacter] != ']')
- {
- [self setScanLocation:theScanLocation];
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan array. Array not terminated by a ']' character.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-9 userInfo:theUserInfo];
- }
- [theArray release];
- return(NO);
- }
-
- break;
- }
- [self skipWhitespace];
- }
-
-[self skipWhitespace];
-
-if ([self scanCharacter:']'] == NO)
- {
- [self setScanLocation:theScanLocation];
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan array. Array not terminated by a ']' character.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-10 userInfo:theUserInfo];
- }
- [theArray release];
- return(NO);
- }
-
-if (outArray != NULL)
- *outArray = [[theArray copy] autorelease];
-
-[theArray release];
-
-return(YES);
-}
+
+ if (outArray != NULL)
+ *outArray = [[theArray copy] autorelease];
+
+ [theArray release];
+
+ return(YES);
+ }
- (BOOL)scanJSONStringConstant:(NSString **)outStringConstant error:(NSError **)outError
-{
-NSUInteger theScanLocation = [self scanLocation];
-
-[self skipWhitespace];
-
-NSMutableString *theString = [[NSMutableString alloc] init];
-
-if ([self scanCharacter:'"'] == NO)
- {
- [self setScanLocation:theScanLocation];
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan string constant. String not started by a '\"' character.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-11 userInfo:theUserInfo];
- }
- [theString release];
- return(NO);
- }
-
-while ([self scanCharacter:'"'] == NO)
- {
- NSString *theStringChunk = NULL;
- if ([self scanNotQuoteCharactersIntoString:&theStringChunk])
- {
- CFStringAppend((CFMutableStringRef)theString, (CFStringRef)theStringChunk);
- }
- else if ([self scanCharacter:'\\'] == YES)
- {
- unichar theCharacter = [self scanCharacter];
- switch (theCharacter)
- {
- case '"':
- case '\\':
- case '/':
- break;
- case 'b':
- theCharacter = '\b';
- break;
- case 'f':
- theCharacter = '\f';
- break;
- case 'n':
- theCharacter = '\n';
- break;
- case 'r':
- theCharacter = '\r';
- break;
- case 't':
- theCharacter = '\t';
- break;
- case 'u':
- {
- theCharacter = 0;
-
- int theShift;
- for (theShift = 12; theShift >= 0; theShift -= 4)
- {
- const int theDigit = HexToInt([self scanCharacter]);
- if (theDigit == -1)
- {
- [self setScanLocation:theScanLocation];
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan string constant. Unicode character could not be decoded.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-12 userInfo:theUserInfo];
- }
- [theString release];
- return(NO);
- }
- theCharacter |= (theDigit << theShift);
- }
- }
- break;
- default:
- {
- if (strictEscapeCodes == YES)
- {
- [self setScanLocation:theScanLocation];
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan string constant. Unknown escape code.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-13 userInfo:theUserInfo];
- }
- [theString release];
- return(NO);
- }
- }
- break;
- }
- CFStringAppendCharacters((CFMutableStringRef)theString, &theCharacter, 1);
- }
- else
+ {
+ NSUInteger theScanLocation = [self scanLocation];
+
+ [self skipWhitespace];
+
+ NSMutableString *theString = [[NSMutableString alloc] init];
+
+ if ([self scanCharacter:'"'] == NO)
{
+ [self setScanLocation:theScanLocation];
if (outError)
{
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan string constant. No terminating double quote character.", NSLocalizedDescriptionKey,
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan string constant. String not started by a '\"' character.", NSLocalizedDescriptionKey,
NULL];
[theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-14 userInfo:theUserInfo];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-11 userInfo:theUserInfo];
}
[theString release];
return(NO);
}
- }
-
-if (outStringConstant != NULL)
- *outStringConstant = [[theString copy] autorelease];
+ while ([self scanCharacter:'"'] == NO)
+ {
+ NSString *theStringChunk = NULL;
+ if ([self scanNotQuoteCharactersIntoString:&theStringChunk])
+ {
+ CFStringAppend((CFMutableStringRef)theString, (CFStringRef)theStringChunk);
+ }
+ else if ([self scanCharacter:'\\'] == YES)
+ {
+ unichar theCharacter = [self scanCharacter];
+ switch (theCharacter)
+ {
+ case '"':
+ case '\\':
+ case '/':
+ break;
+ case 'b':
+ theCharacter = '\b';
+ break;
+ case 'f':
+ theCharacter = '\f';
+ break;
+ case 'n':
+ theCharacter = '\n';
+ break;
+ case 'r':
+ theCharacter = '\r';
+ break;
+ case 't':
+ theCharacter = '\t';
+ break;
+ case 'u':
+ {
+ theCharacter = 0;
+
+ int theShift;
+ for (theShift = 12; theShift >= 0; theShift -= 4)
+ {
+ const int theDigit = HexToInt([self scanCharacter]);
+ if (theDigit == -1)
+ {
+ [self setScanLocation:theScanLocation];
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan string constant. Unicode character could not be decoded.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-12 userInfo:theUserInfo];
+ }
+ [theString release];
+ return(NO);
+ }
+ theCharacter |= (theDigit << theShift);
+ }
+ }
+ break;
+ default:
+ {
+ if (strictEscapeCodes == YES)
+ {
+ [self setScanLocation:theScanLocation];
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan string constant. Unknown escape code.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-13 userInfo:theUserInfo];
+ }
+ [theString release];
+ return(NO);
+ }
+ }
+ break;
+ }
+ CFStringAppendCharacters((CFMutableStringRef)theString, &theCharacter, 1);
+ }
+ else
+ {
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan string constant. No terminating double quote character.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-14 userInfo:theUserInfo];
+ }
+ [theString release];
+ return(NO);
+ }
+
+ }
+
+ if (outStringConstant != NULL)
+ *outStringConstant = [[theString copy] autorelease];
-[theString release];
+ [theString release];
-return(YES);
-}
+ return(YES);
+ }
- (BOOL)scanJSONNumberConstant:(NSNumber **)outNumberConstant error:(NSError **)outError
-{
-NSNumber *theNumber = NULL;
-
-[self skipWhitespace];
-
-if ([self scanNumber:&theNumber] == YES)
- {
- if (outNumberConstant != NULL)
- *outNumberConstant = theNumber;
- return(YES);
- }
-else
- {
- if (outError)
- {
- NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"Could not scan number constant.", NSLocalizedDescriptionKey,
- NULL];
- [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
- *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-14 userInfo:theUserInfo];
- }
- return(NO);
- }
-}
+ {
+ NSNumber *theNumber = NULL;
+
+ [self skipWhitespace];
+
+ if ([self scanNumber:&theNumber] == YES)
+ {
+ if (outNumberConstant != NULL)
+ *outNumberConstant = theNumber;
+ return(YES);
+ }
+ else
+ {
+ if (outError)
+ {
+ NSMutableDictionary *theUserInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"Could not scan number constant.", NSLocalizedDescriptionKey,
+ NULL];
+ [theUserInfo addEntriesFromDictionary:self.userInfoForScanLocation];
+ *outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-14 userInfo:theUserInfo];
+ }
+ return(NO);
+ }
+ }
#if TREAT_COMMENTS_AS_WHITESPACE
- (void)skipWhitespace
-{
-[super skipWhitespace];
-[self scanCStyleComment:NULL];
-[self scanCPlusPlusStyleComment:NULL];
-[super skipWhitespace];
-}
+ {
+ [super skipWhitespace];
+ [self scanCStyleComment:NULL];
+ [self scanCPlusPlusStyleComment:NULL];
+ [super skipWhitespace];
+ }
#endif // TREAT_COMMENTS_AS_WHITESPACE
#pragma mark -
- (BOOL)scanNotQuoteCharactersIntoString:(NSString **)outValue
-{
-u_int8_t *P;
-for (P = current; P < end && *P != '\"' && *P != '\\'; ++P)
- ;
-
-if (P == current)
- {
- return(NO);
- }
-
-if (outValue)
- {
- *outValue = [[[NSString alloc] initWithBytes:current length:P - current encoding:NSUTF8StringEncoding] autorelease];
- }
-
-current = P;
-
-return(YES);
-}
+ {
+ u_int8_t *P;
+ for (P = current; P < end && *P != '\"' && *P != '\\'; ++P)
+ ;
+
+ if (P == current)
+ {
+ return(NO);
+ }
+
+ if (outValue)
+ {
+ *outValue = [[[NSString alloc] initWithBytes:current length:P - current encoding:NSUTF8StringEncoding] autorelease];
+ }
+
+ current = P;
+
+ return(YES);
+ }
@end
View
430 Source/JSON/CJSONSerializer.m
@@ -55,251 +55,251 @@ + (void)initialize
}
+ (id)serializer
-{
-return([[[self alloc] init] autorelease]);
-}
+ {
+ return([[[self alloc] init] autorelease]);
+ }
- (NSData *)serializeObject:(id)inObject error:(NSError **)outError
-{
-NSData *theResult = NULL;
+ {
+ NSData *theResult = NULL;
-if ([inObject isKindOfClass:[NSNull class]])
- {
- theResult = [self serializeNull:inObject error:outError];
- }
-else if ([inObject isKindOfClass:[NSNumber class]])
- {
- theResult = [self serializeNumber:inObject error:outError];
- }
-else if ([inObject isKindOfClass:[NSString class]])
- {
- theResult = [self serializeString:inObject error:outError];
- }
-else if ([inObject isKindOfClass:[NSArray class]])
- {
- theResult = [self serializeArray:inObject error:outError];
- }
-else if ([inObject isKindOfClass:[NSDictionary class]])
- {
- theResult = [self serializeDictionary:inObject error:outError];
- }
-else if ([inObject isKindOfClass:[NSData class]])
- {
- NSString *theString = [[[NSString alloc] initWithData:inObject encoding:NSUTF8StringEncoding] autorelease];
- theResult = [self serializeString:theString error:outError];
- }
-else if ([inObject respondsToSelector:@selector(JSONDataRepresentation)])
- {
- theResult = [inObject JSONDataRepresentation];
- }
-else
- {
- if (outError)
- {
- NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSString stringWithFormat:@"Cannot serialize data of type '%@'", NSStringFromClass([inObject class])], NSLocalizedDescriptionKey,
- NULL];
- *outError = [NSError errorWithDomain:@"TODO_DOMAIN" code:-1 userInfo:theUserInfo];
- }
- return(NULL);
- }
-if (theResult == NULL)
- {
- if (outError)
- {
- NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSString stringWithFormat:@"Could not serialize object '%@'", inObject], NSLocalizedDescriptionKey,
- NULL];
- *outError = [NSError errorWithDomain:@"TODO_DOMAIN" code:-1 userInfo:theUserInfo];
- }
- return(NULL);
- }
-return(theResult);
-}
+ if ([inObject isKindOfClass:[NSNull class]])
+ {
+ theResult = [self serializeNull:inObject error:outError];
+ }
+ else if ([inObject isKindOfClass:[NSNumber class]])
+ {
+ theResult = [self serializeNumber:inObject error:outError];
+ }
+ else if ([inObject isKindOfClass:[NSString class]])
+ {
+ theResult = [self serializeString:inObject error:outError];
+ }
+ else if ([inObject isKindOfClass:[NSArray class]])
+ {
+ theResult = [self serializeArray:inObject error:outError];
+ }
+ else if ([inObject isKindOfClass:[NSDictionary class]])
+ {
+ theResult = [self serializeDictionary:inObject error:outError];
+ }
+ else if ([inObject isKindOfClass:[NSData class]])
+ {
+ NSString *theString = [[[NSString alloc] initWithData:inObject encoding:NSUTF8StringEncoding] autorelease];
+ theResult = [self serializeString:theString error:outError];
+ }
+ else if ([inObject respondsToSelector:@selector(JSONDataRepresentation)])
+ {
+ theResult = [inObject JSONDataRepresentation];
+ }
+ else
+ {
+ if (outError)
+ {
+ NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSString stringWithFormat:@"Cannot serialize data of type '%@'", NSStringFromClass([inObject class])], NSLocalizedDescriptionKey,
+ NULL];
+ *outError = [NSError errorWithDomain:@"TODO_DOMAIN" code:-1 userInfo:theUserInfo];
+ }
+ return(NULL);
+ }
+ if (theResult == NULL)
+ {
+ if (outError)
+ {
+ NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSString stringWithFormat:@"Could not serialize object '%@'", inObject], NSLocalizedDescriptionKey,
+ NULL];
+ *outError = [NSError errorWithDomain:@"TODO_DOMAIN" code:-1 userInfo:theUserInfo];
+ }
+ return(NULL);
+ }
+ return(theResult);
+ }
- (NSData *)serializeNull:(NSNull *)inNull error:(NSError **)outError
-{
-#pragma unused (inNull, outError)
-return(kNULL);
-}
+ {
+ #pragma unused (inNull, outError)
+ return(kNULL);
+ }
- (NSData *)serializeNumber:(NSNumber *)inNumber error:(NSError **)outError
-{
-#pragma unused (outError)
-NSData *theResult = NULL;
-switch (CFNumberGetType((CFNumberRef)inNumber))
- {
- case kCFNumberCharType:
- {
- int theValue = [inNumber intValue];
- if (theValue == 0)
- theResult = kFalse;
- else if (theValue == 1)
- theResult = kTrue;
- else
- theResult = [[inNumber stringValue] dataUsingEncoding:NSASCIIStringEncoding];
- }
- break;
- case kCFNumberFloat32Type:
- case kCFNumberFloat64Type:
- case kCFNumberFloatType:
- case kCFNumberDoubleType:
- case kCFNumberSInt8Type:
- case kCFNumberSInt16Type:
- case kCFNumberSInt32Type:
- case kCFNumberSInt64Type:
- case kCFNumberShortType:
- case kCFNumberIntType:
- case kCFNumberLongType:
- case kCFNumberLongLongType:
- case kCFNumberCFIndexType:
- default:
- theResult = [[inNumber stringValue] dataUsingEncoding:NSASCIIStringEncoding];
- break;
- }
-return(theResult);
-}
+ {
+ #pragma unused (outError)
+ NSData *theResult = NULL;
+ switch (CFNumberGetType((CFNumberRef)inNumber))
+ {
+ case kCFNumberCharType:
+ {
+ int theValue = [inNumber intValue];
+ if (theValue == 0)
+ theResult = kFalse;
+ else if (theValue == 1)
+ theResult = kTrue;
+ else
+ theResult = [[inNumber stringValue] dataUsingEncoding:NSASCIIStringEncoding];
+ }
+ break;
+ case kCFNumberFloat32Type:
+ case kCFNumberFloat64Type:
+ case kCFNumberFloatType:
+ case kCFNumberDoubleType:
+ case kCFNumberSInt8Type:
+ case kCFNumberSInt16Type:
+ case kCFNumberSInt32Type:
+ case kCFNumberSInt64Type:
+ case kCFNumberShortType:
+ case kCFNumberIntType:
+ case kCFNumberLongType:
+ case kCFNumberLongLongType:
+ case kCFNumberCFIndexType:
+ default:
+ theResult = [[inNumber stringValue] dataUsingEncoding:NSASCIIStringEncoding];
+ break;
+ }
+ return(theResult);
+ }
- (NSData *)serializeString:(NSString *)inString error:(NSError **)outError
-{
-#pragma unused (outError)
+ {
+ #pragma unused (outError)
-NSMutableData *theData = [NSMutableData dataWithLength:inString.length * 2 + 2];
+ NSMutableData *theData = [NSMutableData dataWithLength:inString.length * 2 + 2];
-char *theOutputStart = [theData mutableBytes];
-char *OUT = theOutputStart;
+ char *theOutputStart = [theData mutableBytes];
+ char *OUT = theOutputStart;
-*OUT++ = '"';
+ *OUT++ = '"';
-const char *theUTF8String = [inString UTF8String];
-for (const char *IN = theUTF8String; IN && *IN != '\0'; ++IN)
- {
- switch (*IN)
+ const char *theUTF8String = [inString UTF8String];
+ for (const char *IN = theUTF8String; IN && *IN != '\0'; ++IN)
{
- case '\\':
+ switch (*IN)
{
- *OUT++ = '\\';
- *OUT++ = '\\';
+ case '\\':
+ {
+ *OUT++ = '\\';
+ *OUT++ = '\\';
+ }
+ break;
+ case '\"':
+ {
+ *OUT++ = '\\';
+ *OUT++ = '\"';
+ }
+ break;
+ case '/':
+ {
+ *OUT++ = '\\';
+ *OUT++ = '/';
+ }
+ break;
+ case '\b':
+ {
+ *OUT++ = '\\';
+ *OUT++ = 'b';
+ }
+ break;
+ case '\f':
+ {
+ *OUT++ = '\\';
+ *OUT++ = 'f';
+ }
+ break;
+ case '\n':
+ {
+ *OUT++ = '\\';
+ *OUT++ = 'n';
+ }
+ break;
+ case '\r':
+ {
+ *OUT++ = '\\';
+ *OUT++ = 'r';
+ }
+ break;
+ case '\t':
+ {
+ *OUT++ = '\\';
+ *OUT++ = 't';
+ }
+ break;
+ default:
+ {
+ *OUT++ = *IN;
+ }
+ break;
}
- break;