Skip to content

Commit

Permalink
Merge pull request #2 from snip3r8/master
Browse files Browse the repository at this point in the history
ARC compatibility
  • Loading branch information
amarcadet committed Oct 10, 2012
2 parents 6cc14da + 7aa0bf3 commit 2c4dedb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
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

0 comments on commit 2c4dedb

Please sign in to comment.