ObjFW  Diff

Differences From Artifact [7c7b5b7fed]:

To Artifact [f753114c1f]:


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

	madvise((void*)str, len, MADV_NORMAL);

	return (utf8 ? 1 : 0);
}

@implementation OFString





+ newFromCString: (const char*)str
{
	return [[self alloc] initFromCString: str];
}

+ newFromFormatCString: (const char*)fmt, ...
{
	id ret;
	va_list args;

	va_start(args, fmt);
	ret = [[self alloc] initFromFormatCString: fmt
				    withArguments: args];
	va_end(args);

	return ret;
}

+ newFromFormatCString: (const char*)fmt
	 withArguments: (va_list)args
{
	return [[self alloc] initFromFormatCString: fmt
				     withArguments: args];
}

- init
{
	if ((self = [super init])) {
		length = 0;
		string = NULL;
		is_utf8 = NO;
	}

	return self;
}

- initFromCString: (const char*)str
{
	Class c;

	if ((self = [super init])) {
		if (str != NULL) {
			length = strlen(str);








>
>
>
>
>
|

|


|





|
|





|
|

|
|













|







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

	madvise((void*)str, len, MADV_NORMAL);

	return (utf8 ? 1 : 0);
}

@implementation OFString
+ string
{
	return [[[self alloc] init] autorelease];
}

+ stringWithCString: (const char*)str
{
	return [[[self alloc] initWithCString: str] autorelease];
}

+ stringWithFormat: (const char*)fmt, ...
{
	id ret;
	va_list args;

	va_start(args, fmt);
	ret = [[[self alloc] initWithFormat: fmt
			       andArguments: args] autorelease];
	va_end(args);

	return ret;
}

+ stringWithFormat: (const char*)fmt
      andArguments: (va_list)args
{
	return [[[self alloc] initWithFormat: fmt
				andArguments: args] autorelease];
}

- init
{
	if ((self = [super init])) {
		length = 0;
		string = NULL;
		is_utf8 = NO;
	}

	return self;
}

- initWithCString: (const char*)str
{
	Class c;

	if ((self = [super init])) {
		if (str != NULL) {
			length = strlen(str);

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
			memcpy(string, str, length + 1);
		}
	}

	return self;
}

- initFromFormatCString: (const char*)fmt, ...
{
	id ret;
	va_list args;

	va_start(args, fmt);
	ret = [self initFromFormatCString: fmt
			    withArguments: args];
	va_end(args);

	return ret;
}

- initFromFormatCString: (const char*)fmt
	  withArguments: (va_list)args
{
	int t;
	Class c;

	if ((self = [super init])) {
		if (fmt == NULL) {
			c = [self class];







|





|
|





|
|







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
			memcpy(string, str, length + 1);
		}
	}

	return self;
}

- initWithFormat: (const char*)fmt, ...
{
	id ret;
	va_list args;

	va_start(args, fmt);
	ret = [self initWithFormat: fmt
		      andArguments: args];
	va_end(args);

	return ret;
}

- initWithFormat: (const char*)fmt
    andArguments: (va_list)args
{
	int t;
	Class c;

	if ((self = [super init])) {
		if (fmt == NULL) {
			c = [self class];
230
231
232
233
234
235
236
237
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
- (size_t)length
{
	return length;
}

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

- setTo: (OFString*)str
{

	[self free];





















	return (self = [str clone]);
}

- (int)compareTo: (OFString*)str
{
	return strcmp(string, [str cString]);
}

- append: (OFString*)str
{
	return [self appendCString: [str cString]];
}

- appendCString: (const char*)str
{
	char   *newstr;
	size_t newlen, strlength;

	if (string == NULL)
		return [self setTo: [OFString newFromCString: str]];

	strlength = strlen(str);

	switch (check_utf8(str, strlength)) {
	case 1:
		is_utf8 = YES;
		break;
	case -1:







|




>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|

















<
<
<







235
236
237
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
276
277
278
279
280
281
282
283
284
285
286
287



288
289
290
291
292
293
294
- (size_t)length
{
	return length;
}

- (OFString*)clone
{
	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;
}

- (int)compareTo: (OFString*)str
{
	return strcmp(string, [str cString]);
}

- append: (OFString*)str
{
	return [self appendCString: [str cString]];
}

- appendCString: (const char*)str
{
	char   *newstr;
	size_t newlen, strlength;




	strlength = strlen(str);

	switch (check_utf8(str, strlength)) {
	case 1:
		is_utf8 = YES;
		break;
	case -1: