ObjFW  Check-in [46b770d066]

Overview
Comment:Add missing const for some return types; new exception.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 46b770d0665fa6510357f09e4dacddd5ac392500aee78ffef49a4411202e3f3c
User & Date: js on 2008-12-13 14:50:29
Other Links: manifest | tags
Context
2008-12-13
14:52
Fix 2 FIXMEs in OFTCPSocket. check-in: 7d05cee843 user: js tags: trunk
14:50
Add missing const for some return types; new exception. check-in: 46b770d066 user: js tags: trunk
13:52
On some systems, localhost doesn't work for IPv6, thus use ::1. check-in: add10740d1 user: js tags: trunk
Changes

Modified src/OFExceptions.h from [f063fde1b6] to [78a34e9941].

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
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
 * \return The object that caused the exception
 */
- (id)object;

/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;
@end

/**
 * An OFException indicating there is not enough memory available.
 */
@interface OFNoMemException: OFException
{
	size_t req_size;
}

/**
 * Creates a new no memory exception.
 *
 * \param obj The object which caused the exception
 * \param size The size of the memory that couldn't be allocated
 * \return A new no memory exception
 */
+ newWithObject: (id)obj
	andSize: (size_t)size;

/**
 * Initializes an already allocated no memory exception.
 *
 * \param obj The object which caused the exception
 * \param size The size of the memory that couldn't be allocated
 * \return An initialized no memory exception
 */
- initWithObject: (id)obj
	 andSize: (size_t)size;

/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;

/**
 * \return The size of the memoory that couldn't be allocated
 */
- (size_t)requestedSize;
@end

/**
 * An OFException indicating the given memory is not part of the object.
 */
@interface OFMemNotPartOfObjException: OFException
{
	void *pointer;
}

/**
 * Creates a new memory not part of object exception.
 *
 * \param obj The object which caused the exception
 * \param ptr A pointer to the memory that is not part of the object
 * \return A new memory not part of object exception
 */
+ newWithObject: (id)obj
     andPointer: (void*)ptr;

/**
 * Initializes an already allocated memory not part of object exception.
 *
 * \param obj The object which caused the exception
 * \param ptr A pointer to the memory that is not part of the object
 * \return An initialized memory not part of object exception
 */
- initWithObject: (id)obj
      andPointer: (void*)ptr;

/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;

/**
 * \return A pointer to the memory which is not part of the object
 */
- (void*)pointer;
@end

/**
 * An OFException indicating the given value is out of range. 
 */
@interface OFOutOfRangeException: OFException {}
/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;
@end

/**
 * An OFException indicating that the conversation between two charsets failed.
 */
@interface OFCharsetConversionFailedException: OFException {}
/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;
@end

/**
 * An OFException indicating the file couldn't be opened.
 */
@interface OFOpenFileFailedException: OFException
{
	char *path;
	char *mode;
}

/**
 * Creates a new open file failed exception.
 *
 * \param obj The object which caused the exception
 * \param p A C string of the path to the file tried to open
 * \param m A C string of the mode in which the file should have been opened
 * \return A new open file failed exception
 */
+ newWithObject: (id)obj
	andPath: (const char*)p







|











<
<




















|
















<
<




















|














|









|












<
<







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
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
 * \return The object that caused the exception
 */
- (id)object;

/**
 * \return An error message for the exception as a C String
 */
- (const char*)cString;
@end

/**
 * An OFException indicating there is not enough memory available.
 */
@interface OFNoMemException: OFException
{
	size_t req_size;
}

/**


 * \param obj The object which caused the exception
 * \param size The size of the memory that couldn't be allocated
 * \return A new no memory exception
 */
+ newWithObject: (id)obj
	andSize: (size_t)size;

/**
 * Initializes an already allocated no memory exception.
 *
 * \param obj The object which caused the exception
 * \param size The size of the memory that couldn't be allocated
 * \return An initialized no memory exception
 */
- initWithObject: (id)obj
	 andSize: (size_t)size;

/**
 * \return An error message for the exception as a C String
 */
- (const char*)cString;

/**
 * \return The size of the memoory that couldn't be allocated
 */
- (size_t)requestedSize;
@end

/**
 * An OFException indicating the given memory is not part of the object.
 */
@interface OFMemNotPartOfObjException: OFException
{
	void *pointer;
}

/**


 * \param obj The object which caused the exception
 * \param ptr A pointer to the memory that is not part of the object
 * \return A new memory not part of object exception
 */
+ newWithObject: (id)obj
     andPointer: (void*)ptr;

/**
 * Initializes an already allocated memory not part of object exception.
 *
 * \param obj The object which caused the exception
 * \param ptr A pointer to the memory that is not part of the object
 * \return An initialized memory not part of object exception
 */
- initWithObject: (id)obj
      andPointer: (void*)ptr;

/**
 * \return An error message for the exception as a C String
 */
- (const char*)cString;

/**
 * \return A pointer to the memory which is not part of the object
 */
- (void*)pointer;
@end

/**
 * An OFException indicating the given value is out of range. 
 */
@interface OFOutOfRangeException: OFException {}
/**
 * \return An error message for the exception as a C String
 */
- (const char*)cString;
@end

/**
 * An OFException indicating that the conversation between two charsets failed.
 */
@interface OFCharsetConversionFailedException: OFException {}
/**
 * \return An error message for the exception as a C String
 */
- (const char*)cString;
@end

/**
 * An OFException indicating the file couldn't be opened.
 */
@interface OFOpenFileFailedException: OFException
{
	char *path;
	char *mode;
}

/**


 * \param obj The object which caused the exception
 * \param p A C string of the path to the file tried to open
 * \param m A C string of the mode in which the file should have been opened
 * \return A new open file failed exception
 */
+ newWithObject: (id)obj
	andPath: (const char*)p
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
	 andMode: (const char*)m;

- free;

/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;

/**
 * \return A C string of the path to the file which couldn't be opened
 */
- (char*)path;

/**







|







175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
	 andMode: (const char*)m;

- free;

/**
 * \return An error message for the exception as a C String
 */
- (const char*)cString;

/**
 * \return A C string of the path to the file which couldn't be opened
 */
- (char*)path;

/**
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
{
	size_t req_size;
	size_t req_items;
	BOOL has_items;
}

/**
 * Creates a new read or write failed exception.
 *
 * \param obj The object which caused the exception
 * \param size The requested size of the data that couldn't be read / written
 * \param nitems The requested number of items that couldn't be read / written
 * \return A new open file failed exception
 */
+ newWithObject: (id)obj
	andSize: (size_t)size
      andNItems: (size_t)nitems;

/**
 * Creates a new read or write failed exception.
 *
 * \param obj The object which caused the exception
 * \param size The requested size of the data that couldn't be read / written
 * \return A new open file failed exception
 */
+ newWithObject: (id)obj
	andSize: (size_t)size;








<
<










<
<







199
200
201
202
203
204
205


206
207
208
209
210
211
212
213
214
215


216
217
218
219
220
221
222
{
	size_t req_size;
	size_t req_items;
	BOOL has_items;
}

/**


 * \param obj The object which caused the exception
 * \param size The requested size of the data that couldn't be read / written
 * \param nitems The requested number of items that couldn't be read / written
 * \return A new open file failed exception
 */
+ newWithObject: (id)obj
	andSize: (size_t)size
      andNItems: (size_t)nitems;

/**


 * \param obj The object which caused the exception
 * \param size The requested size of the data that couldn't be read / written
 * \return A new open file failed exception
 */
+ newWithObject: (id)obj
	andSize: (size_t)size;

257
258
259
260
261
262
263





264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315















































 */
- (size_t)requestedSize;

/**
 * \return The requested number of items that coudln't be read / written
 */
- (size_t)requestedItems;





@end

/**
 * An OFException indicating a read to the file failed.
 */
@interface OFReadFailedException: OFReadOrWriteFailedException {}
/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;
@end

/**
 * An OFException indicating a write to the file failed.
 */
@interface OFWriteFailedException: OFReadOrWriteFailedException {}
/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;
@end

/**
 * An OFException indicating a socket is not connected or bound.
 */
@interface OFNotConnectedException: OFException {}
/**
 * \return An error message for the exception as a C string.
 */
- (char*)cString;
@end

/**
 * An OFException indicating an attempt to connect or bind an already connected
 * or bound socket 
 */
@interface OFAlreadyConnectedException: OFException {}
/**
 * \return An error message for the exception as a C string.
 */
- (char*)cString;
@end

/**
 * An OFException indicating that the specified port is invalid.
 */
@interface OFInvalidPortException: OFException
/**
 * \return An error message for the exception as a C string.
 */
- (char*)cString;
@end






















































>
>
>
>
>









|









|









|










|





|



|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
 */
- (size_t)requestedSize;

/**
 * \return The requested number of items that coudln't be read / written
 */
- (size_t)requestedItems;

/**
 * \return Whether NItems was specified
 */
- (BOOL)hasNItems;
@end

/**
 * An OFException indicating a read to the file failed.
 */
@interface OFReadFailedException: OFReadOrWriteFailedException {}
/**
 * \return An error message for the exception as a C String
 */
- (const char*)cString;
@end

/**
 * An OFException indicating a write to the file failed.
 */
@interface OFWriteFailedException: OFReadOrWriteFailedException {}
/**
 * \return An error message for the exception as a C String
 */
- (const char*)cString;
@end

/**
 * An OFException indicating a socket is not connected or bound.
 */
@interface OFNotConnectedException: OFException {}
/**
 * \return An error message for the exception as a C string.
 */
- (const char*)cString;
@end

/**
 * An OFException indicating an attempt to connect or bind an already connected
 * or bound socket 
 */
@interface OFAlreadyConnectedException: OFException {}
/**
 * \return An error message for the exception as a C string.
 */
- (const char*)cString;
@end

/**
 * An OFException indicating that the specified port is invalid.
 */
@interface OFInvalidPortException: OFException {}
/**
 * \return An error message for the exception as a C string.
 */
- (const char*)cString;
@end

/**
 * An OFException indicating the translation of an address failed.
 */
@interface OFAddressTranslationFailedException: OFException
{
	char *node;
	char *service;
}

/**
 * \param n The node for which translation was requested
 * \param s The service of the node for which translation was requested
 * \return A new address translation failed exception
 */
+ newWithObject: (id)obj
	andNode: (const char*)n
     andService: (const char*)s;

/**
 * Initializes an already allocated address translation failed exception.
 *
 * \param n The node for which translation was requested
 * \param s The service of the node for which translation was requested
 * \return An initialized address translation failed exception
 */
- initWithObject: (id)obj
	 andNode: (const char*)n
      andService: (const char*)s;

- free;

/**
 * \return An error message for the exception as a C string.
 */
- (const char*)cString;

/**
 * /return The node for which translation was requested
 */
- (const char*)node;

/**
 * \return The service of the node for which translation was requested
 */
- (const char*)service;
@end

Modified src/OFExceptions.m from [c1fe9bf0a6] to [a965c66066].

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
}

- (id)object
{
	return object;
}

- (char*)cString
{
	return string;
}
@end

@implementation OFNoMemException
+ newWithObject: (id)obj







|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
}

- (id)object
{
	return object;
}

- (const char*)cString
{
	return string;
}
@end

@implementation OFNoMemException
+ newWithObject: (id)obj
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{
	if ((self = [super initWithObject: obj]))
		req_size = size;

	return self;
}

- (char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "Could not allocate %zu bytes for object of class "
	    "%s!", req_size, object != nil ? [object name] : "(null)");








|







76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{
	if ((self = [super initWithObject: obj]))
		req_size = size;

	return self;
}

- (const char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "Could not allocate %zu bytes for object of class "
	    "%s!", req_size, object != nil ? [object name] : "(null)");

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
{
	if ((self = [super initWithObject: obj]))
		pointer = ptr;

	return self;
}

- (char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "Memory at %p was not allocated as part of object "
	    "of class %s, thus the memory allocation was not changed! It is "
	    "also possible that there was an attempt to free the same memory "
	    "twice.", pointer, [object name]);

	return string;
}

- (void*)pointer
{
	return pointer;
}
@end

@implementation OFOutOfRangeException
- (char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "Value out of range in object of class %s!",
	    object != nil ? [object name] : "(null)");

	return string;
}
@end

@implementation OFCharsetConversionFailedException
- (char*)cString
{
	if (string != NULL)
		return string;
	
	asprintf(&string, "Charset conversion failed in object of classs %s!",
	    [object name]);








|



















|












|







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
{
	if ((self = [super initWithObject: obj]))
		pointer = ptr;

	return self;
}

- (const char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "Memory at %p was not allocated as part of object "
	    "of class %s, thus the memory allocation was not changed! It is "
	    "also possible that there was an attempt to free the same memory "
	    "twice.", pointer, [object name]);

	return string;
}

- (void*)pointer
{
	return pointer;
}
@end

@implementation OFOutOfRangeException
- (const char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "Value out of range in object of class %s!",
	    object != nil ? [object name] : "(null)");

	return string;
}
@end

@implementation OFCharsetConversionFailedException
- (const char*)cString
{
	if (string != NULL)
		return string;
	
	asprintf(&string, "Charset conversion failed in object of classs %s!",
	    [object name]);

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
200
201
}

- initWithObject: (id)obj
	 andPath: (const char*)p
	 andMode: (const char*)m
{
	if ((self = [super initWithObject: obj])) {
		path = p != NULL ? strdup(p) : NULL;
		mode = m != NULL ? strdup(m) : NULL;
	}

	return self;
}

- free
{
	if (path != NULL)
		free(path);
	if (mode != NULL)
		free(mode);

	return [super free];
}

- (char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "Failed to open file %s with mode %s in object of "
	    "class %s!", path, mode, [self name]);








|
|















|







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
200
201
}

- initWithObject: (id)obj
	 andPath: (const char*)p
	 andMode: (const char*)m
{
	if ((self = [super initWithObject: obj])) {
		path = (p != NULL ? strdup(p) : NULL);
		mode = (m != NULL ? strdup(m) : NULL);
	}

	return self;
}

- free
{
	if (path != NULL)
		free(path);
	if (mode != NULL)
		free(mode);

	return [super free];
}

- (const char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "Failed to open file %s with mode %s in object of "
	    "class %s!", path, mode, [self name]);

260
261
262
263
264
265
266





267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341


























































	return req_size;
}

- (size_t)requestedItems
{
	return req_items;
}





@end

@implementation OFReadFailedException
- (char*)cString
{
	if (string != NULL)
		return string;;

	if (has_items)
		asprintf(&string, "Failed to read %zu items of size %zu in "
		    "object of class %s!", req_items, req_size, [object name]);
	else
		asprintf(&string, "Failed to read %zu bytes in object of class "
		    "%s!", req_size, [object name]);

	return string;
}
@end

@implementation OFWriteFailedException
- (char*)cString
{
	if (string != NULL)
		return string;

	if (has_items)
		asprintf(&string, "Failed to write %zu items of size %zu in "
		    "object of class %s!", req_items, req_size, [object name]);
	else
		asprintf(&string, "Failed to write %zu bytes in object of "
		    "class %s!", req_size, [object name]);

	return string;
}
@end

@implementation OFNotConnectedException
- (char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "The socket of type %s is not connected or bound!",
	    [object name]);

	return string;
}
@end

@implementation OFAlreadyConnectedException
- (char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "The socket of type %s is already connected or bound "
	    "and thus can't be connected or bound again!", [object name]);

	return string;
}
@end

@implementation OFInvalidPortException
- (char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "The port specified is not valid for a socket of "
	    "type %s! This usually means you tried to use port 0, which is an "
	    "invalid port.", [object name]);

	return string;
}
@end

































































>
>
>
>
>



|
















|
















|












|












|











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
	return req_size;
}

- (size_t)requestedItems
{
	return req_items;
}

- (BOOL)hasNItems
{
	return has_items;
}
@end

@implementation OFReadFailedException
- (const char*)cString
{
	if (string != NULL)
		return string;;

	if (has_items)
		asprintf(&string, "Failed to read %zu items of size %zu in "
		    "object of class %s!", req_items, req_size, [object name]);
	else
		asprintf(&string, "Failed to read %zu bytes in object of class "
		    "%s!", req_size, [object name]);

	return string;
}
@end

@implementation OFWriteFailedException
- (const char*)cString
{
	if (string != NULL)
		return string;

	if (has_items)
		asprintf(&string, "Failed to write %zu items of size %zu in "
		    "object of class %s!", req_items, req_size, [object name]);
	else
		asprintf(&string, "Failed to write %zu bytes in object of "
		    "class %s!", req_size, [object name]);

	return string;
}
@end

@implementation OFNotConnectedException
- (const char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "The socket of type %s is not connected or bound!",
	    [object name]);

	return string;
}
@end

@implementation OFAlreadyConnectedException
- (const char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "The socket of type %s is already connected or bound "
	    "and thus can't be connected or bound again!", [object name]);

	return string;
}
@end

@implementation OFInvalidPortException
- (const char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "The port specified is not valid for a socket of "
	    "type %s! This usually means you tried to use port 0, which is an "
	    "invalid port.", [object name]);

	return string;
}
@end

@implementation OFAddressTranslationFailedException
+ newWithObject: (id)obj
	andNode: (const char*)n
     andService: (const char*)s
{
	return [self newWithObject: obj
			   andNode: n
			andService: s];
}

- initWithObject: (id)obj
	 andNode: (const char*)n
      andService: (const char*)s
{
	if ((self = [super initWithObject: obj])) {
		node = (n != NULL ? strdup(n) : NULL);
		service = (s != NULL ? strdup(s) : NULL);
	}

	return self;
}

- free
{
	if (node != NULL)
		free(node);
	if (service != NULL)
		free(node);

	return [super free];
}

- (const char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "The specified node with the specified service could "
	    "not be translated to an address for an object of type %s. This "
	    "means that either the node was not found, there is no such "
	    "service on the specified node, there was a problem with the name "
	    "server, there was a problem with your network connection or you "
	    "specified an invalid node or service.", [object name]);

	return string;
}

- (const char*)node
{
	return node;
}

- (const char*)service
{
	return service;
}
@end

Modified src/OFString.h from [02ec2a897c] to [d8d41ef5ac].

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
 * Initializes an already allocated OFString from a wide C string.
 * 
 * \param str A wide C string to initialize the OFString with
 * \return An initialized OFString
 */
- initFromWideCString: (const wchar_t*)str;

/**
 * \return The OFString as a C string, if possible (if not, returns NULL).
 *         If not needed anymore, it is usefull to call freeMem:.
 */
- (char*)getCString;

/**
 * \return The OFString as a wide C string
 */
- (wchar_t*)wideCString;

/**
 * \return The length of the OFString
 */
- (size_t)length;







/**
 * Clones the OFString, creating a new one.
 * 
 * \return A copy of the OFString
 */
- (OFString*)clone;








<
<
<
<
<
<



|






>
>
>
>
>
>







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
 * Initializes an already allocated OFString from a wide C string.
 * 
 * \param str A wide C string to initialize the OFString with
 * \return An initialized OFString
 */
- initFromWideCString: (const wchar_t*)str;







/**
 * \return The OFString as a wide C string
 */
- (const wchar_t*)wideCString;

/**
 * \return The length of the OFString
 */
- (size_t)length;

/**
 * \return The OFString as a C string, if possible (if not, returns NULL).
 *         If not needed anymore, it is usefull to call freeMem:.
 */
- (char*)getCString;

/**
 * Clones the OFString, creating a new one.
 * 
 * \return A copy of the OFString
 */
- (OFString*)clone;

Modified src/OFString.m from [f6358fc52b] to [9f7f197b86].

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
						ofSize: sizeof(wchar_t)];
			wmemcpy(string, str, length + 1);
		}
	}

	return self;
}











- (char*)getCString
{
	char *str;
	size_t len;

	if ((len = wcstombs(NULL, string, 0)) == (size_t)-1)
		@throw [OFCharsetConversionFailedException newWithObject: self];

	str = [self getMemWithSize: len + 1];

	if (wcstombs(str, string, len + 1) != len) {
		[self freeMem: str];
		@throw [OFCharsetConversionFailedException newWithObject: self];
	}

	return str;
}

- (wchar_t*)wideCString
{
	return string;
}

- (size_t)length
{
	return length;
}

- (OFString*)clone
{
	return [OFString newFromWideCString: string];
}

- (OFString*)setTo: (OFString*)str
{







>
>
>
>
>
>
>
>
>
>



















<
<
<
<
<
<
<
<
<
<







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
						ofSize: sizeof(wchar_t)];
			wmemcpy(string, str, length + 1);
		}
	}

	return self;
}

- (const wchar_t*)wideCString
{
	return string;
}

- (size_t)length
{
	return length;
}

- (char*)getCString
{
	char *str;
	size_t len;

	if ((len = wcstombs(NULL, string, 0)) == (size_t)-1)
		@throw [OFCharsetConversionFailedException newWithObject: self];

	str = [self getMemWithSize: len + 1];

	if (wcstombs(str, string, len + 1) != len) {
		[self freeMem: str];
		@throw [OFCharsetConversionFailedException newWithObject: self];
	}

	return str;
}











- (OFString*)clone
{
	return [OFString newFromWideCString: string];
}

- (OFString*)setTo: (OFString*)str
{