ObjFW  Diff

Differences From Artifact [c32d0fe539]:

To Artifact [4d99c8e035]:


25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
25
26
27
28
29
30
31

32

33
34
35
36
37
38
39







-
+
-







#import "OFINICategory+Private.h"

#import "OFInvalidFormatException.h"
#import "OFOpenItemFailedException.h"

OF_DIRECT_MEMBERS
@interface OFINIFile ()
- (void)of_parseFile: (OFString *)path
- (void)of_parseFile: (OFString *)path encoding: (of_string_encoding_t)encoding;
	    encoding: (of_string_encoding_t)encoding;
@end

static bool
isWhitespaceLine(OFString *line)
{
	const char *cString = line.UTF8String;
	size_t length = line.UTF8StringLength;
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
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







-
+
-










-
+
-







- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithPath: (OFString *)path
{
	return [self initWithPath: path
	return [self initWithPath: path encoding: OF_STRING_ENCODING_UTF_8];
			 encoding: OF_STRING_ENCODING_UTF_8];
}

- (instancetype)initWithPath: (OFString *)path
		    encoding: (of_string_encoding_t)encoding
{
	self = [super init];

	@try {
		_categories = [[OFMutableArray alloc] init];

		[self of_parseFile: path
		[self of_parseFile: path encoding: encoding];
			  encoding: encoding];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
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
105
106
107
108
109
110
111

112

113
114
115
116
117
118
119

120

121
122
123
124
125
126
127







-
+
-







-
+
-







	[_categories addObject: category];

	objc_autoreleasePoolPop(pool);

	return category;
}

- (void)of_parseFile: (OFString *)path
- (void)of_parseFile: (OFString *)path encoding: (of_string_encoding_t)encoding
	    encoding: (of_string_encoding_t)encoding
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *file;
	OFINICategory *category = nil;
	OFString *line;

	@try {
		file = [OFFile fileWithPath: path
		file = [OFFile fileWithPath: path mode: @"r"];
				       mode: @"r"];
	} @catch (OFOpenItemFailedException *e) {
		/* Handle missing file like an empty file */
		if (e.errNo == ENOENT)
			return;

		@throw e;
	}
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
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







-
+
-






-
+
-











	}

	objc_autoreleasePoolPop(pool);
}

- (void)writeToFile: (OFString *)path
{
	[self writeToFile: path
	[self writeToFile: path encoding: OF_STRING_ENCODING_UTF_8];
		 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
	OFFile *file = [OFFile fileWithPath: path mode: @"w"];
				       mode: @"w"];
	bool first = true;

	for (OFINICategory *category in _categories)
		if ([category of_writeToStream: file
				      encoding: encoding
					 first: first])
			first = false;

	objc_autoreleasePoolPop(pool);
}
@end