ObjFW  Check-in [cc2e866e55]

Overview
Comment:Let OFString's setTo: use const char* instead of OFString*.
This is far more useful.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cc2e866e5579a70e1bd6207327735e6072f9e5e8f2a41f4cef5efabf7d2f833c
User & Date: js on 2009-02-14 19:04:50
Other Links: manifest | tags
Context
2009-02-14
20:15
Add intmax_t and uintmax_t to OFNumber. check-in: db131a629c user: js tags: trunk
19:04
Let OFString's setTo: use const char* instead of OFString*.
This is far more useful.
check-in: cc2e866e55 user: js tags: trunk
17:26
Always use #include for libc headers due to glibc being broken.
Do the same for win32 headers, just in case. They should work with
#import, but you never know ;).
check-in: 029511474c user: js tags: trunk
Changes

Modified src/OFString.h from [6a1a0bcc55] to [eac68d8a40].

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
- (id)copy;

/**
 * Sets the OFString to the specified OFString.
 *
 * \param str An OFString to set the OFString to.
 */
- setTo: (OFString*)str;

/**
 * Append another OFString to the OFString.
 *
 * \param str An OFString to append
 */
- append: (OFString*)str;







|







111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
- (id)copy;

/**
 * Sets the OFString to the specified OFString.
 *
 * \param str An OFString to set the OFString to.
 */
- setTo: (const char*)str;

/**
 * Append another OFString to the OFString.
 *
 * \param str An OFString to append
 */
- append: (OFString*)str;

Modified src/OFString.m from [8d074bf70b] to [6c57bbac26].

238
239
240
241
242
243
244
245
246
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
}

- (id)copy
{
	return [OFString stringWithCString: string];
}

- setTo: (OFString*)str
{
	size_t len;

	if (string != NULL)
		free(string);

	len = [str length];

	switch (check_utf8([str cString], len)) {
	case 1:
		is_utf8 = YES;
		break;
	case -1:
		string = NULL;
		length = 0;
		is_utf8 = NO;

		@throw [OFInvalidEncodingException newWithClass: [self class]];
	}

	length = len;
	string = [self getMemWithSize: length + 1];
	memcpy(string, [str cString], length + 1);

	return self;
}

- (BOOL)isEqual: (id)obj
{
	if (![obj isKindOf: [OFString class]])







|






|

|













|







238
239
240
241
242
243
244
245
246
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
}

- (id)copy
{
	return [OFString stringWithCString: string];
}

- setTo: (const char*)str
{
	size_t len;

	if (string != NULL)
		free(string);

	len = strlen(str);

	switch (check_utf8(str, len)) {
	case 1:
		is_utf8 = YES;
		break;
	case -1:
		string = NULL;
		length = 0;
		is_utf8 = NO;

		@throw [OFInvalidEncodingException newWithClass: [self class]];
	}

	length = len;
	string = [self getMemWithSize: length + 1];
	memcpy(string, str, length + 1);

	return self;
}

- (BOOL)isEqual: (id)obj
{
	if (![obj isKindOf: [OFString class]])

Modified tests/OFString/OFString.m from [d1e8e561ed] to [0abd9793f1].

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

	s3 = [s1 copy];

	CHECK([s1 isEqual: s3])
	CHECK(![s1 isEqual: [OFObject new]]);

	[s2 appendCString: "123"];
	[s4 setTo: s2];

	CHECK(![s2 compare: s4])
	CHECK(!strcmp([[s1 append: s2] cString], "test123"))
	CHECK(strlen([s1 cString]) == [s1 length] && [s1 length] == 7)
	CHECK(!strcmp([[s1 reverse] cString], "321tset"))
	CHECK(!strcmp([[s1 upper] cString], "321TSET"))
	CHECK(!strcmp([[s1 lower] cString], "321tset"))







|







63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

	s3 = [s1 copy];

	CHECK([s1 isEqual: s3])
	CHECK(![s1 isEqual: [OFObject new]]);

	[s2 appendCString: "123"];
	[s4 setTo: [s2 cString]];

	CHECK(![s2 compare: s4])
	CHECK(!strcmp([[s1 append: s2] cString], "test123"))
	CHECK(strlen([s1 cString]) == [s1 length] && [s1 length] == 7)
	CHECK(!strcmp([[s1 reverse] cString], "321tset"))
	CHECK(!strcmp([[s1 upper] cString], "321TSET"))
	CHECK(!strcmp([[s1 lower] cString], "321tset"))