Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARC compatibility #2

Merged
merged 1 commit into from
Oct 10, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion XMLReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
// Created by Troy on 9/18/10.
// Updated by Antoine Marcadet on 9/23/11.
// Updated by Divan Visagie on 2012-08-26
//

#import <Foundation/Foundation.h>
Expand All @@ -18,7 +19,7 @@ typedef NSUInteger XMLReaderOptions;
{
NSMutableArray *dictionaryStack;
NSMutableString *textInProgress;
NSError **errorPointer;
NSError *errorPointer;
}

+ (NSDictionary *)dictionaryForXMLData:(NSData *)data error:(NSError **)errorPointer;
Expand Down
26 changes: 8 additions & 18 deletions XMLReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
// Created by Troy on 9/18/10.
// Updated by Antoine Marcadet on 9/23/11.
// Updated by Divan Visagie on 2012-08-26
//

#import "XMLReader.h"
Expand All @@ -27,7 +28,7 @@ + (NSDictionary *)dictionaryForXMLData:(NSData *)data error:(NSError **)error
{
XMLReader *reader = [[XMLReader alloc] initWithError:error];
NSDictionary *rootDictionary = [reader objectWithData:data options:0];
[reader release];

return rootDictionary;
}

Expand All @@ -41,7 +42,7 @@ + (NSDictionary *)dictionaryForXMLData:(NSData *)data options:(XMLReaderOptions)
{
XMLReader *reader = [[XMLReader alloc] initWithError:error];
NSDictionary *rootDictionary = [reader objectWithData:data options:options];
[reader release];

return rootDictionary;
}

Expand All @@ -58,24 +59,15 @@ - (id)initWithError:(NSError **)error
{
if (self = [super init])
{
errorPointer = error;
errorPointer = *error;
}
return self;
}

- (void)dealloc
{
[dictionaryStack release];
[textInProgress release];
[super dealloc];
}

- (NSDictionary *)objectWithData:(NSData *)data options:(XMLReaderOptions)options
{
// Clear out any old data
[dictionaryStack release];
[textInProgress release];


dictionaryStack = [[NSMutableArray alloc] init];
textInProgress = [[NSMutableString alloc] init];

Expand All @@ -92,8 +84,6 @@ - (NSDictionary *)objectWithData:(NSData *)data options:(XMLReaderOptions)option
parser.delegate = self;
BOOL success = [parser parse];

[parser release];

// Return the stack's root dictionary on success
if (success)
{
Expand Down Expand Up @@ -160,10 +150,10 @@ - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName names
{
// trim after concatenating
NSString *trimmedString = [textInProgress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[dictInProgress setObject:[[trimmedString mutableCopy] autorelease] forKey:kXMLReaderTextNodeKey];
[dictInProgress setObject:[trimmedString mutableCopy] forKey:kXMLReaderTextNodeKey];

// Reset the text
[textInProgress release];

textInProgress = [[NSMutableString alloc] init];
}

Expand All @@ -180,7 +170,7 @@ - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
// Set the error pointer to the parser's error object
*errorPointer = parseError;
errorPointer = parseError;
}

@end