ObjFW  Diff

Differences From Artifact [ec546376b0]:

To Artifact [7b8481ed3a]:


27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41







-
+







- init:(const char*)str
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = strlen(string);
			length = strlen(str);
			if ((string = [self getMem:length]) == NULL)
				return NULL;
			memcpy(string, str, length);
		}
	}
	return self;
}
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
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







-
-
+
-




-
-
+
+




-
-
+
+

-
-
+




-
+

-
-
+
+

-
+




	string = newstr;

	return self;
}

- (OFString*)clone
{
	if (string != NULL)
		return [OFString new:string];
	return [OFString new:string];
	return [OFString new];
}

- (OFString*)append: (const char*)str
{
	char	*new_string;
	size_t	new_length, str_length;
	char	*newstr;
	size_t	newlen, strlength;

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

	str_length = strlen(str);
	new_length = length + str_length;
	strlength = strlen(str);
	newlen = length + strlength;

	if ((new_string =
	    [self resizeMem:string toSize:new_length + 1]) == NULL) {
	if ((newstr = [self resizeMem:string toSize:newlen + 1]) == NULL) {
		/* FIXME: Add error handling */
		return nil;
	}

	string = new_string;
	string = newstr;

	memcpy(string + length, str, str_length);
	string[new_length] = '\0';
	memcpy(string + length, str, strlength);
	string[newlen] = '\0';

	length = new_length;
	length = newlen;

	return self;
}
@end