Comment: | OFString: Rename JSONValue to objectByParsingJSON |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
8611f48f424ae2b84846c5a4277d7b8f |
User & Date: | js on 2020-08-13 21:07:20 |
Other Links: | manifest | tags |
2020-08-13
| ||
21:12 | messagePackValue -> objectByParsingMessagePack check-in: 6cfa8f5c7e user: js tags: trunk | |
21:07 | OFString: Rename JSONValue to objectByParsingJSON check-in: 8611f48f42 user: js tags: trunk | |
20:58 | Add src/runtime/Info.plist to {clean,ignore}-glob check-in: 67b8b22764 user: js tags: trunk | |
Modified src/Makefile from [34c348d2c8] to [f2c0d6b35c].
︙ | ︙ | |||
82 83 84 85 86 87 88 | OFSHA384Or512Hash.m \ OFSHA512Hash.m \ OFSortedList.m \ OFStdIOStream.m \ OFStream.m \ OFString.m \ OFString+CryptoHashing.m \ | | | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | OFSHA384Or512Hash.m \ OFSHA512Hash.m \ OFSortedList.m \ OFStdIOStream.m \ OFStream.m \ OFString.m \ OFString+CryptoHashing.m \ OFString+JSONParsing.m \ OFString+PropertyListValue.m \ OFString+Serialization.m \ OFString+URLEncoding.m \ OFString+XMLEscaping.m \ OFString+XMLUnescaping.m \ OFSystemInfo.m \ OFTarArchive.m \ |
︙ | ︙ |
Modified src/OFLocale.m from [80430a2785] to [5d8907dfbe].
︙ | ︙ | |||
508 509 510 511 512 513 514 | if (_language == nil) return; pool = objc_autoreleasePoolPush(); mapPath = [path stringByAppendingPathComponent: @"languages.json"]; @try { | | > | 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | if (_language == nil) return; pool = objc_autoreleasePoolPush(); mapPath = [path stringByAppendingPathComponent: @"languages.json"]; @try { map = [OFString stringWithContentsOfFile: mapPath] .objectByParsingJSON; } @catch (OFOpenItemFailedException *e) { objc_autoreleasePoolPop(pool); return; } language = _language.lowercaseString; territory = _territory.lowercaseString; |
︙ | ︙ | |||
533 534 535 536 537 538 539 | return; } languageFile = [path stringByAppendingPathComponent: [languageFile stringByAppendingString: @".json"]]; [_localizedStrings addObject: | | > | 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | return; } languageFile = [path stringByAppendingPathComponent: [languageFile stringByAppendingString: @".json"]]; [_localizedStrings addObject: [OFString stringWithContentsOfFile: languageFile] .objectByParsingJSON]; objc_autoreleasePoolPop(pool); } #endif - (OFString *)localizedStringForID: (OFConstantString *)ID fallback: (id)fallback, ... |
︙ | ︙ |
Renamed and modified src/OFString+JSONValue.h [311031a35c] to src/OFString+JSONParsing.h [bc722e0fb3].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif | | | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFString_JSONParsing_reference; #ifdef __cplusplus } #endif @interface OFString (JSONParsing) /*! * @brief The string interpreted as JSON and parsed as an object. * * @note This also allows parsing JSON5, an extension of JSON. See * http://json5.org/ for more details. * * @warning Although not specified by the JSON specification, this can also * return primitives like strings and numbers. The rationale behind * this is that most JSON parsers allow JSON data just consisting of a * single primitive, leading to real world JSON files sometimes only * consisting of a single primitive. Therefore, you should not make any * assumptions about the object returned by this method if you don't * want your program to terminate due to a message not understood, but * instead check the returned object using @ref isKindOfClass:. */ @property (readonly, nonatomic) id objectByParsingJSON; /*! * @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. * |
︙ | ︙ | |||
61 62 63 64 65 66 67 | * instead check the returned object using @ref isKindOfClass:. * * @param depthLimit The maximum depth the parser should accept (defaults to 32 * if not specified, 0 means no limit (insecure!)) * * @return An object */ | | | 61 62 63 64 65 66 67 68 69 70 71 | * instead check the returned object using @ref isKindOfClass:. * * @param depthLimit The maximum depth the parser should accept (defaults to 32 * if not specified, 0 means no limit (insecure!)) * * @return An object */ - (id)objectByParsingJSONWithDepthLimit: (size_t)depthLimit; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFString+JSONValue.m [2f361d6379] to src/OFString+JSONParsing.m [706b49d04b].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #include <stdlib.h> #include <string.h> #include <math.h> #include <assert.h> | | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <stdlib.h> #include <string.h> #include <math.h> #include <assert.h> #import "OFString+JSONParsing.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OFNull.h" #import "OFInvalidJSONException.h" int _OFString_JSONParsing_reference; static id nextObject(const char **pointer, const char *stop, size_t *line, size_t depthLimit); static void skipWhitespaces(const char **pointer, const char *stop, size_t *line) { |
︙ | ︙ | |||
637 638 639 640 641 642 643 | case 'I': return parseNumber(pointer, stop, line); default: return nil; } } | | | | | | 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | case 'I': return parseNumber(pointer, stop, line); default: return nil; } } @implementation OFString (JSONParsing) - (id)objectByParsingJSON { return [self objectByParsingJSONWithDepthLimit: 32]; } - (id)objectByParsingJSONWithDepthLimit: (size_t)depthLimit { void *pool = objc_autoreleasePoolPush(); const char *pointer = self.UTF8String; const char *stop = pointer + self.UTF8StringLength; id object; size_t line = 1; |
︙ | ︙ |
Modified src/OFString.h from [9976ca688e] to [2923bf31dc].
︙ | ︙ | |||
1276 1277 1278 1279 1280 1281 1282 | OF_ASSUME_NONNULL_END #include "OFConstantString.h" #include "OFMutableString.h" #ifdef __OBJC__ # import "OFString+CryptoHashing.h" | | | 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 | OF_ASSUME_NONNULL_END #include "OFConstantString.h" #include "OFMutableString.h" #ifdef __OBJC__ # import "OFString+CryptoHashing.h" # import "OFString+JSONParsing.h" # ifdef OF_HAVE_FILES # import "OFString+PathAdditions.h" # endif # import "OFString+PropertyListValue.h" # import "OFString+Serialization.h" # import "OFString+URLEncoding.h" # import "OFString+XMLEscaping.h" |
︙ | ︙ |
Modified src/OFString.m from [3885de5d40] to [6889fff2f5].
︙ | ︙ | |||
126 127 128 129 130 131 132 | size_t, bool); /* References for static linking */ void _references_to_categories_of_OFString(void) { _OFString_CryptoHashing_reference = 1; | | | 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | size_t, bool); /* References for static linking */ void _references_to_categories_of_OFString(void) { _OFString_CryptoHashing_reference = 1; _OFString_JSONParsing_reference = 1; #ifdef OF_HAVE_FILES _OFString_PathAdditions_reference = 1; #endif _OFString_PropertyListValue_reference = 1; _OFString_Serialization_reference = 1; _OFString_URLEncoding_reference = 1; _OFString_XMLEscaping_reference = 1; |
︙ | ︙ |
Modified tests/OFJSONTests.m from [9395f43f69] to [dda895677f].
︙ | ︙ | |||
34 35 36 37 38 39 40 | [OFNumber numberWithInt: 0xF], [OFNull null], @"foo", [OFNumber numberWithBool: false], nil], nil]; | | | | | | | | | | | | | | | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | [OFNumber numberWithInt: 0xF], [OFNull null], @"foo", [OFNumber numberWithBool: false], nil], nil]; TEST(@"-[objectByParsingJSON] #1", [s.objectByParsingJSON isEqual: d]) TEST(@"-[JSONRepresentation]", [[d JSONRepresentation] isEqual: @"{\"x\":[0.5,15,null,\"foo\",false],\"foo\":\"b\\na\\r\"}"]) TEST(@"OF_JSON_REPRESENTATION_PRETTY", [[d JSONRepresentationWithOptions: OF_JSON_REPRESENTATION_PRETTY] isEqual: @"{\n\t\"x\": [\n\t\t0.5,\n\t\t15,\n\t\tnull,\n\t\t" @"\"foo\",\n\t\tfalse\n\t],\n\t\"foo\": \"b\\na\\r\"\n}"]) TEST(@"OF_JSON_REPRESENTATION_JSON5", [[d JSONRepresentationWithOptions: OF_JSON_REPRESENTATION_JSON5] isEqual: @"{x:[0.5,15,null,\"foo\",false],foo:\"b\\\na\\r\"}"]) EXPECT_EXCEPTION(@"-[objectByParsingJSON] #2", OFInvalidJSONException, [@"{" objectByParsingJSON]) EXPECT_EXCEPTION(@"-[objectByParsingJSON] #3", OFInvalidJSONException, [@"]" objectByParsingJSON]) EXPECT_EXCEPTION(@"-[objectByParsingJSON] #4", OFInvalidJSONException, [@"bar" objectByParsingJSON]) EXPECT_EXCEPTION(@"-[objectByParsingJSON] #5", OFInvalidJSONException, [@"[\"a\" \"b\"]" objectByParsingJSON]) TEST(@"-[objectByParsingJSON] #6", [@"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" .objectByParsingJSON isEqual: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFDictionary dictionary]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]) EXPECT_EXCEPTION(@"-[objectByParsingJSON] #7", OFInvalidJSONException, [@"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" objectByParsingJSON]) objc_autoreleasePoolPop(pool); } @end |
Modified utils/ofarc/LHAArchive.m from [c25e61eb57] to [cb999e6ec3].
︙ | ︙ | |||
141 142 143 144 145 146 147 | @"%" PRIu32, entry.uncompressedSize]; OFString *CRC16 = [OFString stringWithFormat: @"%04" PRIX16, entry.CRC16]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_compressed_size", | | | | | | | | | | | | | | | | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | @"%" PRIu32, entry.uncompressedSize]; OFString *CRC16 = [OFString stringWithFormat: @"%04" PRIX16, entry.CRC16]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_compressed_size", @"[" @" 'Compressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", compressedSize)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_uncompressed_size", @"[" @" 'Uncompressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", uncompressedSize)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_compression_method", @"Compression method: %[method]", @"method", entry.compressionMethod)]; [of_stdout writeString: @"\t"]; |
︙ | ︙ |
Modified utils/ofarc/TarArchive.m from [ed61f78528] to [ec05b83de8].
︙ | ︙ | |||
122 123 124 125 126 127 128 | OFString *UID = [OFString stringWithFormat: @"%u", entry.UID]; OFString *GID = [OFString stringWithFormat: @"%u", entry.GID]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_size", | | | | | | | | | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | OFString *UID = [OFString stringWithFormat: @"%u", entry.UID]; OFString *GID = [OFString stringWithFormat: @"%u", entry.GID]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_size", @"[" @" 'Size: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", size)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_mode", @"Mode: %[mode]", @"mode", mode)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_uid", |
︙ | ︙ |
Modified utils/ofarc/ZIPArchive.m from [b0e2928e0d] to [64fc6c92d3].
︙ | ︙ | |||
134 135 136 137 138 139 140 | stringWithFormat: @"%08" PRIX32, entry.CRC32]; OFString *modificationDate = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_compressed_size", | | | | | | | | | | | | | | | | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | stringWithFormat: @"%08" PRIX32, entry.CRC32]; OFString *modificationDate = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_compressed_size", @"[" @" 'Compressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", compressedSize)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_uncompressed_size", @"[" @" 'Uncompressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", uncompressedSize)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_compression_method", @"Compression method: %[method]", @"method", compressionMethod)]; [of_stdout writeString: @"\t"]; |
︙ | ︙ |
Modified utils/ofhttp/OFHTTP.m from [636026cd3b] to [976ffe7a77].
︙ | ︙ | |||
809 810 811 812 813 814 815 | lengthString = OF_LOCALIZED(@"size_kib", @"%[num] KiB", @"num", lengthString); } else { lengthString = [OFString stringWithFormat: @"%jd", _resumedFrom + _length]; lengthString = OF_LOCALIZED(@"size_bytes", | | | | | | | | 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 | lengthString = OF_LOCALIZED(@"size_kib", @"%[num] KiB", @"num", lengthString); } else { lengthString = [OFString stringWithFormat: @"%jd", _resumedFrom + _length]; lengthString = OF_LOCALIZED(@"size_bytes", @"[" @" [" @" {'num == 1': '1 byte'}," @" {'': '%[num] bytes'}" @" ]" @"]".objectByParsingJSON, @"num", lengthString); } } else lengthString = OF_LOCALIZED(@"size_unknown", @"unknown"); if (_verbose) { |
︙ | ︙ |
Modified utils/ofhttp/ProgressBar.m from [ab819ab9fe] to [814de8c246].
︙ | ︙ | |||
200 201 202 203 204 205 206 | [of_stdout writeString: OF_LOCALIZED(@"progress_kib", @"%[num] KiB", @"num", num)]; } else { OFString *num = [OFString stringWithFormat: @"%jd", _resumedFrom + _received]; [of_stdout writeString: OF_LOCALIZED(@"progress_bytes", | | | | | | | | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | [of_stdout writeString: OF_LOCALIZED(@"progress_kib", @"%[num] KiB", @"num", num)]; } else { OFString *num = [OFString stringWithFormat: @"%jd", _resumedFrom + _received]; [of_stdout writeString: OF_LOCALIZED(@"progress_bytes", @"[" @" [" @" {'num == 1': '1 byte '}," @" {'': '%[num] bytes'}" @" ]" @"]".objectByParsingJSON, @"num", num)]; } [of_stdout writeString: @" "]; if (_stopped) _BPS = (float)_received / |
︙ | ︙ |