ObjFW  Diff

Differences From Artifact [c5b8e74c51]:

To Artifact [c3388d8ecc]:


8
9
10
11
12
13
14

15
16
17
18

19
20
21
22
23
24
25
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import "config.h"

#include <stdarg.h>

#include <string.h>

#import "OFString.h"
#import "OFMutableString.h"

#import "OFExceptions.h"
#import "OFMacros.h"

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







>




>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import "config.h"

#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#import "OFString.h"
#import "OFMutableString.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "OFMacros.h"

@implementation OFString
+ string
{
	return [[[OFMutableString alloc] init] autorelease];
150
151
152
153
154
155
156























































157
}

- lower
{
	@throw [OFNotImplementedException newWithClass: isa
					   andSelector: _cmd];
}























































@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
}

- lower
{
	@throw [OFNotImplementedException newWithClass: isa
					   andSelector: _cmd];
}

- (OFArray*)splitWithDelimiter: (OFString*)delimiter
{
	OFAutoreleasePool *pool;
	OFArray *array = [[OFArray alloc] init];
	const char *delim = [delimiter cString];
	size_t delim_len = [delimiter length];
	size_t i, last;

	@try {
		pool = [[OFAutoreleasePool alloc] init];
	} @catch (OFException *e) {
		[array release];
		@throw e;
	}

	@try {
		for (i = 0, last = 0; i <= length; i++) {
			if (OF_UNLIKELY(i == length ||
			    !memcmp(string + i, delim, delim_len))) {
				OFString *str;
				char *tmp;

				/*
				 * We can't use [self allocWithSize:] here as
				 * self might be a @""-literal.
				 */
				if ((tmp = malloc(i - last + 1)) == NULL)
					@throw [OFNoMemException
					    newWithClass: isa
						 andSize: i - last + 1];
				memcpy(tmp, string + last, i - last);
				tmp[i - last] = '\0';
				@try {
					str = [OFString stringWithCString: tmp];
				} @finally {
					free(tmp);
				}

				[array add: str];
				[pool releaseObjects];

				i += delim_len - 1;
				last = i + 1;
			}
		}
	} @catch (OFException *e) {
		[array release];
		@throw e;
	} @finally {
		[pool release];
	}

	return [array autorelease];
}
@end