Skip to content
This repository
Browse code

Tabs to spaces:

for i in `find **/*.h **/*.m`; do echo "Expanding $i" && expand -t 2
  $i >$i.tmp && mv $i.tmp $i; done
  • Loading branch information...
commit 78fb38fdf3f0e868665bc3f7fce33696e5414236 1 parent 7e4fa59
Gabriel Handford authored
48 Classes/NSObject+YAJL.m
@@ -36,44 +36,44 @@ @implementation NSObject (YAJL)
36 36 #pragma mark Gen
37 37
38 38 - (NSString *)yajl_JSONString {
39   - return [self yajl_JSONStringWithOptions:YAJLGenOptionsNone indentString:@" "];
  39 + return [self yajl_JSONStringWithOptions:YAJLGenOptionsNone indentString:@" "];
40 40 }
41 41
42 42 - (NSString *)yajl_JSONStringWithOptions:(YAJLGenOptions)options indentString:(NSString *)indentString {
43   - YAJLGen *gen = [[YAJLGen alloc] initWithGenOptions:options indentString:indentString];
44   - [gen object:self];
45   - NSString *buffer = [[gen buffer] retain];
46   - [gen release];
47   - return [buffer autorelease];
  43 + YAJLGen *gen = [[YAJLGen alloc] initWithGenOptions:options indentString:indentString];
  44 + [gen object:self];
  45 + NSString *buffer = [[gen buffer] retain];
  46 + [gen release];
  47 + return [buffer autorelease];
48 48 }
49 49
50 50 #pragma mark Parsing
51 51
52 52 - (id)yajl_JSON {
53   - NSError *error = nil;
54   - id JSON = [self yajl_JSON:&error];
55   - if (error) [NSException raise:YAJLParserException format:[error localizedDescription]];
56   - return JSON;
  53 + NSError *error = nil;
  54 + id JSON = [self yajl_JSON:&error];
  55 + if (error) [NSException raise:YAJLParserException format:[error localizedDescription]];
  56 + return JSON;
57 57 }
58 58
59 59 - (id)yajl_JSON:(NSError **)error {
60   - return [self yajl_JSONWithOptions:YAJLParserOptionsNone error:error];
  60 + return [self yajl_JSONWithOptions:YAJLParserOptionsNone error:error];
61 61 }
62 62
63 63 - (id)yajl_JSONWithOptions:(YAJLParserOptions)options error:(NSError **)error {
64   - NSData *data = nil;
65   - if ([self isKindOfClass:[NSData class]]) {
66   - data = (NSData *)self;
67   - } else if ([self respondsToSelector:@selector(dataUsingEncoding:)]) {
68   - data = [(id)self dataUsingEncoding:NSUTF8StringEncoding];
69   - } else {
70   - [NSException raise:YAJLParsingUnsupportedException format:@"Object of type (%@) must implement dataUsingEncoding: to be parsed", [self class]];
71   - }
72   -
73   - YAJLDocument *document = [[YAJLDocument alloc] initWithData:data parserOptions:options error:error];
74   - id root = [document.root retain];
75   - [document release];
76   - return [root autorelease];
  64 + NSData *data = nil;
  65 + if ([self isKindOfClass:[NSData class]]) {
  66 + data = (NSData *)self;
  67 + } else if ([self respondsToSelector:@selector(dataUsingEncoding:)]) {
  68 + data = [(id)self dataUsingEncoding:NSUTF8StringEncoding];
  69 + } else {
  70 + [NSException raise:YAJLParsingUnsupportedException format:@"Object of type (%@) must implement dataUsingEncoding: to be parsed", [self class]];
  71 + }
  72 +
  73 + YAJLDocument *document = [[YAJLDocument alloc] initWithData:data parserOptions:options error:error];
  74 + id root = [document.root retain];
  75 + [document release];
  76 + return [root autorelease];
77 77 }
78 78
79 79
36 Classes/YAJLDocument.h
@@ -31,9 +31,9 @@
31 31 #include "YAJLParser.h"
32 32
33 33 typedef enum {
34   - YAJLDecoderCurrentTypeNone,
35   - YAJLDecoderCurrentTypeArray,
36   - YAJLDecoderCurrentTypeDict
  34 + YAJLDecoderCurrentTypeNone,
  35 + YAJLDecoderCurrentTypeArray,
  36 + YAJLDecoderCurrentTypeDict
37 37 } YAJLDecoderCurrentType;
38 38
39 39 extern NSInteger YAJLDocumentStackCapacity;
@@ -49,22 +49,22 @@ extern NSInteger YAJLDocumentStackCapacity;
49 49 @end
50 50
51 51 @interface YAJLDocument : NSObject <YAJLParserDelegate> {
52   -
53   - id root_; // NSArray or NSDictionary
54   - YAJLParser *parser_;
55   -
  52 +
  53 + id root_; // NSArray or NSDictionary
  54 + YAJLParser *parser_;
  55 +
56 56 __weak id<YAJLDocumentDelegate> delegate_;
57   -
58   - __weak NSMutableDictionary *dict_; // weak; if map in progress, points to the current map
59   - __weak NSMutableArray *array_; // weak; If array in progress, points the current array
60   - __weak NSString *key_; // weak; If map in progress, points to current key
61   -
62   - NSMutableArray *stack_;
63   - NSMutableArray *keyStack_;
64   -
65   - YAJLDecoderCurrentType currentType_;
66   -
67   - YAJLParserStatus parserStatus_;
  57 +
  58 + __weak NSMutableDictionary *dict_; // weak; if map in progress, points to the current map
  59 + __weak NSMutableArray *array_; // weak; If array in progress, points the current array
  60 + __weak NSString *key_; // weak; If map in progress, points to current key
  61 +
  62 + NSMutableArray *stack_;
  63 + NSMutableArray *keyStack_;
  64 +
  65 + YAJLDecoderCurrentType currentType_;
  66 +
  67 + YAJLParserStatus parserStatus_;
68 68
69 69 }
70 70
142 Classes/YAJLDocument.m
@@ -46,122 +46,122 @@ - (id)init {
46 46 }
47 47
48 48 - (id)initWithParserOptions:(YAJLParserOptions)parserOptions {
49   - if ((self = [super init])) {
50   - stack_ = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
51   - keyStack_ = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
52   - parserStatus_ = YAJLParserStatusNone;
53   - parser_ = [[YAJLParser alloc] initWithParserOptions:parserOptions];
54   - parser_.delegate = self;
55   - }
56   - return self;
  49 + if ((self = [super init])) {
  50 + stack_ = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
  51 + keyStack_ = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
  52 + parserStatus_ = YAJLParserStatusNone;
  53 + parser_ = [[YAJLParser alloc] initWithParserOptions:parserOptions];
  54 + parser_.delegate = self;
  55 + }
  56 + return self;
57 57 }
58 58
59 59 - (id)initWithData:(NSData *)data parserOptions:(YAJLParserOptions)parserOptions error:(NSError **)error {
60   - if ((self = [self initWithParserOptions:parserOptions])) {
61   - [self parse:data error:error];
62   - }
63   - return self;
  60 + if ((self = [self initWithParserOptions:parserOptions])) {
  61 + [self parse:data error:error];
  62 + }
  63 + return self;
64 64 }
65 65
66 66 - (void)dealloc {
67   - [stack_ release];
68   - [keyStack_ release];
69   - parser_.delegate = nil;
70   - [parser_ release];
71   - [root_ release];
72   - [super dealloc];
  67 + [stack_ release];
  68 + [keyStack_ release];
  69 + parser_.delegate = nil;
  70 + [parser_ release];
  71 + [root_ release];
  72 + [super dealloc];
73 73 }
74 74
75 75 - (YAJLParserStatus)parse:(NSData *)data error:(NSError **)error {
76   - parserStatus_ = [parser_ parse:data];
77   - if (error) *error = [parser_ parserError];
78   - return parserStatus_;
  76 + parserStatus_ = [parser_ parse:data];
  77 + if (error) *error = [parser_ parserError];
  78 + return parserStatus_;
79 79 }
80 80
81 81 #pragma mark Delegates
82 82
83 83 - (void)parser:(YAJLParser *)parser didAdd:(id)value {
84   - switch(currentType_) {
85   - case YAJLDecoderCurrentTypeArray:
86   - [array_ addObject:value];
  84 + switch(currentType_) {
  85 + case YAJLDecoderCurrentTypeArray:
  86 + [array_ addObject:value];
87 87 if ([delegate_ respondsToSelector:@selector(document:didAddObject:toArray:)])
88 88 [delegate_ document:self didAddObject:value toArray:array_];
89   - break;
90   - case YAJLDecoderCurrentTypeDict:
91   - NSParameterAssert(key_);
92   - [dict_ setObject:value forKey:key_];
  89 + break;
  90 + case YAJLDecoderCurrentTypeDict:
  91 + NSParameterAssert(key_);
  92 + [dict_ setObject:value forKey:key_];
93 93 if ([delegate_ respondsToSelector:@selector(document:didSetObject:forKey:inDictionary:)])
94 94 [delegate_ document:self didSetObject:value forKey:key_ inDictionary:dict_];
95   - [self _popKey];
96   - break;
97   - }
  95 + [self _popKey];
  96 + break;
  97 + }
98 98 }
99 99
100 100 - (void)parser:(YAJLParser *)parser didMapKey:(NSString *)key {
101   - key_ = key;
102   - [keyStack_ addObject:key_]; // Push
  101 + key_ = key;
  102 + [keyStack_ addObject:key_]; // Push
103 103 }
104 104
105 105 - (void)_popKey {
106   - key_ = nil;
107   - [keyStack_ removeLastObject]; // Pop
108   - if ([keyStack_ count] > 0)
109   - key_ = [keyStack_ objectAtIndex:[keyStack_ count]-1];
  106 + key_ = nil;
  107 + [keyStack_ removeLastObject]; // Pop
  108 + if ([keyStack_ count] > 0)
  109 + key_ = [keyStack_ objectAtIndex:[keyStack_ count]-1];
110 110 }
111 111
112 112 - (void)parserDidStartDictionary:(YAJLParser *)parser {
113   - NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:YAJLDocumentStackCapacity];
114   - if (!root_) root_ = [dict retain];
115   - [stack_ addObject:dict]; // Push
116   - [dict release];
117   - dict_ = dict;
118   - currentType_ = YAJLDecoderCurrentTypeDict;
  113 + NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:YAJLDocumentStackCapacity];
  114 + if (!root_) root_ = [dict retain];
  115 + [stack_ addObject:dict]; // Push
  116 + [dict release];
  117 + dict_ = dict;
  118 + currentType_ = YAJLDecoderCurrentTypeDict;
119 119 }
120 120
121 121 - (void)parserDidEndDictionary:(YAJLParser *)parser {
122   - id value = [[stack_ objectAtIndex:[stack_ count]-1] retain];
  122 + id value = [[stack_ objectAtIndex:[stack_ count]-1] retain];
123 123 NSDictionary *dict = dict_;
124   - [self _pop];
125   - [self parser:parser didAdd:value];
126   - [value release];
  124 + [self _pop];
  125 + [self parser:parser didAdd:value];
  126 + [value release];
127 127 if ([delegate_ respondsToSelector:@selector(document:didAddDictionary:)])
128 128 [delegate_ document:self didAddDictionary:dict];
129 129 }
130 130
131 131 - (void)parserDidStartArray:(YAJLParser *)parser {
132   - NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
133   - if (!root_) root_ = [array retain];
134   - [stack_ addObject:array]; // Push
135   - [array release];
136   - array_ = array;
137   - currentType_ = YAJLDecoderCurrentTypeArray;
  132 + NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
  133 + if (!root_) root_ = [array retain];
  134 + [stack_ addObject:array]; // Push
  135 + [array release];
  136 + array_ = array;
  137 + currentType_ = YAJLDecoderCurrentTypeArray;
138 138 }
139 139
140 140 - (void)parserDidEndArray:(YAJLParser *)parser {
141   - id value = [[stack_ objectAtIndex:[stack_ count]-1] retain];
  141 + id value = [[stack_ objectAtIndex:[stack_ count]-1] retain];
142 142 NSArray *array = array_;
143   - [self _pop];
144   - [self parser:parser didAdd:value];
145   - [value release];
  143 + [self _pop];
  144 + [self parser:parser didAdd:value];
  145 + [value release];
146 146 if ([delegate_ respondsToSelector:@selector(document:didAddArray:)])
147 147 [delegate_ document:self didAddArray:array];
148 148 }
149 149
150 150 - (void)_pop {
151   - [stack_ removeLastObject];
152   - array_ = nil;
153   - dict_ = nil;
154   - currentType_ = YAJLDecoderCurrentTypeNone;
155   -
156   - id value = nil;
157   - if ([stack_ count] > 0) value = [stack_ objectAtIndex:[stack_ count]-1];
158   - if ([value isKindOfClass:[NSArray class]]) {
159   - array_ = (NSMutableArray *)value;
160   - currentType_ = YAJLDecoderCurrentTypeArray;
161   - } else if ([value isKindOfClass:[NSDictionary class]]) {
162   - dict_ = (NSMutableDictionary *)value;
163   - currentType_ = YAJLDecoderCurrentTypeDict;
164   - }
  151 + [stack_ removeLastObject];
  152 + array_ = nil;
  153 + dict_ = nil;
  154 + currentType_ = YAJLDecoderCurrentTypeNone;
  155 +
  156 + id value = nil;
  157 + if ([stack_ count] > 0) value = [stack_ objectAtIndex:[stack_ count]-1];
  158 + if ([value isKindOfClass:[NSArray class]]) {
  159 + array_ = (NSMutableArray *)value;
  160 + currentType_ = YAJLDecoderCurrentTypeArray;
  161 + } else if ([value isKindOfClass:[NSDictionary class]]) {
  162 + dict_ = (NSMutableDictionary *)value;
  163 + currentType_ = YAJLDecoderCurrentTypeDict;
  164 + }
165 165 }
166 166
167 167 @end
6 Classes/YAJLGen.h
@@ -36,8 +36,8 @@ extern NSString *const YAJLGenInvalidObjectException;
36 36 @constant YAJLGenOptionsBeautify
37 37 */
38 38 enum {
39   - YAJLGenOptionsNone = 0,
40   - YAJLGenOptionsBeautify = 1 << 0,
  39 + YAJLGenOptionsNone = 0,
  40 + YAJLGenOptionsBeautify = 1 << 0,
41 41 YAJLGenOptionsIgnoreUnknownTypes = 1 << 1, // Ignore unknown types (will use null value)
42 42 YAJLGenOptionsIncludeUnsupportedTypes = 1 << 2, // Handle non-JSON types (including NSDate, NSData, NSURL)
43 43 };
@@ -59,7 +59,7 @@ typedef NSUInteger YAJLGenOptions;
59 59 - NSURL -> URL (absolute) string
60 60 */
61 61 @interface YAJLGen : NSObject {
62   - yajl_gen gen_;
  62 + yajl_gen gen_;
63 63
64 64 YAJLGenOptions genOptions_;
65 65 }
118 Classes/YAJLGen.m
@@ -35,52 +35,52 @@
35 35 @implementation YAJLGen
36 36
37 37 - (id)init {
38   - return [self initWithGenOptions:YAJLGenOptionsNone indentString:@""];
  38 + return [self initWithGenOptions:YAJLGenOptionsNone indentString:@""];
39 39 }
40 40
41 41 - (id)initWithGenOptions:(YAJLGenOptions)genOptions indentString:(NSString *)indentString {
42   - if ((self = [super init])) {
  42 + if ((self = [super init])) {
43 43 genOptions_ = genOptions;
44   - yajl_gen_config cfg = {
45   - ((genOptions & YAJLGenOptionsBeautify) ? 1 : 0),
46   - [indentString UTF8String]
47   - };
48   - gen_ = yajl_gen_alloc(&cfg, NULL);
49   - }
50   - return self;
  44 + yajl_gen_config cfg = {
  45 + ((genOptions & YAJLGenOptionsBeautify) ? 1 : 0),
  46 + [indentString UTF8String]
  47 + };
  48 + gen_ = yajl_gen_alloc(&cfg, NULL);
  49 + }
  50 + return self;
51 51 }
52 52
53   -- (void)dealloc {
54   - if (gen_ != NULL) yajl_gen_free(gen_);
55   - [super dealloc];
  53 +- (void)dealloc {
  54 + if (gen_ != NULL) yajl_gen_free(gen_);
  55 + [super dealloc];
56 56 }
57 57
58   -- (void)object:(id)obj {
59   - if ([obj respondsToSelector:@selector(JSON)]) {
60   - return [self object:[obj JSON]];
61   - } else if ([obj isKindOfClass:[NSArray class]]) {
62   - [self startArray];
63   - for(id element in obj)
64   - [self object:element];
65   - [self endArray];
66   - } else if ([obj isKindOfClass:[NSDictionary class]]) {
67   - [self startDictionary];
68   - for(id key in obj) {
69   - [self object:key];
70   - [self object:[obj objectForKey:key]];
71   - }
72   - [self endDictionary];
73   - } else if ([obj isKindOfClass:[NSNumber class]]) {
74   - if ('c' != *[obj objCType]) {
75   - [self number:obj];
76   - } else {
77   - [self bool:[obj boolValue]];
78   - }
79   - } else if ([obj isKindOfClass:[NSString class]]) {
80   - [self string:obj];
81   - } else if ([obj isKindOfClass:[NSNull class]]) {
82   - [self null];
83   - } else {
  58 +- (void)object:(id)obj {
  59 + if ([obj respondsToSelector:@selector(JSON)]) {
  60 + return [self object:[obj JSON]];
  61 + } else if ([obj isKindOfClass:[NSArray class]]) {
  62 + [self startArray];
  63 + for(id element in obj)
  64 + [self object:element];
  65 + [self endArray];
  66 + } else if ([obj isKindOfClass:[NSDictionary class]]) {
  67 + [self startDictionary];
  68 + for(id key in obj) {
  69 + [self object:key];
  70 + [self object:[obj objectForKey:key]];
  71 + }
  72 + [self endDictionary];
  73 + } else if ([obj isKindOfClass:[NSNumber class]]) {
  74 + if ('c' != *[obj objCType]) {
  75 + [self number:obj];
  76 + } else {
  77 + [self bool:[obj boolValue]];
  78 + }
  79 + } else if ([obj isKindOfClass:[NSString class]]) {
  80 + [self string:obj];
  81 + } else if ([obj isKindOfClass:[NSNull class]]) {
  82 + [self null];
  83 + } else {
84 84
85 85 BOOL unknownType = NO;
86 86 if (genOptions_ & YAJLGenOptionsIncludeUnsupportedTypes) {
@@ -106,57 +106,57 @@ - (void)object:(id)obj {
106 106 [self null]; // Use null value for unknown type if we are ignoring
107 107 }
108 108 }
109   - }
  109 + }
110 110 }
111 111
112 112 - (void)null {
113   - yajl_gen_null(gen_);
  113 + yajl_gen_null(gen_);
114 114 }
115 115
116 116 - (void)bool:(BOOL)b {
117   - yajl_gen_bool(gen_, b);
  117 + yajl_gen_bool(gen_, b);
118 118 }
119 119
120 120 - (void)number:(NSNumber *)number {
121   - NSString *s = [number stringValue];
122   - unsigned int length = [s lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
123   - const char *c = [s UTF8String];
124   - yajl_gen_number(gen_, c, length);
  121 + NSString *s = [number stringValue];
  122 + unsigned int length = [s lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
  123 + const char *c = [s UTF8String];
  124 + yajl_gen_number(gen_, c, length);
125 125 }
126 126
127 127 - (void)string:(NSString *)s {
128   - unsigned int length = [s lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
129   - const unsigned char *c = (const unsigned char *)[s UTF8String];
130   - yajl_gen_string(gen_, c, length);
  128 + unsigned int length = [s lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
  129 + const unsigned char *c = (const unsigned char *)[s UTF8String];
  130 + yajl_gen_string(gen_, c, length);
131 131 }
132 132
133 133 - (void)startDictionary {
134   - yajl_gen_map_open(gen_);
  134 + yajl_gen_map_open(gen_);
135 135 }
136 136
137 137 - (void)endDictionary {
138   - yajl_gen_map_close(gen_);
  138 + yajl_gen_map_close(gen_);
139 139 }
140 140
141 141 - (void)startArray {
142   - yajl_gen_array_open(gen_);
  142 + yajl_gen_array_open(gen_);
143 143 }
144 144
145 145 - (void)endArray {
146   - yajl_gen_array_close(gen_);
  146 + yajl_gen_array_close(gen_);
147 147 }
148 148
149 149 - (void)clear {
150   - yajl_gen_clear(gen_);
  150 + yajl_gen_clear(gen_);
151 151 }
152 152
153 153 - (NSString *)buffer {
154   - const unsigned char *buf;
155   - unsigned int len;
156   - yajl_gen_get_buf(gen_, &buf, &len);
157   - NSString *s = [NSString stringWithUTF8String:(const char*)buf];
158   - return s;
159   -}
  154 + const unsigned char *buf;
  155 + unsigned int len;
  156 + yajl_gen_get_buf(gen_, &buf, &len);
  157 + NSString *s = [NSString stringWithUTF8String:(const char*)buf];
  158 + return s;
  159 +}
160 160
161 161 @end
162 162
30 Classes/YAJLParser.h
@@ -55,18 +55,18 @@ typedef enum {
55 55 @constant YAJLParserOptionsCheckUTF8 Invalid UTF8 strings will cause a parse error
56 56 */
57 57 enum {
58   - YAJLParserOptionsNone = 0,
59   - YAJLParserOptionsAllowComments = 1 << 0, // Allows comments in JSON
60   - YAJLParserOptionsCheckUTF8 = 1 << 1, // If YES will verify UTF-8
  58 + YAJLParserOptionsNone = 0,
  59 + YAJLParserOptionsAllowComments = 1 << 0, // Allows comments in JSON
  60 + YAJLParserOptionsCheckUTF8 = 1 << 1, // If YES will verify UTF-8
61 61 YAJLParserOptionsStrictPrecision = 1 << 2, // If YES will force strict precision and return integer overflow error
62 62 };
63 63 typedef NSUInteger YAJLParserOptions;
64 64
65 65 enum {
66   - YAJLParserStatusNone = 0,
67   - YAJLParserStatusOK = 1,
68   - YAJLParserStatusInsufficientData = 2,
69   - YAJLParserStatusError = 3
  66 + YAJLParserStatusNone = 0,
  67 + YAJLParserStatusOK = 1,
  68 + YAJLParserStatusInsufficientData = 2,
  69 + YAJLParserStatusError = 3
70 70 };
71 71 typedef NSUInteger YAJLParserStatus;
72 72
@@ -95,14 +95,14 @@ typedef NSUInteger YAJLParserStatus;
95 95
96 96
97 97 @interface YAJLParser : NSObject {
98   -
99   - yajl_handle handle_;
100   -
101   - id <YAJLParserDelegate> delegate_; // weak
102   -
103   - YAJLParserOptions parserOptions_;
104   -
105   - NSError *parserError_;
  98 +
  99 + yajl_handle handle_;
  100 +
  101 + id <YAJLParserDelegate> delegate_; // weak
  102 +
  103 + YAJLParserOptions parserOptions_;
  104 +
  105 + NSError *parserError_;
106 106 }
107 107
108 108 @property (assign, nonatomic) id <YAJLParserDelegate> delegate;
190 Classes/YAJLParser.m
@@ -65,46 +65,46 @@ - (id)init {
65 65 }
66 66
67 67 - (id)initWithParserOptions:(YAJLParserOptions)parserOptions {
68   - if ((self = [super init])) {
69   - parserOptions_ = parserOptions;
70   - }
71   - return self;
  68 + if ((self = [super init])) {
  69 + parserOptions_ = parserOptions;
  70 + }
  71 + return self;
72 72 }
73 73
74 74 - (void)dealloc {
75   - if (handle_ != NULL) {
76   - yajl_free(handle_);
77   - handle_ = NULL;
78   - }
79   -
80   - [parserError_ release];
81   - [super dealloc];
  75 + if (handle_ != NULL) {
  76 + yajl_free(handle_);
  77 + handle_ = NULL;
  78 + }
  79 +
  80 + [parserError_ release];
  81 + [super dealloc];
82 82 }
83 83
84 84 #pragma mark Error Helpers
85 85
86 86 - (NSError *)_errorForStatus:(NSInteger)code message:(NSString *)message value:(NSString *)value {
87   - NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:message forKey:NSLocalizedDescriptionKey];
  87 + NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:message forKey:NSLocalizedDescriptionKey];
88 88 if (value) [userInfo setObject:value forKey:YAJLParserValueKey];
89   - return [NSError errorWithDomain:YAJLErrorDomain code:code userInfo:userInfo];
  89 + return [NSError errorWithDomain:YAJLErrorDomain code:code userInfo:userInfo];
90 90 }
91 91
92 92 - (void)_cancelWithErrorForStatus:(NSInteger)code message:(NSString *)message value:(NSString *)value {
93   - self.parserError = [self _errorForStatus:code message:message value:value];
  93 + self.parserError = [self _errorForStatus:code message:message value:value];
94 94 }
95 95
96 96 #pragma mark YAJL Callbacks
97 97
98 98 int yajl_null(void *ctx) {
99   - [(id)ctx _add:[NSNull null]];
100   - return 1;
  99 + [(id)ctx _add:[NSNull null]];
  100 + return 1;
101 101 }
102 102
103 103 int yajl_boolean(void *ctx, int boolVal) {
104   - NSNumber *number = [[NSNumber alloc] initWithBool:(BOOL)boolVal];
105   - [(id)ctx _add:number];
106   - [number release];
107   - return 1;
  104 + NSNumber *number = [[NSNumber alloc] initWithBool:(BOOL)boolVal];
  105 + [(id)ctx _add:number];
  106 + [number release];
  107 + return 1;
108 108 }
109 109
110 110 // Instead of using yajl_integer, and yajl_double we use yajl_number and parse
@@ -113,13 +113,13 @@ int yajl_boolean(void *ctx, int boolVal) {
113 113 // and is up to the parser?
114 114
115 115 //int yajl_integer(void *ctx, long integerVal) {
116   -// [(id)ctx _add:[NSNumber numberWithLong:integerVal]];
117   -// return 1;
  116 +// [(id)ctx _add:[NSNumber numberWithLong:integerVal]];
  117 +// return 1;
118 118 //}
119 119 //
120 120 //int yajl_double(void *ctx, double doubleVal) {
121   -// [(id)ctx _add:[NSNumber numberWithDouble:doubleVal]];
122   -// return 1;
  121 +// [(id)ctx _add:[NSNumber numberWithDouble:doubleVal]];
  122 +// return 1;
123 123 //}
124 124
125 125 int ParseDouble(void *ctx, const char *buf, const char *numberVal, unsigned int numberLen) {
@@ -137,15 +137,15 @@ int ParseDouble(void *ctx, const char *buf, const char *numberVal, unsigned int
137 137 }
138 138
139 139 int yajl_number(void *ctx, const char *numberVal, unsigned int numberLen) {
140   - char buf[numberLen+1];
141   - memcpy(buf, numberVal, numberLen);
142   - buf[numberLen] = 0;
143   -
144   - if (memchr(numberVal, '.', numberLen) || memchr(numberVal, 'e', numberLen) || memchr(numberVal, 'E', numberLen)) {
  140 + char buf[numberLen+1];
  141 + memcpy(buf, numberVal, numberLen);
  142 + buf[numberLen] = 0;
  143 +
  144 + if (memchr(numberVal, '.', numberLen) || memchr(numberVal, 'e', numberLen) || memchr(numberVal, 'E', numberLen)) {
145 145 return ParseDouble(ctx, buf, numberVal, numberLen);
146   - } else {
147   - long long i = strtoll((const char *) buf, NULL, 10);
148   - if ((i == LLONG_MIN || i == LLONG_MAX) && errno == ERANGE) {
  146 + } else {
  147 + long long i = strtoll((const char *) buf, NULL, 10);
  148 + if ((i == LLONG_MIN || i == LLONG_MAX) && errno == ERANGE) {
149 149 if (([(id)ctx parserOptions] & YAJLParserOptionsStrictPrecision) == YAJLParserOptionsStrictPrecision) {
150 150 NSString *s = [[NSString alloc] initWithBytes:numberVal length:numberLen encoding:NSUTF8StringEncoding];
151 151 [(id)ctx _cancelWithErrorForStatus:YAJLParserErrorCodeIntegerOverflow message:[NSString stringWithFormat:@"integer overflow on '%@'", s] value:s];
@@ -155,47 +155,47 @@ int yajl_number(void *ctx, const char *numberVal, unsigned int numberLen) {
155 155 // If we integer overflow lets try double precision for HUGE_VAL > double > LLONG_MAX
156 156 return ParseDouble(ctx, buf, numberVal, numberLen);
157 157 }
158   - }
159   - NSNumber *number = [[NSNumber alloc] initWithLongLong:i];
160   - [(id)ctx _add:number];
161   - [number release];
162   - }
163   -
164   - return 1;
  158 + }
  159 + NSNumber *number = [[NSNumber alloc] initWithLongLong:i];
  160 + [(id)ctx _add:number];
  161 + [number release];
  162 + }
  163 +
  164 + return 1;
165 165 }
166 166
167 167 int yajl_string(void *ctx, const unsigned char *stringVal, unsigned int stringLen) {
168   - NSString *s = [[NSString alloc] initWithBytes:stringVal length:stringLen encoding:NSUTF8StringEncoding];
169   - [(id)ctx _add:s];
170   - [s release];
171   - return 1;
  168 + NSString *s = [[NSString alloc] initWithBytes:stringVal length:stringLen encoding:NSUTF8StringEncoding];
  169 + [(id)ctx _add:s];
  170 + [s release];
  171 + return 1;
172 172 }
173 173
174 174 int yajl_map_key(void *ctx, const unsigned char *stringVal, unsigned int stringLen) {
175   - NSString *s = [[NSString alloc] initWithBytes:stringVal length:stringLen encoding:NSUTF8StringEncoding];
176   - [(id)ctx _mapKey:s];
177   - [s release];
178   - return 1;
  175 + NSString *s = [[NSString alloc] initWithBytes:stringVal length:stringLen encoding:NSUTF8StringEncoding];
  176 + [(id)ctx _mapKey:s];
  177 + [s release];
  178 + return 1;
179 179 }
180 180
181 181 int yajl_start_map(void *ctx) {
182   - [(id)ctx _startDictionary];
183   - return 1;
  182 + [(id)ctx _startDictionary];
  183 + return 1;
184 184 }
185 185
186 186 int yajl_end_map(void *ctx) {
187   - [(id)ctx _endDictionary];
188   - return 1;
  187 + [(id)ctx _endDictionary];
  188 + return 1;
189 189 }
190 190
191 191 int yajl_start_array(void *ctx) {
192   - [(id)ctx _startArray];
193   - return 1;
  192 + [(id)ctx _startArray];
  193 + return 1;
194 194 }
195 195
196 196 int yajl_end_array(void *ctx) {
197   - [(id)ctx _endArray];
198   - return 1;
  197 + [(id)ctx _endArray];
  198 + return 1;
199 199 }
200 200
201 201 static yajl_callbacks callbacks = {
@@ -215,63 +215,63 @@ int yajl_end_array(void *ctx) {
215 215 #pragma mark -
216 216
217 217 - (void)_add:(id)value {
218   - [delegate_ parser:self didAdd:value];
  218 + [delegate_ parser:self didAdd:value];
219 219 }
220 220
221 221 - (void)_mapKey:(NSString *)key {
222   - [delegate_ parser:self didMapKey:key];
  222 + [delegate_ parser:self didMapKey:key];
223 223 }
224 224
225 225 - (void)_startDictionary {
226   - [delegate_ parserDidStartDictionary:self];
  226 + [delegate_ parserDidStartDictionary:self];
227 227 }
228 228
229 229 - (void)_endDictionary {
230   - [delegate_ parserDidEndDictionary:self];
  230 + [delegate_ parserDidEndDictionary:self];
231 231 }
232 232
233   -- (void)_startArray {
234   - [delegate_ parserDidStartArray:self];
  233 +- (void)_startArray {
  234 + [delegate_ parserDidStartArray:self];
235 235 }
236 236
237 237 - (void)_endArray {
238   - [delegate_ parserDidEndArray:self];
  238 + [delegate_ parserDidEndArray:self];
239 239 }
240 240
241 241 - (YAJLParserStatus)parse:(NSData *)data {
242   - if (!handle_) {
243   - yajl_parser_config cfg = {
244   - ((parserOptions_ & YAJLParserOptionsAllowComments) ? 1 : 0), // allowComments: if nonzero, javascript style comments will be allowed in the input (both /* */ and //)
245   - ((parserOptions_ & YAJLParserOptionsCheckUTF8) ? 1 : 0) // checkUTF8: if nonzero, invalid UTF8 strings will cause a parse error
246   - };
247   -
248   - handle_ = yajl_alloc(&callbacks, &cfg, NULL, self);
249   - if (!handle_) {
250   - self.parserError = [self _errorForStatus:YAJLParserErrorCodeAllocError message:@"Unable to allocate YAJL handle" value:nil];
251   - return YAJLParserStatusError;
252   - }
253   - }
254   -
255   - yajl_status status = yajl_parse(handle_, [data bytes], [data length]);
256   - if (status == yajl_status_client_canceled) {
257   - // We cancelled because we encountered an error here in the client;
258   - // and parserError should be already set
259   - NSAssert(self.parserError, @"Client cancelled, but we have no parserError set");
260   - return YAJLParserStatusError;
261   - } else if (status == yajl_status_error) {
262   - unsigned char *errorMessage = yajl_get_error(handle_, 1, [data bytes], [data length]);
263   - NSString *errorString = [NSString stringWithUTF8String:(char *)errorMessage];
264   - self.parserError = [self _errorForStatus:status message:errorString value:nil];
265   - yajl_free_error(handle_, errorMessage);
266   - return YAJLParserStatusError;
267   - } else if (status == yajl_status_insufficient_data) {
268   - return YAJLParserStatusInsufficientData;
269   - } else if (status == yajl_status_ok) {
270   - return YAJLParserStatusOK;
271   - } else {
272   - self.parserError = [self _errorForStatus:status message:[NSString stringWithFormat:@"Unexpected status %d", status] value:nil];
273   - return YAJLParserStatusError;
274   - }
  242 + if (!handle_) {
  243 + yajl_parser_config cfg = {
  244 + ((parserOptions_ & YAJLParserOptionsAllowComments) ? 1 : 0), // allowComments: if nonzero, javascript style comments will be allowed in the input (both /* */ and //)
  245 + ((parserOptions_ & YAJLParserOptionsCheckUTF8) ? 1 : 0) // checkUTF8: if nonzero, invalid UTF8 strings will cause a parse error
  246 + };
  247 +
  248 + handle_ = yajl_alloc(&callbacks, &cfg, NULL, self);
  249 + if (!handle_) {
  250 + self.parserError = [self _errorForStatus:YAJLParserErrorCodeAllocError message:@"Unable to allocate YAJL handle" value:nil];
  251 + return YAJLParserStatusError;
  252 + }
  253 + }
  254 +
  255 + yajl_status status = yajl_parse(handle_, [data bytes], [data length]);
  256 + if (status == yajl_status_client_canceled) {
  257 + // We cancelled because we encountered an error here in the client;
  258 + // and parserError should be already set
  259 + NSAssert(self.parserError, @"Client cancelled, but we have no parserError set");
  260 + return YAJLParserStatusError;
  261 + } else if (status == yajl_status_error) {
  262 + unsigned char *errorMessage = yajl_get_error(handle_, 1, [data bytes], [data length]);
  263 + NSString *errorString = [NSString stringWithUTF8String:(char *)errorMessage];
  264 + self.parserError = [self _errorForStatus:status message:errorString value:nil];
  265 + yajl_free_error(handle_, errorMessage);
  266 + return YAJLParserStatusError;
  267 + } else if (status == yajl_status_insufficient_data) {
  268 + return YAJLParserStatusInsufficientData;
  269 + } else if (status == yajl_status_ok) {
  270 + return YAJLParserStatusOK;
  271 + } else {
  272 + self.parserError = [self _errorForStatus:status message:[NSString stringWithFormat:@"Unexpected status %d", status] value:nil];
  273 + return YAJLParserStatusError;
  274 + }
275 275 }
276 276
277 277 @end
4 SBJSON/NSString+SBJSON.m
@@ -57,7 +57,7 @@ - (id)JSONValueWithOptions:(NSDictionary *)opts
57 57
58 58 [NSException raise:@"enojson"
59 59 format:@"Failed to parse '%@' as JSON", self];
60   - return nil;
  60 + return nil;
61 61 }
62 62
63 63 - (id)JSONFragmentValue
@@ -73,7 +73,7 @@ - (id)JSONFragmentValue
73 73
74 74 [NSException raise:@"enofragment"
75 75 format:@"Failed to parse '%@' as a JSON fragment", self];
76   - return nil;
  76 + return nil;
77 77 }
78 78
79 79 @end
4 SBJSON/SBJSONScanner.m
@@ -214,7 +214,7 @@ - (BOOL)scanRestOfArray:(NSMutableArray **)o
214 214 } while (*c == ',' && c++);
215 215
216 216 [self raise:enocomma format:@"Expected , or ] while parsing array"];
217   - return NO; // got rid of compiler warning
  217 + return NO; // got rid of compiler warning
218 218 }
219 219
220 220 - (BOOL)scanDictionary:(NSDictionary **)o
@@ -265,7 +265,7 @@ - (BOOL)scanRestOfDictionary:(NSMutableDictionary **)o
265 265 } while (*c == ',' && c++);
266 266
267 267 [self raise:enocomma format:@"Expected , or } while parsing dictionary"];
268   - return NO; // JAE just got rid of compiler warning.
  268 + return NO; // JAE just got rid of compiler warning.
269 269 }
270 270
271 271 - (BOOL)scanRestOfString:(NSMutableString **)o
18 Tests/NSDataTest.m
@@ -16,15 +16,15 @@ @interface NSDataTest : YAJLTestCase
16 16 @implementation NSDataTest
17 17
18 18 - (void)testExample {
19   - NSData *data = [[self loadString:@"example"] dataUsingEncoding:NSUTF8StringEncoding];
20   - id JSON = [data yajl_JSON];
21   - GHTestLog([JSON description]);
22   -
23   - GHAssertTrue([JSON isKindOfClass:[NSDictionary class]], nil);
24   - NSDictionary *glossary = [JSON objectForKey:@"glossary"];
25   - GHAssertNotNil(glossary, nil);
26   - NSString *title = [glossary objectForKey:@"title"];
27   - GHAssertEqualStrings(title, @"example glossary", nil);
  19 + NSData *data = [[self loadString:@"example"] dataUsingEncoding:NSUTF8StringEncoding];
  20 + id JSON = [data yajl_JSON];
  21 + GHTestLog([JSON description]);
  22 +
  23 + GHAssertTrue([JSON isKindOfClass:[NSDictionary class]], nil);
  24 + NSDictionary *glossary = [JSON objectForKey:@"glossary"];
  25 + GHAssertNotNil(glossary, nil);
  26 + NSString *title = [glossary objectForKey:@"title"];
  27 + GHAssertEqualStrings(title, @"example glossary", nil);
28 28 }
29 29
30 30 @end
48 Tests/NSObjectTest.m
@@ -19,35 +19,35 @@ @interface CustomJSONObject : NSObject
19 19 @implementation NSObjectTest
20 20
21 21 - (void)testDictionary {
22   - NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
23   - [NSArray arrayWithObjects:@"arrayValue1", [NSNumber numberWithBool:YES], [NSNumber numberWithBool:NO], [NSNull null],
24   - [NSNumber numberWithInteger:1], [NSNumber numberWithDouble:234234.234234], nil], @"key2",
25   - nil];
26   -
27   - NSString *JSONString = [dict yajl_JSONStringWithOptions:YAJLGenOptionsBeautify indentString:@" "];
28   -
29   - NSString *expected = [self loadString:@"gen_expected1"];
30   - GHTestLog(JSONString);
31   - GHAssertEqualStrings(JSONString, expected, nil);
  22 + NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
  23 + [NSArray arrayWithObjects:@"arrayValue1", [NSNumber numberWithBool:YES], [NSNumber numberWithBool:NO], [NSNull null],
  24 + [NSNumber numberWithInteger:1], [NSNumber numberWithDouble:234234.234234], nil], @"key2",
  25 + nil];
  26 +
  27 + NSString *JSONString = [dict yajl_JSONStringWithOptions:YAJLGenOptionsBeautify indentString:@" "];
  28 +
  29 + NSString *expected = [self loadString:@"gen_expected1"];
  30 + GHTestLog(JSONString);
  31 + GHAssertEqualStrings(JSONString, expected, nil);
32 32 }
33 33
34 34 - (void)testArray {
35   - NSArray *array = [NSArray arrayWithObjects:@"arrayValue1", [NSNumber numberWithBool:YES], [NSNumber numberWithBool:NO], [NSNull null],
36   - [NSNumber numberWithInteger:1], [NSNumber numberWithDouble:234234.234234], nil];
37   -
38   - NSString *JSONString = [array yajl_JSONStringWithOptions:YAJLGenOptionsBeautify indentString:@" "];
39   -
40   - NSString *expected = [self loadString:@"object_expected_array"];
41   - GHTestLog(JSONString);
42   - GHAssertEqualStrings(JSONString, expected, nil);
  35 + NSArray *array = [NSArray arrayWithObjects:@"arrayValue1", [NSNumber numberWithBool:YES], [NSNumber numberWithBool:NO], [NSNull null],
  36 + [NSNumber numberWithInteger:1], [NSNumber numberWithDouble:234234.234234], nil];
  37 +
  38 + NSString *JSONString = [array yajl_JSONStringWithOptions:YAJLGenOptionsBeautify indentString:@" "];
  39 +
  40 + NSString *expected = [self loadString:@"object_expected_array"];
  41 + GHTestLog(JSONString);
  42 + GHAssertEqualStrings(JSONString, expected, nil);
43 43 }
44 44
45 45 - (void)testCustom {
46   - CustomJSONObject *obj = [[[CustomJSONObject alloc] init] autorelease];
47   - NSString *JSONString = [obj yajl_JSONString];
48   - NSString *expected = @"[\"Test\"]";
49   - GHTestLog(JSONString);
50   - GHAssertEqualStrings(JSONString, expected, nil);
  46 + CustomJSONObject *obj = [[[CustomJSONObject alloc] init] autorelease];
  47 + NSString *JSONString = [obj yajl_JSONString];
  48 + NSString *expected = @"[\"Test\"]";
  49 + GHTestLog(JSONString);
  50 + GHAssertEqualStrings(JSONString, expected, nil);
51 51 }
52 52
53 53 - (void)testComments {
@@ -80,7 +80,7 @@ - (void)testPrecision {
80 80 @implementation CustomJSONObject
81 81
82 82 - (id)JSON {
83   - return [NSArray arrayWithObject:@"Test"];
  83 + return [NSArray arrayWithObject:@"Test"];
84 84 }
85 85
86 86 @end
20 Tests/NSStringTest.m
@@ -16,16 +16,16 @@ @interface NSStringTest : YAJLTestCase
16 16 @implementation NSStringTest
17 17
18 18 - (void)testExample {
19   - NSString *exampleString = [self loadString:@"example"];
20   - GHTestLog(@"Example string: %@", exampleString);
21   - id JSON = [exampleString yajl_JSON];
22   - GHTestLog([JSON description]);
23   -
24   - GHAssertTrue([JSON isKindOfClass:[NSDictionary class]], nil);
25   - NSDictionary *glossary = [JSON objectForKey:@"glossary"];
26   - GHAssertNotNil(glossary, nil);
27   - NSString *title = [glossary objectForKey:@"title"];
28   - GHAssertEqualStrings(title, @"example glossary", nil);
  19 + NSString *exampleString = [self loadString:@"example"];
  20 + GHTestLog(@"Example string: %@", exampleString);
  21 + id JSON = [exampleString yajl_JSON];
  22 + GHTestLog([JSON description]);
  23 +
  24 + GHAssertTrue([JSON isKindOfClass:[NSDictionary class]], nil);
  25 + NSDictionary *glossary = [JSON objectForKey:@"glossary"];
  26 + GHAssertNotNil(glossary, nil);
  27 + NSString *title = [glossary objectForKey:@"title"];
  28 + GHAssertEqualStrings(title, @"example glossary", nil);
29 29 }
30 30
31 31 @end
60 Tests/PerfTest.m
@@ -16,39 +16,39 @@ @implementation PerfTest
16 16 #define kPerfTestCount 200
17 17
18 18 - (void)_testYAJLParser {
19   - NSString *examplePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"json"];
20   - NSData *data = [[NSData dataWithContentsOfFile:examplePath options:NSUncachedRead error:nil] retain];
21   -
22   - NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
23   - for(NSInteger i = 0; i < kPerfTestCount; i++) {
24   - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
25   - YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:YAJLParserOptionsNone];
26   - if (![parser parse:data]) GHFail(@"Failed to parse: %@", parser.parserError);
27   - [parser release];
28   - [pool release];
29   - }
30   - NSTimeInterval took = [NSDate timeIntervalSinceReferenceDate] - start;
31   - GHTestLog(@"Took %0.4f sec", took);
32   - [data release];
  19 + NSString *examplePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"json"];
  20 + NSData *data = [[NSData dataWithContentsOfFile:examplePath options:NSUncachedRead error:nil] retain];
  21 +
  22 + NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
  23 + for(NSInteger i = 0; i < kPerfTestCount; i++) {
  24 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  25 + YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:YAJLParserOptionsNone];
  26 + if (![parser parse:data]) GHFail(@"Failed to parse: %@", parser.parserError);
  27 + [parser release];
  28 + [pool release];
  29 + }
  30 + NSTimeInterval took = [NSDate timeIntervalSinceReferenceDate] - start;
  31 + GHTestLog(@"Took %0.4f sec", took);
  32 + [data release];
33 33 }
34 34
35 35 - (void)_testSBJSON {
36   - NSString *examplePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"json"];
37   - NSData *testData = [NSData dataWithContentsOfFile:examplePath options:NSUncachedRead error:nil];
38   - NSString *testString = [[NSString alloc] initWithData:testData encoding:NSUTF8StringEncoding];
39   -
40   - NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
41   - for(NSInteger i = 0; i < kPerfTestCount; i++) {
42   - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
43   - id value = [testString JSONValue];
44   - if (!value) GHFail(@"No result");
45   - [pool release];
46   - }
47   - NSTimeInterval took = [NSDate timeIntervalSinceReferenceDate] - start;
48   - GHTestLog(@"Took %0.4f", took);
49   -
50   - [testString release];
51   -
  36 + NSString *examplePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"json"];
  37 + NSData *testData = [NSData dataWithContentsOfFile:examplePath options:NSUncachedRead error:nil];
  38 + NSString *testString = [[NSString alloc] initWithData:testData encoding:NSUTF8StringEncoding];
  39 +
  40 + NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
  41 + for(NSInteger i = 0; i < kPerfTestCount; i++) {
  42 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  43 + id value = [testString JSONValue];
  44 + if (!value) GHFail(@"No result");
  45 + [pool release];
  46 + }
  47 + NSTimeInterval took = [NSDate timeIntervalSinceReferenceDate] - start;
  48 + GHTestLog(@"Took %0.4f", took);
  49 +
  50 + [testString release];
  51 +
52 52 }
53 53
54 54 @end
10 Tests/TwitterTest.m
@@ -17,12 +17,12 @@ @implementation TwitterTest
17 17
18 18 - (void)testCoordinates {
19 19 NSString *twitterJSONString = [self loadString:@"twitter"];
20   - id JSON = [twitterJSONString yajl_JSON];
21   - GHTestLog([JSON description]);
  20 + id JSON = [twitterJSONString yajl_JSON];
  21 + GHTestLog([JSON description]);
22 22
23   - GHAssertTrue([JSON isKindOfClass:[NSDictionary class]], nil);
24   - NSDictionary *geo = [JSON objectForKey:@"geo"];
25   - GHAssertNotNil(geo, nil);
  23 + GHAssertTrue([JSON isKindOfClass:[NSDictionary class]], nil);
  24 + NSDictionary *geo = [JSON objectForKey:@"geo"];
  25 + GHAssertNotNil(geo, nil);
26 26 NSArray *coordinates = [geo objectForKey:@"coordinates"];
27 27 NSNumber *coord1 = [coordinates objectAtIndex:0];
28 28 NSNumber *coord2 = [coordinates objectAtIndex:1];
94 Tests/YAJLDocumentTest.m
@@ -19,30 +19,30 @@ - (YAJLDocument *)_loadDocument:(NSString *)sampleName parserOptions:(YAJLParser
19 19 return document;
20 20 }
21 21
22   -- (void)test {
23   - NSError *error = nil;
  22 +- (void)test {
  23 + NSError *error = nil;
24 24 YAJLDocument *document = [self _loadDocument:@"example" parserOptions:0 error:&error];
25   - if (error) GHFail(@"Error: %@", error);
26   - GHTestLog(@"Root: %@", document.root);
  25 + if (error) GHFail(@"Error: %@", error);
  26 + GHTestLog(@"Root: %@", document.root);
27 27 }
28 28
29 29 - (void)testStreaming {
30   - YAJLDocument *document = [[YAJLDocument alloc] init];
  30 + YAJLDocument *document = [[YAJLDocument alloc] init];
31 31
32   - NSError *error = nil;
33   - NSData *data1 = [self loadData:@"stream_array1"];
34   - YAJLParserStatus status1 = [document parse:data1 error:&error];
35   - GHAssertTrue(status1 == YAJLParserStatusInsufficientData, nil);
36   - if (error) GHFail(@"Error: %@", error);
37   - GHTestLog(@"First part: %@", document.root);
38   -
39   - NSData *data2 = [self loadData:@"stream_array2"];
40   - YAJLParserStatus status2 = [document parse:data2 error:&error];
41   - GHAssertTrue(status2 == YAJLParserStatusOK, nil);
42   - if (error) GHFail(@"Error: %@", error);
  32 + NSError *error = nil;
  33 + NSData *data1 = [self loadData:@"stream_array1"];
  34 + YAJLParserStatus status1 = [document parse:data1 error:&error];
  35 + GHAssertTrue(status1 == YAJLParserStatusInsufficientData, nil);
  36 + if (error) GHFail(@"Error: %@", error);
  37 + GHTestLog(@"First part: %@", document.root);
  38 +
  39 + NSData *data2 = [self loadData:@"stream_array2"];
  40 + YAJLParserStatus status2 = [document parse:data2 error:&error];
  41 + GHAssertTrue(status2 == YAJLParserStatusOK, nil);
  42 + if (error) GHFail(@"Error: %@", error);
43 43
44   - GHTestLog(@"Root: %@", document.root);
45   - [document release];
  44 + GHTestLog(@"Root: %@", document.root);
  45 + [document release];
46 46 }
47 47
48 48 - (void)testDoubleOverflow {
@@ -50,50 +50,50 @@ - (void)testDoubleOverflow {
50 50 YAJLDocument *document = [self _loadDocument:@"overflow" parserOptions:0 error:&error];
51 51 GHAssertNotNil(document, nil);
52 52 GHTestLog(@"Root: %@", document.root);
53   - YAJLParserStatus status = document.parserStatus;
54   - GHAssertEquals(status, (NSUInteger)YAJLParserStatusError, @"Should have error status");
55   -
56   - if (error) {
57   - GHTestLog(@"Parse error:\n%@", error);
  53 + YAJLParserStatus status = document.parserStatus;
  54 + GHAssertEquals(status, (NSUInteger)YAJLParserStatusError, @"Should have error status");
  55 +
  56 + if (error) {
  57 + GHTestLog(@"Parse error:\n%@", error);
58 58 GHAssertEquals([error code], (NSInteger)YAJLParserErrorCodeDoubleOverflow, nil);
59 59 GHAssertEqualStrings([[error userInfo] objectForKey:YAJLParserValueKey], @"1.79769e+309", nil);
60   - } else {
61   - GHFail(@"Should have error");
62   - }
  60 + } else {
  61 + GHFail(@"Should have error");
  62 + }
63 63 }
64 64
65 65 - (void)testOverflow2 {
66 66 NSError *error = nil;
67 67 YAJLDocument *document = [self _loadDocument:@"overflow2" parserOptions:0 error:&error];
68 68 GHTestLog(@"Root: %@", document.root);
69   - YAJLParserStatus status = document.parserStatus;
70   - GHAssertEquals(status, (NSUInteger)YAJLParserStatusOK, @"Should have OK status");
  69 + YAJLParserStatus status = document.parserStatus;
  70 + GHAssertEquals(status, (NSUInteger)YAJLParserStatusOK, @"Should have OK status");
71 71 GHAssertEqualObjects([document.root objectForKey:@"key1"], [NSNumber numberWithDouble:12343434343434343434343434344343434.0], nil);
72 72 GHAssertEqualObjects([document.root objectForKey:@"key2"], [NSNumber numberWithDouble:343434343434344343434343434.0], nil);
73 73 }
74 74
75 75 // This sample.json is too insane; Will need to revisit
76 76 - (void)_testEqualToSBJSON {
77   -