ObjFW  Diff

Differences From Artifact [68b2726756]:

To Artifact [3e627dd8f1]:


1
2
3
4
5
6
7
8
9
10
11
12
13

14




15
16
17
18
19
20
21
22
23

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


40
41
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
/*
 * Copyright (c) 2008
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import <stdlib.h>
#import <string.h>

#import "OFString.h"




#import "OFExceptions.h"

@implementation OFString
+ new: (const char*)str
{
	return [[OFString alloc] init: str];
}

- init

{
	return [self init: NULL];
}

- init: (const char*)str
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = strlen(str);
			string = [self getMem: length + 1];
			memcpy(string, str, length + 1);
		}
	}


	return self;
}

- (char*)cString
{

	return string;






}

- (size_t)length
{
	return length;
}

- (OFString*)setTo: (OFConstString*)str
{
	char *newstr;
	size_t newlen;
	
	if ([str cString] == NULL) {
		[self freeMem: string];

		length = 0;
		string = NULL;

		return self;
	}

	newlen = [str length];
	newstr = [self getMem: newlen + 1];
	memcpy(newstr, [str cString], newlen + 1);

	if (string != NULL)
		[self freeMem: string];

	length = newlen;
	string = newstr;

	return self;
}

- (OFString*)clone
{

	return [OFString new: string];
}

- (OFString*)append: (OFConstString*)str
{
	char   *newstr;
	size_t newlen, strlength;

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

	strlength = [str length];
	newlen = length + strlength;

	newstr = [self resizeMem: string
			  toSize: newlen + 1];

	memcpy(newstr + length, [str cString], strlength + 1);

	length = newlen;
	string = newstr;

	return self;
}

- (int)compare: (OFConstString*)str
{
	return strcmp(string, [str cString]);
}
@end













>

>
>
>
>



|

|


<
>

|


|

<
<
<
|
<
<
<
<
|
|
>
>
|




>
|
>
>
>
>
>
>







|

<
<
<
<
|
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<





>
|


|

<
<
|
<
|
|
<
<

<
<
|
<
|
<
<
|
|

<
<
<
<
<

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34



35




36
37
38
39
40
41
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
/*
 * Copyright (c) 2008
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import <stdlib.h>
#import <string.h>

#import "OFString.h"
#import "OFConstCString.h"
#import "OFConstWideCString.h"
#import "OFCString.h"
#import "OFWideCString.h"
#import "OFExceptions.h"

@implementation OFString
+ newWithConstCString: (const char*)str
{
	return [[OFConstCString alloc] initWithConstCString: str];
}


+ newWithConstWideCString: (const wchar_t*)str
{
	return [[OFConstWideCString alloc] initWithConstWideCString: str];
}

+ newWithCString: (char*)str
{



	return [[OFCString alloc] initWithCString: str];




}

+ newWithWideCString: (wchar_t*)str
{
	return [[OFWideCString alloc] initWithWideCString: str];
}

- (char*)cString
{
	@throw [OFNotImplementedException new: self withMethod: "cString"];
	return NULL;
}

- (wchar_t*)wcString
{
	@throw [OFNotImplementedException new: self withMethod: "wcString"];
	return NULL;
}

- (size_t)length
{
	return length;
}

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




	[self free];







	self = [str clone];









	return self;
}

- (OFString*)clone
{
	@throw [OFNotImplementedException new: self withMethod: "clone"];
	return nil;
}

- (int)compare: (OFString*)str
{


	@throw [OFNotImplementedException new: self withMethod: "compare:"];

	return 0;
}





- (OFString*)append: (OFString*)str

{


	@throw [OFNotImplementedException new: self withMethod: "append:"];
	return nil;
}





@end