Differences From Artifact [e87f1f698c]:
- File src/OFINIFile.m — part of check-in [904d0639c4] at 2024-08-24 09:20:58 on branch trunk — OFINIFile: Allow comments before first category (user: js, size: 4394) [annotate] [blame] [check-ins using] [more...]
To Artifact [408c66dded]:
- File
src/OFINIFile.m
— part of check-in
[0fead8a915]
at
2024-08-24 10:14:30
on branch trunk
— Rename OFINICategory to OFINISection
OFINICategory is provided as a deprecated subclass of OFINISection to
maintain API and ABI compatibility. (user: js, size: 4521) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
19 20 21 22 23 24 25 | #include "config.h" #include <errno.h> #import "OFINIFile.h" #import "OFArray.h" | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include "config.h" #include <errno.h> #import "OFINIFile.h" #import "OFArray.h" #import "OFINISection.h" #import "OFINISection+Private.h" #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFStream.h" #import "OFString.h" #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" |
︙ | ︙ | |||
48 49 50 51 52 53 54 | if (!OFASCIIIsSpace(cString[i])) return false; return true; } @implementation OFINIFile | | | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | if (!OFASCIIIsSpace(cString[i])) return false; return true; } @implementation OFINIFile @synthesize sections = _sections; + (instancetype)fileWithIRI: (OFIRI *)IRI { return [[[self alloc] initWithIRI: IRI] autorelease]; } + (instancetype)fileWithIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding |
︙ | ︙ | |||
75 76 77 78 79 80 81 | } - (instancetype)initWithIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { self = [super init]; @try { | | | | > > > > > | | | | | | | | > > > > > | | | | | | | | | | | | | 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 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 | } - (instancetype)initWithIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { self = [super init]; @try { _prologue = [[OFINISection alloc] of_initWithName: nil]; _sections = [[OFMutableArray alloc] init]; [self of_parseIRI: IRI encoding: encoding]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_prologue release]; [_sections release]; [super dealloc]; } - (OFArray OF_GENERIC(OFINISection *) *)categories { return self.sections; } - (OFINISection *)sectionForName: (OFString *)name { void *pool = objc_autoreleasePoolPush(); OFINISection *section; for (section in _sections) if ([section.name isEqual: name]) return section; section = [[[OFINISection alloc] of_initWithName: name] autorelease]; [_sections addObject: section]; objc_autoreleasePoolPop(pool); return section; } - (OFINISection *)categoryForName: (OFString *)name { return [self sectionForName: name]; } - (void)of_parseIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFStream *file; OFINISection *section = _prologue; OFString *line; if (encoding == OFStringEncodingAutodetect) encoding = OFStringEncodingUTF8; @try { file = [OFIRIHandler openItemAtIRI: IRI mode: @"r"]; } @catch (OFOpenItemFailedException *e) { /* Handle missing file like an empty file */ if (e.errNo == ENOENT) return; @throw e; } while ((line = [file readLineWithEncoding: encoding]) != nil) { if (isWhitespaceLine(line)) continue; if ([line hasPrefix: @"["]) { OFString *sectionName; if (![line hasSuffix: @"]"]) @throw [OFInvalidFormatException exception]; sectionName = [line substringWithRange: OFMakeRange(1, line.length - 2)]; section = [[[OFINISection alloc] of_initWithName: sectionName] autorelease]; [_sections addObject: section]; } else [section of_parseLine: line]; } objc_autoreleasePoolPop(pool); } - (void)writeToIRI: (OFIRI *)IRI { [self writeToIRI: IRI encoding: OFStringEncodingUTF8]; } - (void)writeToIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFStream *file = [OFIRIHandler openItemAtIRI: IRI mode: @"w"]; bool first = true; if ([_prologue of_writeToStream: file encoding: encoding first: true]) first = false; for (OFINISection *section in _sections) if ([section of_writeToStream: file encoding: encoding first: first]) first = false; objc_autoreleasePoolPop(pool); } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, _sections]; } @end |