Overview
Comment: | OFINIFile: Add support for different encodings |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
44de69ef31988e5fae6537fa5fdc4c62 |
User & Date: | js on 2014-06-14 09:44:45 |
Other Links: | manifest | tags |
Context
2014-06-16
| ||
15:06 | Make return type of -[OFArray objects] const check-in: 68d32a92c1 user: js tags: trunk | |
2014-06-14
| ||
09:44 | OFINIFile: Add support for different encodings check-in: 44de69ef31 user: js tags: trunk | |
2014-06-13
| ||
16:41 | Clean up OFINIFileTests.m check-in: 34cf1fb8c2 user: js tags: trunk | |
Changes
Modified src/OFINICategory+Private.h from [141e6d31f9] to [963e590a59].
︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | + + + + | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFINICategory.h" #import "OFString.h" #import "macros.h" @class OFStream; @interface OFINICategory (OF_PRIVATE_CATEGORY) - (instancetype)OF_init; - (void)OF_parseLine: (OFString*)line; - (bool)OF_writeToStream: (OFStream*)stream encoding: (of_string_encoding_t)encoding first: (bool)first; @end |
Modified src/OFINICategory.m from [8e99773efd] to [077a8d208b].
︙ | |||
406 407 408 409 410 411 412 413 414 415 416 417 418 419 | 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | + | i++; } objc_autoreleasePoolPop(pool); } - (bool)OF_writeToStream: (OFStream*)stream encoding: (of_string_encoding_t)encoding first: (bool)first { OFEnumerator *enumerator; id line; if ([_lines count] == 0) return false; |
︙ | |||
428 429 430 431 432 433 434 435 | 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | + + - + + | if ([line isKindOfClass: [OFINICategory_Comment class]]) { OFINICategory_Comment *comment = line; [stream writeLine: comment->_comment]; } else if ([line isKindOfClass: [OFINICategory_Pair class]]) { OFINICategory_Pair *pair = line; OFString *key = escapeString(pair->_key); OFString *value = escapeString(pair->_value); OFString *line = [OFString stringWithFormat: @"%@=%@\n", key, value]; |
Modified src/OFINIFile.h from [d3236d0058] to [ad0922c06d].
︙ | |||
11 12 13 14 15 16 17 18 19 20 | 11 12 13 14 15 16 17 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 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 91 92 93 94 95 96 97 98 99 100 101 102 103 | + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFString.h" #import "OFINICategory.h" @class OFMutableArray; |
Modified src/OFINIFile.m from [38c671870e] to [7cf0535b70].
︙ | |||
24 25 26 27 28 29 30 | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | - + + | #import "OFInvalidFormatException.h" #import "OFOpenFileFailedException.h" #import "autorelease.h" #import "macros.h" @interface OFINIFile (OF_PRIVATE_CATEGORY) |
︙ | |||
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 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 91 92 93 94 95 96 | + + + + + + + + + + + + + + - + + | } @implementation OFINIFile + (instancetype)fileWithPath: (OFString*)path { return [[[self alloc] initWithPath: path] autorelease]; } + (instancetype)fileWithPath: (OFString*)path encoding: (of_string_encoding_t)encoding { return [[[self alloc] initWithPath: path encoding: encoding] autorelease]; } - init { OF_INVALID_INIT_METHOD } - initWithPath: (OFString*)path { return [self initWithPath: path encoding: OF_STRING_ENCODING_UTF_8]; } - initWithPath: (OFString*)path encoding: (of_string_encoding_t)encoding { self = [super init]; @try { _categories = [[OFMutableArray alloc] init]; |
︙ | |||
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | 126 127 128 129 130 131 132 133 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 | + - + | objc_autoreleasePoolPop(pool); return [category autorelease]; } - (void)OF_parseFile: (OFString*)path encoding: (of_string_encoding_t)encoding { void *pool = objc_autoreleasePoolPush(); OFFile *file; OFINICategory *category = nil; OFString *line; @try { file = [OFFile fileWithPath: path mode: @"r"]; } @catch (OFOpenFileFailedException *e) { /* Handle missing file like an empty file */ if ([e errNo] == ENOENT) return; @throw e; } |
︙ | |||
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | + + + + + + + + | } objc_autoreleasePoolPop(pool); } - (void)writeToFile: (OFString*)path { [self writeToFile: path encoding: OF_STRING_ENCODING_UTF_8]; } - (void)writeToFile: (OFString*)path encoding: (of_string_encoding_t)encoding { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"w"]; OFEnumerator *enumerator = [_categories objectEnumerator]; OFINICategory *category; bool first = true; while ((category = [enumerator nextObject]) != nil) if ([category OF_writeToStream: file encoding: encoding first: first]) first = false; objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFINIFileTests.m from [b708218fa8] to [4b57243305].
︙ | |||
41 42 43 44 45 46 47 | 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 | - + - - + + + - + | @"foobar=baz" NL @";comment" NL @"new=new" NL NL @"[foobar]" NL @";foobarcomment" NL @"qux=\" asd\"" NL |
︙ | |||
111 112 113 114 115 116 117 | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | + - - + + + + + | TEST(@"-[removeValueForKey:]", R([foobar removeValueForKey: @"quxqux "])) module = @"OFINIFile"; /* FIXME: Find a way to write files on Nintendo DS */ #ifndef OF_NINTENDO_DS TEST(@"-[writeToFile:encoding:]", |
Modified tests/testfile.ini from [2addf8918f] to [a2b6991eb2].
1 2 3 4 5 6 7 8 9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | - + | [tests] foo = bar foobar=baz ;comment [foobar] ;foobarcomment qux=" asd" "quxqux " = asd |