Skip to content

Commit

Permalink
Automatic translation to ARC for SBJson + SBJsonTests
Browse files Browse the repository at this point in the history
  • Loading branch information
stig committed Oct 17, 2011
1 parent 037d3d1 commit 02463ba
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 66 deletions.
4 changes: 2 additions & 2 deletions Classes/NSObject+SBJson.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
@implementation NSObject (NSObject_SBJsonWriting)

- (NSString *)JSONRepresentation {
SBJsonWriter *writer = [[[SBJsonWriter alloc] init] autorelease];
SBJsonWriter *writer = [[SBJsonWriter alloc] init];
NSString *json = [writer stringWithObject:self];
if (!json)
NSLog(@"-JSONRepresentation failed. Error is: %@", writer.error);
Expand All @@ -48,7 +48,7 @@ - (NSString *)JSONRepresentation {
@implementation NSString (NSString_SBJsonParsing)

- (id)JSONValue {
SBJsonParser *parser = [[[SBJsonParser alloc] init] autorelease];
SBJsonParser *parser = [[SBJsonParser alloc] init];
id repr = [parser objectWithString:self];
if (!repr)
NSLog(@"-JSONValue failed. Error is: %@", parser.error);
Expand Down
10 changes: 3 additions & 7 deletions Classes/SBJsonParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ - (id)init {
return self;
}

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

#pragma mark Methods

Expand All @@ -58,12 +54,12 @@ - (id)objectWithData:(NSData *)data {
return nil;
}

SBJsonStreamParserAccumulator *accumulator = [[[SBJsonStreamParserAccumulator alloc] init] autorelease];
SBJsonStreamParserAccumulator *accumulator = [[SBJsonStreamParserAccumulator alloc] init];

SBJsonStreamParserAdapter *adapter = [[[SBJsonStreamParserAdapter alloc] init] autorelease];
SBJsonStreamParserAdapter *adapter = [[SBJsonStreamParserAdapter alloc] init];
adapter.delegate = accumulator;

SBJsonStreamParser *parser = [[[SBJsonStreamParser alloc] init] autorelease];
SBJsonStreamParser *parser = [[SBJsonStreamParser alloc] init];
parser.maxDepth = self.maxDepth;
parser.delegate = adapter;

Expand Down
6 changes: 3 additions & 3 deletions Classes/SBJsonStreamParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ typedef enum {
SBJsonTokeniser *tokeniser;
}

@property (nonatomic, assign) SBJsonStreamParserState *state; // Private
@property (nonatomic, readonly, retain) NSMutableArray *stateStack; // Private
@property (nonatomic, unsafe_unretained) SBJsonStreamParserState *state; // Private
@property (nonatomic, readonly, strong) NSMutableArray *stateStack; // Private

/**
@brief Expect multiple documents separated by whitespace
Expand All @@ -129,7 +129,7 @@ typedef enum {
Usually this should be an instance of SBJsonStreamParserAdapter, but you can
substitute your own implementation of the SBJsonStreamParserDelegate protocol if you need to.
*/
@property (assign) id<SBJsonStreamParserDelegate> delegate;
@property (unsafe_unretained) id<SBJsonStreamParserDelegate> delegate;

/**
@brief The max parse depth
Expand Down
4 changes: 0 additions & 4 deletions Classes/SBJsonStreamParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ - (id)init {
}

- (void)dealloc {
self.error = nil;
self.state = nil;
[stateStack release];
[tokeniser release];
[super dealloc];
}

#pragma mark Methods
Expand Down
8 changes: 2 additions & 6 deletions Classes/SBJsonStreamParserAccumulator.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,15 @@ @implementation SBJsonStreamParserAccumulator

@synthesize value;

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

#pragma mark SBJsonStreamParserAdapterDelegate

- (void)parser:(SBJsonStreamParser*)parser foundArray:(NSArray *)array {
value = [array retain];
value = array;
}

- (void)parser:(SBJsonStreamParser*)parser foundObject:(NSDictionary *)dict {
value = [dict retain];
value = dict;
}

@end
2 changes: 1 addition & 1 deletion Classes/SBJsonStreamParserAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,6 @@ typedef enum {
@brief Your delegate object
Set this to the object you want to receive the SBJsonStreamParserAdapterDelegate messages.
*/
@property (assign) id<SBJsonStreamParserAdapterDelegate> delegate;
@property (unsafe_unretained) id<SBJsonStreamParserAdapterDelegate> delegate;

@end
15 changes: 4 additions & 11 deletions Classes/SBJsonStreamParserAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ - (id)init {
return self;
}

- (void)dealloc {
[keyStack release];
[stack release];
[super dealloc];
}

#pragma mark Private methods

Expand Down Expand Up @@ -116,7 +111,7 @@ - (void)parser:(SBJsonStreamParser*)parser found:(id)obj {

- (void)parserFoundObjectStart:(SBJsonStreamParser*)parser {
if (++depth > self.levelsToSkip) {
dict = [[NSMutableDictionary new] autorelease];
dict = [NSMutableDictionary new];
[stack addObject:dict];
currentType = SBJsonStreamParserAdapterObject;
}
Expand All @@ -128,27 +123,25 @@ - (void)parser:(SBJsonStreamParser*)parser foundObjectKey:(NSString*)key_ {

- (void)parserFoundObjectEnd:(SBJsonStreamParser*)parser {
if (depth-- > self.levelsToSkip) {
id value = [dict retain];
id value = dict;
[self pop];
[self parser:parser found:value];
[value release];
}
}

- (void)parserFoundArrayStart:(SBJsonStreamParser*)parser {
if (++depth > self.levelsToSkip) {
array = [[NSMutableArray new] autorelease];
array = [NSMutableArray new];
[stack addObject:array];
currentType = SBJsonStreamParserAdapterArray;
}
}

- (void)parserFoundArrayEnd:(SBJsonStreamParser*)parser {
if (depth-- > self.levelsToSkip) {
id value = [array retain];
id value = array;
[self pop];
[self parser:parser found:value];
[value release];
}
}

Expand Down
6 changes: 3 additions & 3 deletions Classes/SBJsonStreamWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@
NSMutableDictionary *cache;
}

@property (nonatomic, assign) SBJsonStreamWriterState *state; // Internal
@property (nonatomic, readonly, retain) NSMutableArray *stateStack; // Internal
@property (nonatomic, unsafe_unretained) SBJsonStreamWriterState *state; // Internal
@property (nonatomic, readonly, strong) NSMutableArray *stateStack; // Internal

/**
@brief delegate to receive JSON output
Delegate that will receive messages with output.
*/
@property (assign) id<SBJsonStreamWriterDelegate> delegate;
@property (unsafe_unretained) id<SBJsonStreamWriterDelegate> delegate;

/**
@brief The maximum recursing depth.
Expand Down
4 changes: 0 additions & 4 deletions Classes/SBJsonStreamWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ - (id)init {
}

- (void)dealloc {
self.error = nil;
self.state = nil;
[stateStack release];
[cache release];
[super dealloc];
}

#pragma mark Methods
Expand Down
4 changes: 0 additions & 4 deletions Classes/SBJsonStreamWriterAccumulator.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ - (id)init {
return self;
}

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

#pragma mark SBJsonStreamWriterDelegate

Expand Down
2 changes: 1 addition & 1 deletion Classes/SBJsonTokeniser.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ typedef enum {

@interface SBJsonTokeniser : NSObject

@property (retain) SBJsonUTF8Stream *stream;
@property (strong) SBJsonUTF8Stream *stream;
@property (copy) NSString *error;

- (void)appendData:(NSData*)data_;
Expand Down
11 changes: 3 additions & 8 deletions Classes/SBJsonTokeniser.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ - (id)init {
return self;
}

- (void)dealloc {
[_error release];
[_stream release];
[super dealloc];
}

- (void)appendData:(NSData *)data_ {
[_stream appendData:data_];
Expand Down Expand Up @@ -162,16 +157,16 @@ - (sbjson_token_t)getStringToken:(NSObject**)token {
[acc appendString:string];

} else if (ch == '"') {
*token = [[string copy] autorelease];
*token = [string copy];
[_stream skip];
return sbjson_token_string;

} else {
acc = [[string mutableCopy] autorelease];
acc = [string mutableCopy];
}
}
@finally {
[string release];
string = nil;
}
}

Expand Down
6 changes: 1 addition & 5 deletions Classes/SBJsonUTF8Stream.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ - (id)init {
return self;
}

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

- (void)appendData:(NSData *)data_ {

Expand Down Expand Up @@ -135,7 +131,7 @@ - (BOOL)skipCharacters:(const char *)chars length:(NSUInteger)len {
}

- (NSString*)stringWithRange:(NSRange)range {
return [[[NSString alloc] initWithBytes:_bytes + range.location length:range.length encoding:NSUTF8StringEncoding] autorelease];
return [[NSString alloc] initWithBytes:_bytes + range.location length:range.length encoding:NSUTF8StringEncoding];

}

Expand Down
10 changes: 3 additions & 7 deletions Classes/SBJsonWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ - (id)init {
return self;
}

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

- (NSString*)stringWithObject:(id)value {
NSData *data = [self dataWithObject:value];
if (data)
return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return nil;
}

Expand All @@ -80,9 +76,9 @@ - (NSString*)stringWithObject:(id)value error:(NSError**)error_ {
- (NSData*)dataWithObject:(id)object {
self.error = nil;

SBJsonStreamWriterAccumulator *accumulator = [[[SBJsonStreamWriterAccumulator alloc] init] autorelease];
SBJsonStreamWriterAccumulator *accumulator = [[SBJsonStreamWriterAccumulator alloc] init];

SBJsonStreamWriter *streamWriter = [[[SBJsonStreamWriter alloc] init] autorelease];
SBJsonStreamWriter *streamWriter = [[SBJsonStreamWriter alloc] init];
streamWriter.sortKeys = self.sortKeys;
streamWriter.maxDepth = self.maxDepth;
streamWriter.humanReadable = self.humanReadable;
Expand Down
4 changes: 4 additions & 0 deletions SBJson.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 34;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -751,6 +752,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = 34;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
Expand All @@ -773,6 +775,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks";
GCC_DYNAMIC_NO_PIC = NO;
Expand All @@ -795,6 +798,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks";
Expand Down

0 comments on commit 02463ba

Please sign in to comment.