Skip to content
Open
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
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc

# Logs and databases #
######################
*.log

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
32 changes: 16 additions & 16 deletions LGXMLParser/LGXMLParser.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2008 Louis Gerbarg

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
Expand All @@ -8,10 +8,10 @@
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand All @@ -20,7 +20,7 @@
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

*/

#import "LGXMLParser.h"
Expand Down Expand Up @@ -49,7 +49,7 @@ @implementation LGXMLParser
- (void) dealloc {
xmlFreeParserCtxt(ctxt);
self.delegate = nil;

[super dealloc];
}

Expand All @@ -60,7 +60,7 @@ - (xmlParserCtxtPtr) ctxt {
if (!ctxt) {
ctxt = xmlCreatePushParserCtxt(emptySAXHandler, self, NULL, 0, NULL);
}

return ctxt;
}

Expand Down Expand Up @@ -119,19 +119,19 @@ - (void)setShouldResolveExternalEntities:(BOOL)shouldResolveExternalEntities {
static void
startElement2(void *ctx, const xmlChar *name, const xmlChar **atts) {
LGXMLParser *self = (LGXMLParser *)ctx;

if ([self.delegate respondsToSelector:@selector(parser:didStartElement:namespaceURI:qualifiedName:attributes:)]) {
NSMutableDictionary *returnAttributes = nil;
NSMutableDictionary *returnAttributes = nil;
NSUInteger i = 0;

//We need to walk through the attributes and make a dictionary out of them
if (atts) {
returnAttributes = [NSMutableDictionary dictionary];
for(i = 0; atts[i] != NULL && atts[i+1] != NULL; i+=2) {
[returnAttributes setObject:[NSString stringWithUTF8String:(char *)atts[i+1]] forKey:[NSString stringWithUTF8String:(char *)atts[i]]];
}
}

[self.delegate parser:(NSXMLParser *)self didStartElement:[NSString stringWithUTF8String:(const char *)name] namespaceURI:nil qualifiedName:nil attributes:returnAttributes];
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ - (void)setShouldResolveExternalEntities:(BOOL)shouldResolveExternalEntities {
static void
characters2(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) {
LGXMLParser *self = (LGXMLParser *)ctx;

if ([self.delegate respondsToSelector:@selector(parser:foundCharacters:)]) {
NSString *characters = [[[NSString alloc] initWithBytes:(const void *)ch length:len encoding:NSUTF8StringEncoding] autorelease];;
[self.delegate parser:(NSXMLParser *)self foundCharacters:characters];
Expand All @@ -175,10 +175,10 @@ - (void)setShouldResolveExternalEntities:(BOOL)shouldResolveExternalEntities {


//We could do better error handling if we needed it
static void
static void
xmlParserErrors2(void *ctx, const char *msg, ...) {
LGXMLParser *self = (LGXMLParser *)ctx;

if ([self.delegate respondsToSelector:@selector(parser:parseErrorOccurred:)]) {
//FIXME this should be better, but on the phone this is mainly a debugging niceity
NSError *error = [NSError errorWithDomain:@"LGXMLParser" code:0 userInfo:nil];
Expand All @@ -189,7 +189,7 @@ - (void)setShouldResolveExternalEntities:(BOOL)shouldResolveExternalEntities {
static void
ignorableWhitespace2 (void *ctx, const xmlChar *ch, int len) {
LGXMLParser *self = (LGXMLParser *)ctx;

if ([self.delegate respondsToSelector:@selector(parser:foundIgnorableWhitespace:)]) {
NSString *characters = [[[NSString alloc] initWithBytes:(const void *)ch length:len encoding:NSUTF8StringEncoding] autorelease];
[self.delegate parser:(NSXMLParser *)self foundIgnorableWhitespace:characters];
Expand All @@ -199,7 +199,7 @@ - (void)setShouldResolveExternalEntities:(BOOL)shouldResolveExternalEntities {
static void
comment2 (void *ctx, const xmlChar *value) {
LGXMLParser *self = (LGXMLParser *)ctx;

if ([self.delegate respondsToSelector:@selector(parser:foundComment:)]) {
NSString *characters = [[[NSString alloc] initWithBytes:value length:strlen((const char *)value) encoding:NSUTF8StringEncoding] autorelease];
[self.delegate parser:(NSXMLParser *)self foundComment:characters];
Expand All @@ -209,7 +209,7 @@ - (void)setShouldResolveExternalEntities:(BOOL)shouldResolveExternalEntities {
static void
cdataBlock2 (void *ctx, const xmlChar *value, int len) {
LGXMLParser *self = (LGXMLParser *)ctx;

if ([self.delegate respondsToSelector:@selector(parser:foundCDATA:)]) {
NSData *data = [[[NSData alloc] initWithBytes:(const void *)value length:len] autorelease];
[self.delegate parser:(NSXMLParser *)self foundCDATA:data];
Expand Down
12 changes: 6 additions & 6 deletions TouchJSON/NuTests/test_json.nu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(load "TouchJSON")

(class TestJSON is NuTestCase

(- testSerializer is
(set s (CJSONSerializer serializer))
(assert_equal "null" (s serializeNull:nil))
Expand All @@ -10,27 +10,27 @@
(assert_equal "[1,\"two\",3]" (s serializeArray:(array 1 "two" 3.0)))
(assert_equal "{\"three\":[1,2,3]}"
(s serializeDictionary:(dict three:(array 1 2 3))))

;; It seemed to me that an orthgonal API would let me do this...
;;(assert_equal "null" (s serializeObject:nil))
(assert_equal "123" (s serializeObject:123))
(assert_equal "\"one two three\"" (s serializeObject:"one two three"))
(assert_equal "[1,\"two\",3]" (s serializeObject:(array 1 "two" 3.0)))
(assert_equal "{\"three\":[1,2,3]}"
(s serializeObject:(dict three:(array 1 2 3)))))

(- testDeserializer is
(set d (CJSONDeserializer deserializer))
(assert_equal nil (d deserialize:"null"))
(assert_equal 123 (d deserialize:"123"))
(assert_equal "one two three" (d deserialize:"\"one two three\""))
(assert_equal "one two three" (d deserialize:"\"one two three\""))
(assert_equal (array 1 "two" 3.0) (d deserialize:"[1,\"two\",3]"))
(assert_equal (dict three:(array 1 2 3)) (d deserialize:"{\"three\":[1,2,3]}")))

(- testInfoInAndOut is
(set s (CJSONSerializer serializer))
(set d (CJSONDeserializer deserializer))

(set info (NSDictionary dictionaryWithContentsOfFile:"UnitTests/Info.plist"))
(set serialized (s serializeObject:info))
(set info2 (d deserialize:serialized))
Expand Down
2 changes: 1 addition & 1 deletion TouchJSON/Source/CDataScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
u_int8_t *end;
u_int8_t *current;
NSUInteger length;

NSCharacterSet *doubleCharacters;
}

Expand Down
8 changes: 4 additions & 4 deletions TouchJSON/Source/CDataScanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ - (NSUInteger)scanLocation

- (NSData *)data
{
return(data);
return(data);
}

- (void)setData:(NSData *)inData
Expand All @@ -100,7 +100,7 @@ - (void)setData:(NSData *)inData
[data release];
data = NULL;
}

if (inData)
{
data = [inData retain];
Expand Down Expand Up @@ -192,7 +192,7 @@ - (BOOL)scanCharactersFromSet:(NSCharacterSet *)inSet intoString:(NSString **)ou
{
*outValue = [[[NSString alloc] initWithBytes:current length:P - current encoding:NSUTF8StringEncoding] autorelease];
}

current = P;

return(YES);
Expand Down Expand Up @@ -232,7 +232,7 @@ - (BOOL)scanUpToCharactersFromSet:(NSCharacterSet *)inSet intoString:(NSString *
{
*outValue = [[[NSString alloc] initWithBytes:current length:P - current encoding:NSUTF8StringEncoding] autorelease];
}

current = P;

return(YES);
Expand Down
6 changes: 3 additions & 3 deletions TouchJSON/Source/Extensions/CDataScanner_Extensions.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ - (BOOL)scanCStyleComment:(NSString **)outComment
NSString *theComment = NULL;
if ([self scanUpToString:@"*/" intoString:&theComment] == NO)
[NSException raise:NSGenericException format:@"Started to scan a C style comment but it wasn't terminated."];

if ([theComment rangeOfString:@"/*"].location != NSNotFound)
[NSException raise:NSGenericException format:@"C style comments should not be nested."];

if ([self scanString:@"*/" intoString:NULL] == NO)
[NSException raise:NSGenericException format:@"C style comment did not end correctly."];

if (outComment != NULL)
*outComment = theComment;

Expand Down
6 changes: 3 additions & 3 deletions TouchJSON/Source/Extensions/NSScanner_Extensions.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ - (BOOL)scanCStyleComment:(NSString **)outComment
NSString *theComment = NULL;
if ([self scanUpToString:@"*/" intoString:&theComment] == NO)
[NSException raise:NSGenericException format:@"Started to scan a C style comment but it wasn't terminated."];

if ([theComment rangeOfString:@"/*"].location != NSNotFound)
[NSException raise:NSGenericException format:@"C style comments should not be nested."];

if ([self scanString:@"*/" intoString:NULL] == NO)
[NSException raise:NSGenericException format:@"C style comment did not end correctly."];

if (outComment != NULL)
*outComment = theComment;

Expand Down
16 changes: 8 additions & 8 deletions TouchJSON/Source/JSON/CJSONScanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ - (void)setData:(NSData *)inData
else if (theChars[1] != 0)
theEncoding = NSUTF16BigEndianStringEncoding;
}

if (theEncoding != NSUTF8StringEncoding)
{
NSString *theString = [[NSString alloc] initWithData:theData encoding:theEncoding];
Expand Down Expand Up @@ -157,7 +157,7 @@ - (BOOL)scanJSONObject:(id *)outObject error:(NSError **)outError
[self scanJSONArray:&theObject error:outError];
break;
default:

break;
}

Expand Down Expand Up @@ -187,7 +187,7 @@ - (BOOL)scanJSONDictionary:(NSDictionary **)outDictionary error:(NSError **)outE
while ([self currentCharacter] != '}')
{
[self skipWhitespace];

if ([self currentCharacter] == '}')
break;

Expand Down Expand Up @@ -324,7 +324,7 @@ - (BOOL)scanJSONArray:(NSArray **)outArray error:(NSError **)outError
}

[theArray addObject:theValue];

[self skipWhitespace];
if ([self scanCharacter:','] == NO)
{
Expand All @@ -342,7 +342,7 @@ - (BOOL)scanJSONArray:(NSArray **)outArray error:(NSError **)outError
[theArray release];
return(NO);
}

break;
}
[self skipWhitespace];
Expand Down Expand Up @@ -401,7 +401,7 @@ - (BOOL)scanJSONStringConstant:(NSString **)outStringConstant error:(NSError **)
{
[theString appendString:theStringChunk];
}

if ([self scanCharacter:'\\'] == YES)
{
unichar theCharacter = [self scanCharacter];
Expand Down Expand Up @@ -469,7 +469,7 @@ - (BOOL)scanJSONStringConstant:(NSString **)outStringConstant error:(NSError **)
CFStringAppendCharacters((CFMutableStringRef)theString, &theCharacter, 1);
}
}

if (outStringConstant != NULL)
*outStringConstant = [[theString copy] autorelease];

Expand Down Expand Up @@ -527,7 +527,7 @@ - (BOOL)scanNotQuoteCharactersIntoString:(NSString **)outValue
{
*outValue = [[[NSString alloc] initWithBytes:current length:P - current encoding:NSUTF8StringEncoding] autorelease];
}

current = P;

return(YES);
Expand Down
2 changes: 1 addition & 1 deletion TouchJSON/Source/JSON/CJSONSerializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ - (NSString *)serializeDictionary:(NSDictionary *)inDictionary
while ((theKey = [theEnumerator nextObject]) != NULL)
{
id theValue = [inDictionary objectForKey:theKey];

[theString appendFormat:@"%@:%@", [self serializeString:theKey], [self serializeObject:theValue]];
if (theKey != [theKeys lastObject])
[theString appendString:@","];
Expand Down
2 changes: 1 addition & 1 deletion TouchJSON/UnitTests/CDataScanner_UnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (void)testSomething
STAssertFalse(theScanner.isAtEnd, NULL);

NSString *theString = NULL;
BOOL theResult =
BOOL theResult =

theResult = [theScanner scanString:@"Hello" intoString:&theString];
STAssertTrue(theResult, NULL);
Expand Down
2 changes: 1 addition & 1 deletion TouchJSON/UnitTests/CJSONDeserializer_UnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ -(void)testDeserializeDictionaryWithAnEmbeddedArray {
@"a_method", @"method",
[NSArray arrayWithObject:@"a_param"], @"params",
nil];
STAssertEqualObjects(dictionary, theObject, nil);
STAssertEqualObjects(dictionary, theObject, nil);
}

-(void)testCheckForError {
Expand Down
4 changes: 2 additions & 2 deletions TouchJSON/UnitTests/TestData/ex3.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"width": 500,
"height": 500
},
"image": {
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
Expand All @@ -23,4 +23,4 @@
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}
}}
Loading