Skip to content

Commit faaa654

Browse files
committed
Remove parser as argument to all its delegate methods
1 parent e8a1444 commit faaa654

File tree

4 files changed

+47
-46
lines changed

4 files changed

+47
-46
lines changed

src/main/objc/SBJsonChunkParser.m

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ - (void)pop {
129129
}
130130

131131
- (void)parser:(SBJsonStreamParser *)parser found:(id)obj {
132-
[self parser:parser found:obj isValue:NO];
132+
[self parserFound:obj isValue:NO ];
133133
}
134134

135-
- (void)parser:(SBJsonStreamParser *)parser found:(id)obj isValue:(BOOL)isValue {
135+
- (void)parserFound:(id)obj isValue:(BOOL)isValue {
136136
NSParameterAssert(obj);
137137

138138
if(processBlock&&path) {
@@ -170,7 +170,7 @@ - (void)parser:(SBJsonStreamParser *)parser found:(id)obj isValue:(BOOL)isValue
170170

171171
#pragma mark Delegate methods
172172

173-
- (void)parserFoundObjectStart:(SBJsonStreamParser *)parser {
173+
- (void)parserFoundObjectStart {
174174
++depth;
175175
if (depth > _maxDepth)
176176
[self maxDepthError];
@@ -182,18 +182,18 @@ - (void)parserFoundObjectStart:(SBJsonStreamParser *)parser {
182182
currentType = SBJsonChunkObject;
183183
}
184184

185-
- (void)parser:(SBJsonStreamParser *)parser foundObjectKey:(NSString*)key_ {
185+
- (void)parserFoundObjectKey:(NSString *)key_ {
186186
[keyStack addObject:key_];
187187
}
188188

189-
- (void)parserFoundObjectEnd:(SBJsonStreamParser *)parser {
189+
- (void)parserFoundObjectEnd {
190190
depth--;
191191
id value = dict;
192192
[self pop];
193-
[self parser:parser found:value];
193+
[self parser:_parser found:value];
194194
}
195195

196-
- (void)parserFoundArrayStart:(SBJsonStreamParser *)parser {
196+
- (void)parserFoundArrayStart {
197197
depth++;
198198
if (depth > _maxDepth)
199199
[self maxDepthError];
@@ -207,12 +207,12 @@ - (void)parserFoundArrayStart:(SBJsonStreamParser *)parser {
207207
}
208208
}
209209

210-
- (void)parserFoundArrayEnd:(SBJsonStreamParser *)parser {
210+
- (void)parserFoundArrayEnd {
211211
depth--;
212212
if (depth > 1 || !supportPartialDocuments) {
213213
id value = array;
214214
[self pop];
215-
[self parser:parser found:value];
215+
[self parser:_parser found:value];
216216
}
217217
}
218218

@@ -222,23 +222,23 @@ - (void)maxDepthError {
222222
[_parser stop];
223223
}
224224

225-
- (void)parser:(SBJsonStreamParser *)parser foundBoolean:(BOOL)x {
226-
[self parser:parser found:[NSNumber numberWithBool:x] isValue:YES];
225+
- (void)parserFoundBoolean:(BOOL)x {
226+
[self parserFound:[NSNumber numberWithBool:x] isValue:YES ];
227227
}
228228

229-
- (void)parserFoundNull:(SBJsonStreamParser *)parser {
230-
[self parser:parser found:[NSNull null] isValue:YES];
229+
- (void)parserFoundNull {
230+
[self parserFound:[NSNull null] isValue:YES ];
231231
}
232232

233-
- (void)parser:(SBJsonStreamParser *)parser foundNumber:(NSNumber*)num {
234-
[self parser:parser found:num isValue:YES];
233+
- (void)parserFoundNumber:(NSNumber *)num {
234+
[self parserFound:num isValue:YES ];
235235
}
236236

237-
- (void)parser:(SBJsonStreamParser *)parser foundString:(NSString*)string {
238-
[self parser:parser found:string isValue:YES];
237+
- (void)parserFoundString:(NSString *)string {
238+
[self parserFound:string isValue:YES ];
239239
}
240240

241-
- (void)parser:(SBJsonStreamParser *)parser foundError:(NSError *)err {
241+
- (void)parserFoundError:(NSError *)err {
242242
errorHandler(err);
243243
}
244244

@@ -262,7 +262,7 @@ - (NSString *)pathString {
262262
return pathString;
263263
}
264264

265-
- (BOOL)parserShouldSupportManyDocuments:(SBJsonStreamParser *)parser {
265+
- (BOOL)parserShouldSupportManyDocuments {
266266
return supportManyDocuments;
267267
}
268268

src/main/objc/SBJsonStreamParser.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,39 @@ typedef enum {
5151
@protocol SBJsonStreamParserDelegate < NSObject >
5252

5353
/// Called when object start is found
54-
- (void)parserFoundObjectStart:(SBJsonStreamParser *)parser;
54+
- (void)parserFoundObjectStart;
5555

5656
/// Called when object key is found
57-
- (void)parser:(SBJsonStreamParser *)parser foundObjectKey:(NSString*)key;
57+
- (void)parserFoundObjectKey:(NSString *)key;
5858

5959
/// Called when object end is found
60-
- (void)parserFoundObjectEnd:(SBJsonStreamParser *)parser;
60+
- (void)parserFoundObjectEnd;
6161

6262
/// Called when array start is found
63-
- (void)parserFoundArrayStart:(SBJsonStreamParser *)parser;
63+
- (void)parserFoundArrayStart;
6464

6565
/// Called when array end is found
66-
- (void)parserFoundArrayEnd:(SBJsonStreamParser *)parser;
66+
- (void)parserFoundArrayEnd;
6767

6868
/// Called when a boolean value is found
69-
- (void)parser:(SBJsonStreamParser *)parser foundBoolean:(BOOL)x;
69+
- (void)parserFoundBoolean:(BOOL)x;
7070

7171
/// Called when a null value is found
72-
- (void)parserFoundNull:(SBJsonStreamParser *)parser;
72+
- (void)parserFoundNull;
7373

7474
/// Called when a number is found
75-
- (void)parser:(SBJsonStreamParser *)parser foundNumber:(NSNumber*)num;
75+
- (void)parserFoundNumber:(NSNumber *)num;
7676

7777
/// Called when a string is found
78-
- (void)parser:(SBJsonStreamParser *)parser foundString:(NSString*)string;
78+
- (void)parserFoundString:(NSString *)string;
7979

8080
/// Called when an error occurs
81-
- (void)parser:(SBJsonStreamParser *)parser foundError:(NSError*)err;
81+
- (void)parserFoundError:(NSError *)err;
8282

8383
@optional
8484

8585
/// Called to determine whether to allow multiple whitespace-separated documents
86-
- (BOOL)parserShouldSupportManyDocuments:(SBJsonStreamParser *)parser;
86+
- (BOOL)parserShouldSupportManyDocuments;
8787

8888
@end
8989

src/main/objc/SBJsonStreamParser.m

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ - (NSString*)tokenName:(sbjson_token_t)token {
113113
}
114114

115115
- (void)handleObjectStart {
116-
[_delegate parserFoundObjectStart:self];
116+
[_delegate parserFoundObjectStart];
117117
[_stateStack addObject:_state];
118118
_state = [SBJsonStreamParserStateObjectStart sharedInstance];
119119
}
@@ -122,11 +122,11 @@ - (void)handleObjectEnd: (sbjson_token_t) tok {
122122
_state = [_stateStack lastObject];
123123
[_stateStack removeLastObject];
124124
[_state parser:self shouldTransitionTo:tok];
125-
[_delegate parserFoundObjectEnd:self];
125+
[_delegate parserFoundObjectEnd];
126126
}
127127

128128
- (void)handleArrayStart {
129-
[_delegate parserFoundArrayStart:self];
129+
[_delegate parserFoundArrayStart];
130130
[_stateStack addObject:_state];
131131
_state = [SBJsonStreamParserStateArrayStart sharedInstance];
132132
}
@@ -135,7 +135,7 @@ - (void)handleArrayEnd: (sbjson_token_t) tok {
135135
_state = [_stateStack lastObject];
136136
[_stateStack removeLastObject];
137137
[_state parser:self shouldTransitionTo:tok];
138-
[_delegate parserFoundArrayEnd:self];
138+
[_delegate parserFoundArrayEnd];
139139
}
140140

141141
- (void) handleTokenNotExpectedHere: (sbjson_token_t) tok {
@@ -144,7 +144,7 @@ - (void) handleTokenNotExpectedHere: (sbjson_token_t) tok {
144144

145145
_state = [SBJsonStreamParserStateError sharedInstance];
146146
id ui = @{ NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Token '%@' not expected %@", tokenName, stateName]};
147-
[_delegate parser:self foundError:[NSError errorWithDomain:@"org.sbjson.parser" code:2 userInfo:ui]];
147+
[_delegate parserFoundError:[NSError errorWithDomain:@"org.sbjson.parser" code:2 userInfo:ui]];
148148
}
149149

150150
- (SBJsonParserStatus)parse:(NSData *)data_ {
@@ -170,7 +170,8 @@ - (SBJsonParserStatus)parse:(NSData *)data_ {
170170

171171
case sbjson_token_error:
172172
_state = [SBJsonStreamParserStateError sharedInstance];
173-
[_delegate parser:self foundError:[NSError errorWithDomain:@"org.sbjson.parser" code:3 userInfo:@{ NSLocalizedDescriptionKey : tokeniser.error }]];
173+
[_delegate parserFoundError:[NSError errorWithDomain:@"org.sbjson.parser" code:3
174+
userInfo:@{NSLocalizedDescriptionKey : tokeniser.error}]];
174175
return SBJsonParserError;
175176
break;
176177

@@ -204,23 +205,23 @@ - (SBJsonParserStatus)parse:(NSData *)data_ {
204205
break;
205206

206207
case sbjson_token_bool:
207-
[_delegate parser:self foundBoolean:token[0] == 't'];
208+
[_delegate parserFoundBoolean:token[0] == 't'];
208209
[_state parser:self shouldTransitionTo:tok];
209210
break;
210211

211212

212213
case sbjson_token_null:
213-
[_delegate parserFoundNull:self];
214+
[_delegate parserFoundNull];
214215
[_state parser:self shouldTransitionTo:tok];
215216
break;
216217

217218
case sbjson_token_integer: {
218219
const int UNSIGNED_LONG_LONG_MAX_DIGITS = 20;
219220
if (token_len <= UNSIGNED_LONG_LONG_MAX_DIGITS) {
220221
if (*token == '-')
221-
[_delegate parser:self foundNumber: @(strtoll(token, NULL, 10))];
222+
[_delegate parserFoundNumber:@(strtoll(token, NULL, 10))];
222223
else
223-
[_delegate parser:self foundNumber: @(strtoull(token, NULL, 10))];
224+
[_delegate parserFoundNumber:@(strtoull(token, NULL, 10))];
224225

225226
[_state parser:self shouldTransitionTo:tok];
226227
break;
@@ -229,27 +230,27 @@ - (SBJsonParserStatus)parse:(NSData *)data_ {
229230
// FALLTHROUGH
230231

231232
case sbjson_token_real: {
232-
[_delegate parser:self foundNumber: @(strtod(token, NULL))];
233+
[_delegate parserFoundNumber:@(strtod(token, NULL))];
233234
[_state parser:self shouldTransitionTo:tok];
234235
break;
235236
}
236237

237238
case sbjson_token_string: {
238239
NSString *string = [[NSString alloc] initWithBytes:token length:token_len encoding:NSUTF8StringEncoding];
239240
if ([_state needKey])
240-
[_delegate parser:self foundObjectKey:string];
241+
[_delegate parserFoundObjectKey:string];
241242
else
242-
[_delegate parser:self foundString:string];
243+
[_delegate parserFoundString:string];
243244
[_state parser:self shouldTransitionTo:tok];
244245
break;
245246
}
246247

247248
case sbjson_token_encoded: {
248249
NSString *string = [self decodeStringToken:token length:token_len];
249250
if ([_state needKey])
250-
[_delegate parser:self foundObjectKey:string];
251+
[_delegate parserFoundObjectKey:string];
251252
else
252-
[_delegate parser:self foundString:string];
253+
[_delegate parserFoundString:string];
253254
[_state parser:self shouldTransitionTo:tok];
254255
break;
255256
}

src/main/objc/SBJsonStreamParserState.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ - (void)parser:(SBJsonStreamParser *)parser shouldTransitionTo:(sbjson_token_t)t
9999

100100
case sbjson_token_array_close:
101101
case sbjson_token_object_close:
102-
if ([parser.delegate respondsToSelector:@selector(parserShouldSupportManyDocuments:)] && [parser.delegate parserShouldSupportManyDocuments:parser])
102+
if ([parser.delegate respondsToSelector:@selector(parserShouldSupportManyDocuments)] && [parser.delegate parserShouldSupportManyDocuments])
103103
state = parser.state;
104104
else
105105
state = [SBJsonStreamParserStateComplete sharedInstance];

0 commit comments

Comments
 (0)