Skip to content

Commit

Permalink
Switch to SBJsonParser 3.2.
Browse files Browse the repository at this point in the history
This lets us use ARC on SBJsonParser, as well.
  • Loading branch information
Shadowfiend committed Aug 30, 2013
1 parent 92ed45e commit aa08c14
Show file tree
Hide file tree
Showing 26 changed files with 889 additions and 921 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ VPATH = app app/en.lproj json oniguruma oniguruma/enc universalchardet lemon \

NO_ARC_OBJC_SRCS = \
NSObject+SPInvocationGrabbing.m \
Nu.m \
$(JSON_OBJC_SRCS)
Nu.m

JSON_OBJC_SRCS = \
NSObject+JSON.m \
SBJsonParser.m \
SBJsonStreamParser.m \
SBJsonStreamParserAdapter.m \
SBJsonStreamParserAccumulator.m \
SBJsonStreamParserTokeniser.m \
SBJsonStreamParserWriterAccumulator.m \
SBJsonStreamParserAdapter.m \
SBJsonStreamParserState.m \
SBJsonStreamWriter.m \
SBJsonStreamWriterAccumulator.m \
SBJsonStreamWriterState.m \
SBJsonTokeniser.m \
SBJsonUTF8Stream.m \
SBJsonWriter.m

OBJC_SRCS = \
Expand Down Expand Up @@ -145,6 +144,7 @@ OBJC_SRCS = \
ViWindow.m \
ViWindowController.m \
ViWordCompletion.m \
$(JSON_OBJC_SRCS) \
main.m

OBJCXX_SRCS = \
Expand Down
6 changes: 4 additions & 2 deletions app/ViAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#import "ViPreferencePaneAdvanced.h"
#import "TMFileURLProtocol.h"
#import "TxmtURLProtocol.h"
#import "JSON.h"
#import "SBJson.h"
#import "ViError.h"
#import "ViCommandMenuItemView.h"
#import "ViEventManager.h"
Expand Down Expand Up @@ -649,7 +649,9 @@ - (NSString *)eval:(NSString *)script

if ([result isKindOfClass:[NSNull class]])
return nil;
return [result JSONRepresentation];

SBJsonWriter *writer = [[SBJsonWriter alloc] init];
return [writer stringWithObject:result];
}

- (NSError *)openURL:(NSString *)pathOrURL andWait:(BOOL)waitFlag backChannel:(NSString *)channelName
Expand Down
21 changes: 15 additions & 6 deletions app/ViPreferencePaneBundles.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#import "ViPreferencePaneBundles.h"
#import "ViBundleStore.h"
#import "JSON.h"
#import "SBJson.h"
#include "logging.h"

@implementation repoUserTransformer
Expand Down Expand Up @@ -167,15 +167,20 @@ - (void)loadBundlesFromRepo:(NSString *)username
return;
NSData *jsonData = [NSData dataWithContentsOfFile:path];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSArray *arry = [jsonString JSONValue];

SBJsonParser *parser = [[SBJsonParser alloc] init];
NSArray *arry = [parser objectWithString:jsonString];
if (![arry isKindOfClass:[NSArray class]]) {
INFO(@"%s", "failed to parse JSON");
INFO(@"%s: %@", "failed to parse JSON, error was ", parser.error);
return;
}
[_repositories addObjectsFromArray: arry];
} else {
NSString *path = [self repoPathForUser:username readonly:NO];
[[_repoJson JSONRepresentation] writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:NULL];

SBJsonWriter *writer = [[SBJsonWriter alloc] init];
NSString *json =[writer stringWithObject:_repoJson];
[json writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:NULL];
[_repositories addObjectsFromArray:_repoJson];
}

Expand Down Expand Up @@ -457,7 +462,9 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection

NSString *jsonString = [[NSString alloc] initWithData:_userData encoding:NSUTF8StringEncoding];
_userData = nil;
NSDictionary *dict = [jsonString JSONValue];

SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *dict = [parser objectWithString:jsonString];
if (![dict isKindOfClass:[NSDictionary class]]) {
[self cancelProgressSheet:nil];
[progressDescription setStringValue:[NSString stringWithFormat:@"Failed to parse data for user %@.", username]];
Expand Down Expand Up @@ -492,7 +499,9 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection

if (connection == _repoConnection) {
NSString *jsonString = [[NSString alloc] initWithData:_repoData encoding:NSUTF8StringEncoding];
NSArray *repoJson = [jsonString JSONValue];

SBJsonParser *parser = [[SBJsonParser alloc] init];
NSArray *repoJson = [parser objectWithString:jsonString];
[_repoJson addObjectsFromArray:repoJson];

NSDictionary *repoUser = [_processQueue lastObject];
Expand Down
69 changes: 0 additions & 69 deletions json/JSON.h

This file was deleted.

61 changes: 0 additions & 61 deletions json/NSObject+JSON.h

This file was deleted.

58 changes: 0 additions & 58 deletions json/NSObject+JSON.m

This file was deleted.

2 changes: 0 additions & 2 deletions json/SBJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,3 @@
#import "SBJsonStreamParser.h"
#import "SBJsonStreamParserAdapter.h"
#import "SBJsonStreamWriter.h"
#import "SBJsonStreamTokeniser.h"

24 changes: 20 additions & 4 deletions json/SBJsonParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,31 @@
- (id)objectWithData:(NSData*)data;

/**
Parse string and return the represented dictionary or array.
Return the object represented by the given string
Calls objectWithData: internally.
This method converts its input to an NSData object containing UTF8 and calls -objectWithData: with it.
@param string An NSString containing JSON text.
@return The NSArray or NSDictionary represented by the object, or nil if an error occured.
*/
- (id)objectWithString:(NSString *)repr;

/**
Return the object represented by the given string
This method calls objectWithString: internally. If an error occurs, and if error
is not nil, it creates an NSError object and returns this through its second argument.
@param jsonText the json string to parse
@param error pointer to an NSError object to populate on error
@return The NSArray or NSDictionary represented by the object, or nil if an error occured.
@warning Deprecated in Version 3.2; will be removed in 4.0
*/
- (id)objectWithString:(NSString *)string;

- (id)objectWithString:(NSString*)jsonText
error:(NSError**)error __attribute__ ((deprecated));

@end

Expand Down
23 changes: 18 additions & 5 deletions json/SBJsonParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

//#if !__has_feature(objc_arc)
//#error "This source file must be compiled with ARC enabled!"
//#endif
#if !__has_feature(objc_arc)
#error "This source file must be compiled with ARC enabled!"
#endif

#import "SBJsonParser.h"
#import "SBJsonStreamParser.h"
Expand Down Expand Up @@ -84,8 +84,21 @@ - (id)objectWithData:(NSData *)data {
return nil;
}

- (id)objectWithString:(NSString *)string {
return [self objectWithData:[string dataUsingEncoding:NSUTF8StringEncoding]];
- (id)objectWithString:(NSString *)repr {
return [self objectWithData:[repr dataUsingEncoding:NSUTF8StringEncoding]];
}

- (id)objectWithString:(NSString*)repr error:(NSError**)error_ {
id tmp = [self objectWithString:repr];
if (tmp)
return tmp;

if (error_) {
NSDictionary *ui = [NSDictionary dictionaryWithObjectsAndKeys:error, NSLocalizedDescriptionKey, nil];
*error_ = [NSError errorWithDomain:@"org.brautaset.SBJsonParser.ErrorDomain" code:0 userInfo:ui];
}

return nil;
}

@end
Loading

0 comments on commit aa08c14

Please sign in to comment.