Skip to content

Commit

Permalink
Tabs to spaces:
Browse files Browse the repository at this point in the history
for i in `find **/*.h **/*.m`; do echo "Expanding $i" && expand -t 2
  $i >$i.tmp && mv $i.tmp $i; done
  • Loading branch information
gabriel committed Apr 15, 2010
1 parent 7e4fa59 commit 78fb38f
Show file tree
Hide file tree
Showing 18 changed files with 587 additions and 587 deletions.
48 changes: 24 additions & 24 deletions Classes/NSObject+YAJL.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,44 @@ @implementation NSObject (YAJL)
#pragma mark Gen

- (NSString *)yajl_JSONString {
return [self yajl_JSONStringWithOptions:YAJLGenOptionsNone indentString:@" "];
return [self yajl_JSONStringWithOptions:YAJLGenOptionsNone indentString:@" "];
}

- (NSString *)yajl_JSONStringWithOptions:(YAJLGenOptions)options indentString:(NSString *)indentString {
YAJLGen *gen = [[YAJLGen alloc] initWithGenOptions:options indentString:indentString];
[gen object:self];
NSString *buffer = [[gen buffer] retain];
[gen release];
return [buffer autorelease];
YAJLGen *gen = [[YAJLGen alloc] initWithGenOptions:options indentString:indentString];
[gen object:self];
NSString *buffer = [[gen buffer] retain];
[gen release];
return [buffer autorelease];
}

#pragma mark Parsing

- (id)yajl_JSON {
NSError *error = nil;
id JSON = [self yajl_JSON:&error];
if (error) [NSException raise:YAJLParserException format:[error localizedDescription]];
return JSON;
NSError *error = nil;
id JSON = [self yajl_JSON:&error];
if (error) [NSException raise:YAJLParserException format:[error localizedDescription]];
return JSON;
}

- (id)yajl_JSON:(NSError **)error {
return [self yajl_JSONWithOptions:YAJLParserOptionsNone error:error];
return [self yajl_JSONWithOptions:YAJLParserOptionsNone error:error];
}

- (id)yajl_JSONWithOptions:(YAJLParserOptions)options error:(NSError **)error {
NSData *data = nil;
if ([self isKindOfClass:[NSData class]]) {
data = (NSData *)self;
} else if ([self respondsToSelector:@selector(dataUsingEncoding:)]) {
data = [(id)self dataUsingEncoding:NSUTF8StringEncoding];
} else {
[NSException raise:YAJLParsingUnsupportedException format:@"Object of type (%@) must implement dataUsingEncoding: to be parsed", [self class]];
}
YAJLDocument *document = [[YAJLDocument alloc] initWithData:data parserOptions:options error:error];
id root = [document.root retain];
[document release];
return [root autorelease];
NSData *data = nil;
if ([self isKindOfClass:[NSData class]]) {
data = (NSData *)self;
} else if ([self respondsToSelector:@selector(dataUsingEncoding:)]) {
data = [(id)self dataUsingEncoding:NSUTF8StringEncoding];
} else {
[NSException raise:YAJLParsingUnsupportedException format:@"Object of type (%@) must implement dataUsingEncoding: to be parsed", [self class]];
}
YAJLDocument *document = [[YAJLDocument alloc] initWithData:data parserOptions:options error:error];
id root = [document.root retain];
[document release];
return [root autorelease];
}


Expand Down
36 changes: 18 additions & 18 deletions Classes/YAJLDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
#include "YAJLParser.h"

typedef enum {
YAJLDecoderCurrentTypeNone,
YAJLDecoderCurrentTypeArray,
YAJLDecoderCurrentTypeDict
YAJLDecoderCurrentTypeNone,
YAJLDecoderCurrentTypeArray,
YAJLDecoderCurrentTypeDict
} YAJLDecoderCurrentType;

extern NSInteger YAJLDocumentStackCapacity;
Expand All @@ -49,22 +49,22 @@ extern NSInteger YAJLDocumentStackCapacity;
@end

@interface YAJLDocument : NSObject <YAJLParserDelegate> {
id root_; // NSArray or NSDictionary
YAJLParser *parser_;
id root_; // NSArray or NSDictionary
YAJLParser *parser_;
__weak id<YAJLDocumentDelegate> delegate_;
__weak NSMutableDictionary *dict_; // weak; if map in progress, points to the current map
__weak NSMutableArray *array_; // weak; If array in progress, points the current array
__weak NSString *key_; // weak; If map in progress, points to current key
NSMutableArray *stack_;
NSMutableArray *keyStack_;
YAJLDecoderCurrentType currentType_;
YAJLParserStatus parserStatus_;
__weak NSMutableDictionary *dict_; // weak; if map in progress, points to the current map
__weak NSMutableArray *array_; // weak; If array in progress, points the current array
__weak NSString *key_; // weak; If map in progress, points to current key
NSMutableArray *stack_;
NSMutableArray *keyStack_;
YAJLDecoderCurrentType currentType_;
YAJLParserStatus parserStatus_;

}

Expand Down
142 changes: 71 additions & 71 deletions Classes/YAJLDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,122 +46,122 @@ - (id)init {
}

- (id)initWithParserOptions:(YAJLParserOptions)parserOptions {
if ((self = [super init])) {
stack_ = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
keyStack_ = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
parserStatus_ = YAJLParserStatusNone;
parser_ = [[YAJLParser alloc] initWithParserOptions:parserOptions];
parser_.delegate = self;
}
return self;
if ((self = [super init])) {
stack_ = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
keyStack_ = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
parserStatus_ = YAJLParserStatusNone;
parser_ = [[YAJLParser alloc] initWithParserOptions:parserOptions];
parser_.delegate = self;
}
return self;
}

- (id)initWithData:(NSData *)data parserOptions:(YAJLParserOptions)parserOptions error:(NSError **)error {
if ((self = [self initWithParserOptions:parserOptions])) {
[self parse:data error:error];
}
return self;
if ((self = [self initWithParserOptions:parserOptions])) {
[self parse:data error:error];
}
return self;
}

- (void)dealloc {
[stack_ release];
[keyStack_ release];
parser_.delegate = nil;
[parser_ release];
[root_ release];
[super dealloc];
[stack_ release];
[keyStack_ release];
parser_.delegate = nil;
[parser_ release];
[root_ release];
[super dealloc];
}

- (YAJLParserStatus)parse:(NSData *)data error:(NSError **)error {
parserStatus_ = [parser_ parse:data];
if (error) *error = [parser_ parserError];
return parserStatus_;
parserStatus_ = [parser_ parse:data];
if (error) *error = [parser_ parserError];
return parserStatus_;
}

#pragma mark Delegates

- (void)parser:(YAJLParser *)parser didAdd:(id)value {
switch(currentType_) {
case YAJLDecoderCurrentTypeArray:
[array_ addObject:value];
switch(currentType_) {
case YAJLDecoderCurrentTypeArray:
[array_ addObject:value];
if ([delegate_ respondsToSelector:@selector(document:didAddObject:toArray:)])
[delegate_ document:self didAddObject:value toArray:array_];
break;
case YAJLDecoderCurrentTypeDict:
NSParameterAssert(key_);
[dict_ setObject:value forKey:key_];
break;
case YAJLDecoderCurrentTypeDict:
NSParameterAssert(key_);
[dict_ setObject:value forKey:key_];
if ([delegate_ respondsToSelector:@selector(document:didSetObject:forKey:inDictionary:)])
[delegate_ document:self didSetObject:value forKey:key_ inDictionary:dict_];
[self _popKey];
break;
}
[self _popKey];
break;
}
}

- (void)parser:(YAJLParser *)parser didMapKey:(NSString *)key {
key_ = key;
[keyStack_ addObject:key_]; // Push
key_ = key;
[keyStack_ addObject:key_]; // Push
}

- (void)_popKey {
key_ = nil;
[keyStack_ removeLastObject]; // Pop
if ([keyStack_ count] > 0)
key_ = [keyStack_ objectAtIndex:[keyStack_ count]-1];
key_ = nil;
[keyStack_ removeLastObject]; // Pop
if ([keyStack_ count] > 0)
key_ = [keyStack_ objectAtIndex:[keyStack_ count]-1];
}

- (void)parserDidStartDictionary:(YAJLParser *)parser {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:YAJLDocumentStackCapacity];
if (!root_) root_ = [dict retain];
[stack_ addObject:dict]; // Push
[dict release];
dict_ = dict;
currentType_ = YAJLDecoderCurrentTypeDict;
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:YAJLDocumentStackCapacity];
if (!root_) root_ = [dict retain];
[stack_ addObject:dict]; // Push
[dict release];
dict_ = dict;
currentType_ = YAJLDecoderCurrentTypeDict;
}

- (void)parserDidEndDictionary:(YAJLParser *)parser {
id value = [[stack_ objectAtIndex:[stack_ count]-1] retain];
id value = [[stack_ objectAtIndex:[stack_ count]-1] retain];
NSDictionary *dict = dict_;
[self _pop];
[self parser:parser didAdd:value];
[value release];
[self _pop];
[self parser:parser didAdd:value];
[value release];
if ([delegate_ respondsToSelector:@selector(document:didAddDictionary:)])
[delegate_ document:self didAddDictionary:dict];
}

- (void)parserDidStartArray:(YAJLParser *)parser {
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
if (!root_) root_ = [array retain];
[stack_ addObject:array]; // Push
[array release];
array_ = array;
currentType_ = YAJLDecoderCurrentTypeArray;
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
if (!root_) root_ = [array retain];
[stack_ addObject:array]; // Push
[array release];
array_ = array;
currentType_ = YAJLDecoderCurrentTypeArray;
}

- (void)parserDidEndArray:(YAJLParser *)parser {
id value = [[stack_ objectAtIndex:[stack_ count]-1] retain];
id value = [[stack_ objectAtIndex:[stack_ count]-1] retain];
NSArray *array = array_;
[self _pop];
[self parser:parser didAdd:value];
[value release];
[self _pop];
[self parser:parser didAdd:value];
[value release];
if ([delegate_ respondsToSelector:@selector(document:didAddArray:)])
[delegate_ document:self didAddArray:array];
}

- (void)_pop {
[stack_ removeLastObject];
array_ = nil;
dict_ = nil;
currentType_ = YAJLDecoderCurrentTypeNone;

id value = nil;
if ([stack_ count] > 0) value = [stack_ objectAtIndex:[stack_ count]-1];
if ([value isKindOfClass:[NSArray class]]) {
array_ = (NSMutableArray *)value;
currentType_ = YAJLDecoderCurrentTypeArray;
} else if ([value isKindOfClass:[NSDictionary class]]) {
dict_ = (NSMutableDictionary *)value;
currentType_ = YAJLDecoderCurrentTypeDict;
}
[stack_ removeLastObject];
array_ = nil;
dict_ = nil;
currentType_ = YAJLDecoderCurrentTypeNone;

id value = nil;
if ([stack_ count] > 0) value = [stack_ objectAtIndex:[stack_ count]-1];
if ([value isKindOfClass:[NSArray class]]) {
array_ = (NSMutableArray *)value;
currentType_ = YAJLDecoderCurrentTypeArray;
} else if ([value isKindOfClass:[NSDictionary class]]) {
dict_ = (NSMutableDictionary *)value;
currentType_ = YAJLDecoderCurrentTypeDict;
}
}

@end
6 changes: 3 additions & 3 deletions Classes/YAJLGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ extern NSString *const YAJLGenInvalidObjectException;
@constant YAJLGenOptionsBeautify
*/
enum {
YAJLGenOptionsNone = 0,
YAJLGenOptionsBeautify = 1 << 0,
YAJLGenOptionsNone = 0,
YAJLGenOptionsBeautify = 1 << 0,
YAJLGenOptionsIgnoreUnknownTypes = 1 << 1, // Ignore unknown types (will use null value)
YAJLGenOptionsIncludeUnsupportedTypes = 1 << 2, // Handle non-JSON types (including NSDate, NSData, NSURL)
};
Expand All @@ -59,7 +59,7 @@ typedef NSUInteger YAJLGenOptions;
- NSURL -> URL (absolute) string
*/
@interface YAJLGen : NSObject {
yajl_gen gen_;
yajl_gen gen_;

YAJLGenOptions genOptions_;
}
Expand Down
Loading

0 comments on commit 78fb38f

Please sign in to comment.