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
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
+ new: (const char*)str
+ newWithConstCString: (const char*)str
{
	return [[OFString alloc] init: str];
	return [[OFConstCString alloc] initWithConstCString: str];
}

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

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

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

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

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

- (size_t)length
{
	return length;
}

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

		length = 0;
		string = NULL;

		return self;
	}

	newlen = [str length];
	self = [str clone];
	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
{
	@throw [OFNotImplementedException new: self withMethod: "clone"];
	return [OFString new: string];
	return nil;
}

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

	@throw [OFNotImplementedException new: self withMethod: "compare:"];
	if (str == NULL)
		return [self setTo: str];

	return 0;
}
	strlength = [str length];
	newlen = length + strlength;

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

- (OFString*)append: (OFString*)str
	memcpy(newstr + length, [str cString], strlength + 1);

{
	length = newlen;
	string = newstr;

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

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