ObjFW  Diff

Differences From Artifact [53999e7524]:

To Artifact [c26b0e5b15]:


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
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
112

113
114
115
116







-

+

-

+
+
+





-
-
-
-
-
-
-










-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

+
-
-
+
+
+









-
+




-
-
+
+
-
-




-
+
+

-
+








-
+
+
+

	return [self init:NULL];
}

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

- free
{
	if (string != NULL)
		free(string);
	return [super free];
}

- (char*)cString
{
	return string;
}

- (size_t)length
{
	return length;
}

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

		length = 0;
		string = NULL;

		return self;
	}

	newlen = strlen(str);
	if ((newstr = [self getMem:newlen]) == NULL)
		return nil;
	memcpy(newstr, str, newlen);

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

	length = newlen;
	string = strdup(str);
	length = strlen(str);
	string = newstr;

	return self;
}

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

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

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

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

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

	string = new_string;

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

	length = new_length;
}

	return self;
}
@end