Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Started work on YAJL callbacks to instantiate objects.

  • Loading branch information...
commit a40780d8377ea1179857f057342970b743b5932a 1 parent fbfc444
Craig Hockenberry authored
2  MGTwitterEngine.xcodeproj/project.pbxproj
View
@@ -239,7 +239,6 @@
children = (
C90F74CC0D6A3B7500F602A5 /* MGTwitterXMLParser.h */,
C90F74CD0D6A3B7500F602A5 /* MGTwitterXMLParser.m */,
- C90F74E10D6A3FF300F602A5 /* MGTwitterParserDelegate.h */,
C9FEB12A0D6095AF009AA322 /* MGTwitterStatusesParser.h */,
C9FEB12B0D6095AF009AA322 /* MGTwitterStatusesParser.m */,
C90031BA0D6B796400C38924 /* MGTwitterUsersParser.h */,
@@ -271,6 +270,7 @@
C9AE949A0D678D4400ADEBEC /* MGTwitterHTTPURLConnection.h */,
C9AE949B0D678D4400ADEBEC /* MGTwitterHTTPURLConnection.m */,
C9E497610D686B3500C83995 /* MGTwitterRequestTypes.h */,
+ C90F74E10D6A3FF300F602A5 /* MGTwitterParserDelegate.h */,
44F7517D0E47DBF600858A1B /* Twitter LibXML Parsers */,
C90F74CB0D6A3B5300F602A5 /* Twitter NSXML Parsers */,
44AEFFD00F213814004F5AE3 /* Twitter YAJL Parsers */,
6 MGTwitterYAJLParser.h
View
@@ -45,6 +45,12 @@ connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)re
- (NSDictionary *)_userDictionaryForNodeWithName:(const xmlChar *)parentNodeName;
- (NSDictionary *)_hashDictionaryForNodeWithName:(const xmlChar *)parentNodeName;
*/
+- (void)addValue:(id)value forKey:(NSString *)key;
+- (void)addValue:(id)value forKey:(NSString *)key;
+- (void)startDictionaryWithKey:(NSString *)key;
+- (void)endDictionaryWithKey:(NSString *)key;
+- (void)startArrayWithKey:(NSString *)key;
+- (void)endArrayWithKey:(NSString *)key;
// delegate callbacks
- (void)_parsingDidEnd;
129 MGTwitterYAJLParser.m
View
@@ -12,100 +12,108 @@ @implementation MGTwitterYAJLParser
#pragma mark Callbacks
+static NSString *currentKey;
+
int process_yajl_null(void *ctx)
{
id self = ctx;
- NSLog(@"%@: null", self);
-/*
- if (dict && key)
+ //NSLog(@"%@: null", self);
+ if (currentKey)
{
- [dict setValue:[NSNull null] forKey:key];
+ [self addValue:[NSNull null] forKey:currentKey];
}
-*/
+
return 1;
}
int process_yajl_boolean(void * ctx, int boolVal)
{
- id theSelf = ctx;
+ id self = ctx;
- NSLog(@"%@: bool: %s", theSelf, boolVal ? "true" : "false");
-/*
- if (dict && key)
+ //NSLog(@"%@: bool: %s", self, boolVal ? "true" : "false");
+ if (currentKey)
{
- [dict setValue:[NSNumber numberWithBool:boolVal] forKey:key];
+ [self addValue:[NSNumber numberWithBool:boolVal] forKey:currentKey];
+
+ [currentKey release];
+ currentKey = nil;
}
-*/
+
return 1;
}
int process_yajl_integer(void *ctx, long integerVal)
{
- id theSelf = ctx;
+ id self = ctx;
- NSLog(@"%@: integer: %ld", theSelf, integerVal);
-/*
- if (dict && key)
+ //NSLog(@"%@: integer: %ld", self, integerVal);
+ if (currentKey)
{
- [dict setValue:[NSNumber numberWithLong:integerVal] forKey:key];
+ [self addValue:[NSNumber numberWithLong:integerVal] forKey:currentKey];
+
+ [currentKey release];
+ currentKey = nil;
}
-*/
+
return 1;
}
int process_yajl_double(void *ctx, double doubleVal)
{
- id theSelf = ctx;
+ id self = ctx;
- NSLog(@"%@: double: %lf", theSelf, doubleVal);
-/*
- if (dict && key)
+ //NSLog(@"%@: double: %lf", self, doubleVal);
+ if (currentKey)
{
- [dict setValue:[NSNumber numberWithDouble:doubleVal] forKey:key];
+ [self addValue:[NSNumber numberWithDouble:doubleVal] forKey:currentKey];
+
+ [currentKey release];
+ currentKey = nil;
}
-*/
+
return 1;
}
int process_yajl_string(void *ctx, const unsigned char * stringVal, unsigned int stringLen)
{
- id theSelf = ctx;
+ id self = ctx;
- NSLog(@"%@: string: %@", theSelf, [[[NSString alloc] initWithBytes:stringVal length:stringLen encoding:NSUTF8StringEncoding] autorelease]);
-/*
- if (dict && key)
+ //NSLog(@"%@: string: %@", self, [[[NSString alloc] initWithBytes:stringVal length:stringLen encoding:NSUTF8StringEncoding] autorelease]);
+ if (currentKey)
{
NSString *value = [[[NSString alloc] initWithBytes:stringVal length:stringLen encoding:NSUTF8StringEncoding] autorelease];
- [dict setValue:value forKey:key];
+ [self addValue:value forKey:currentKey];
+
+ [currentKey release];
+ currentKey = nil;
}
-*/
+
return 1;
}
int process_yajl_map_key(void *ctx, const unsigned char * stringVal, unsigned int stringLen)
{
- id theSelf = ctx;
+ id self = ctx;
- NSLog(@"%@: key: %@", theSelf, [[[NSString alloc] initWithBytes:stringVal length:stringLen encoding:NSUTF8StringEncoding] autorelease]);
-
-/*
- if (key)
+ //NSLog(@"%@: key: %@", self, [[[NSString alloc] initWithBytes:stringVal length:stringLen encoding:NSUTF8StringEncoding] autorelease]);
+ if (currentKey)
{
- [key release];
- key = nil;
+ [currentKey release];
+ currentKey = nil;
}
- key = [[NSString alloc] initWithBytes:stringVal length:stringLen encoding:NSUTF8StringEncoding];
-*/
+ currentKey = [[NSString alloc] initWithBytes:stringVal length:stringLen encoding:NSUTF8StringEncoding];
+
return 1;
}
int process_yajl_start_map(void *ctx)
{
- id theSelf = ctx;
+ id self = ctx;
- NSLog(@"%@: map open '{'", theSelf);
+ //NSLog(@"%@: map open '{'", self);
+ [self startDictionaryWithKey:currentKey];
/*
dict = [[NSMutableDictionary alloc] initWithCapacity:0];
*/
@@ -115,9 +123,10 @@ int process_yajl_start_map(void *ctx)
int process_yajl_end_map(void *ctx)
{
- id theSelf = ctx;
+ id self = ctx;
- NSLog(@"%@: map close '}'", theSelf);
+ //NSLog(@"%@: map close '}'", self);
+ [self endDictionaryWithKey:currentKey];
/*
[dict release];
dict = nil;
@@ -127,18 +136,20 @@ int process_yajl_end_map(void *ctx)
int process_yajl_start_array(void *ctx)
{
- id theSelf = ctx;
+ id self = ctx;
- NSLog(@"%@: array open '['", theSelf);
+ //NSLog(@"%@: array open '['", self);
+ [self startArrayWithKey:currentKey];
return 1;
}
int process_yajl_end_array(void *ctx)
{
- id theSelf = ctx;
+ id self = ctx;
- NSLog(@"%@: array close ']'", theSelf);
+ //NSLog(@"%@: array close ']'", self);
+ [self endArrayWithKey:currentKey];
return 1;
}
@@ -240,6 +251,32 @@ - (void)parse
#pragma mark Subclass utilities
+- (void)addValue:(id)value forKey:(NSString *)key
+{
+ NSLog(@"%@ = %@ (%@)", key, value, NSStringFromClass([value class]));
+}
+
+- (void)startDictionaryWithKey:(NSString *)key
+{
+ NSLog(@"%@ = dictionary start", key);
+}
+
+- (void)endDictionaryWithKey:(NSString *)key
+{
+ NSLog(@"%@ = dictionary end", key);
+}
+
+- (void)startArrayWithKey:(NSString *)key
+{
+ NSLog(@"%@ = array start", key);
+}
+
+- (void)endArrayWithKey:(NSString *)key
+{
+ NSLog(@"%@ = array end", key);
+}
+
+
/*
// get the value from the current node
- (xmlChar *)_nodeValue
Please sign in to comment.
Something went wrong with that request. Please try again.