Index: src/OFString+JSONValue.h ================================================================== --- src/OFString+JSONValue.h +++ src/OFString+JSONValue.h @@ -25,10 +25,13 @@ #endif @interface OFString (JSONValue) /** * \brief Creates an object from the JSON value of the string. + * + * \note This also allows parsing JSON5, an extension of JSON. See + * http://json5.org/ for more details. * * \return An object */ - (id)JSONValue; @end Index: src/OFString+JSONValue.m ================================================================== --- src/OFString+JSONValue.m +++ src/OFString+JSONValue.m @@ -128,10 +128,11 @@ static inline OFString* parseString(const char *restrict *pointer, const char *stop) { char *buffer; size_t i = 0; + char delimiter = **pointer; if (++(*pointer) + 1 >= stop) return nil; if ((buffer = malloc(stop - *pointer)) == NULL) @@ -234,11 +235,11 @@ default: free(buffer); return nil; } /* End of string found */ - } else if (**pointer == '"') { + } else if (**pointer == delimiter) { OFString *ret; @try { ret = [OFString stringWithUTF8String: buffer length: i]; @@ -398,10 +399,11 @@ if (*pointer >= stop) return nil; switch (**pointer) { case '"': + case '\'': return parseString(pointer, stop); case '[': return parseArray(pointer, stop); case '{': return parseDictionary(pointer, stop); Index: tests/OFJSONTests.m ================================================================== --- tests/OFJSONTests.m +++ tests/OFJSONTests.m @@ -31,14 +31,14 @@ @implementation TestsAppDelegate (JSONTests) - (void)JSONTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFString *s = @"{\"foo\"\t:\"bar\", \"x\":/*fooo*/ [7.5\r,null//bar\n" + OFString *s = @"{\"foo\"\t:'ba\\r', \"x\":/*fooo*/ [7.5\r,null//bar\n" @",\"foo\",false]}"; OFDictionary *d = [OFDictionary dictionaryWithKeysAndObjects: - @"foo", @"bar", + @"foo", @"ba\r", @"x", [OFArray arrayWithObjects: [OFNumber numberWithFloat: 7.5f], [OFNull null], @"foo", [OFNumber numberWithBool: NO], @@ -46,11 +46,11 @@ nil]; TEST(@"-[JSONValue #1]", [[s JSONValue] isEqual: d]) TEST(@"-[JSONRepresentation]", [[d JSONRepresentation] isEqual: - @"{\"foo\":\"bar\",\"x\":[7.5,null,\"foo\",false]}"]) + @"{\"foo\":\"ba\\r\",\"x\":[7.5,null,\"foo\",false]}"]) EXPECT_EXCEPTION(@"-[JSONValue #2]", OFInvalidEncodingException, [@"{" JSONValue]) EXPECT_EXCEPTION(@"-[JSONValue #3]", OFInvalidEncodingException, [@"]" JSONValue])