ObjFW  Check-in [cf85bee74f]

Overview
Comment:Reworked String API.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cf85bee74f29b61b79fcfaa0cec70db1328f64b936da3c8a521fdb85eef4aa92
User & Date: js on 2008-10-05 19:20:33
Other Links: manifest | tags
Context
2008-10-07
17:18
Added OFFile. check-in: 71119a787b user: js tags: trunk
2008-10-05
19:20
Reworked String API. check-in: cf85bee74f user: js tags: trunk
2008-09-15
11:02
API change. check-in: c7f702cc69 user: js tags: trunk
Changes

Modified src/Makefile from [2b071b3432] to [be14b6ad32].

1
2
3
4
5
6



7
8
9
10
11
12

13
14

15
16
17
18
19
20
21
1
2
3
4


5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23




-
-
+
+
+





-
+


+







LIB = ${LIB_PREFIX}objfw${LIB_SUFFIX}
LIB_MAJOR = 1
LIB_MINOR = 0

SRCS = OFConstString.m		\
       OFConstWideString.m	\
SRCS = OFConstCString.m		\
       OFCString.m		\
       OFConstWideCString.m	\
       OFExceptions.m		\
       OFList.m			\
       OFListObject.m		\
       OFObject.m		\
       OFString.m		\
       OFWideString.m
       OFWideCString.m

INCLUDES = OFConstString.h	\
	   OFCString.h		\
	   OFConstWideString.h	\
	   OFExceptions.h	\
	   OFList.h		\
	   OFListObject.h	\
	   OFObject.h		\
	   OFString.h		\
	   OFWideString.h

Added src/OFCString.h version [b9bde22b67].




























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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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 <stddef.h>

#import "OFObject.h"
#import "OFString.h"

@interface OFCString: OFString
{
	char   *string;
}

- initWithCString: (char*)str;
- (char*)cString;
- (OFString*)clone;
- (int)compare: (OFString*)str;
- (OFString*)append: (OFString*)str;
@end

Added src/OFCString.m version [b967cecc4b].







































































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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 "OFCString.h"
#import "OFExceptions.h"

@implementation OFCString
- initWithCString: (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;
}

- (OFString*)clone
{
	return [OFString newWithCString: string];
}

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

- (OFString*)append: (OFString*)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;
}
@end

Added src/OFConstCString.h version [d27a028e68].
























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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 "OFString.h"

@interface OFConstCString: OFString
{
	const char *string;
}

- initWithConstCString: (const char*)str;
- (const char*)cString;
- (OFString*)clone;
- (int)compare: (OFString*)str;
@end

Added src/OFConstCString.m version [d6fb406d96].













































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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 <string.h>
#import "OFConstCString.h"

@implementation OFConstCString
- initWithConstCString: (const char*)str
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = strlen(str);
			string = str;
		}
	}
	return self;
}

- (const char*)cString
{
	return string;
}

- (OFString*)clone
{
	return [OFString newWithConstCString: string];
}

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

Deleted src/OFConstString.h version [8a959a6c98].

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



























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * 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 <stddef.h>
#import "OFObject.h"

@interface OFConstString: OFObject
{
	const char *string;
	size_t	   length;
}

+ new: (const char*)str;
- init;
- init: (const char*)str;
- (const char*)cString;
- (size_t)length;
- (int)compare: (OFConstString*)str;
@end

Deleted src/OFConstString.m version [59a339f3e5].

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






















































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * 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 <string.h>
#import "OFConstString.h"

@implementation OFConstString
+ new: (const char*)str
{
	return [[OFConstString 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 = str;
		}
	}
	return self;
}

- (const char*)cString
{
	return string;
}

- (size_t)length
{
	return length;
}

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

Added src/OFConstWideCString.h version [357f188ce4].


























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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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 <wchar.h>
#import <stddef.h>
#import "OFString.h"

@interface OFConstWideCString: OFString
{
	const wchar_t *string;
}

- initWithConstWideCString: (const wchar_t*)wstr;
- (const wchar_t*)wcString;
- (OFString*)clone;
- (int)compare: (OFString*)str;
@end

Added src/OFConstWideCString.m version [1c21e29078].













































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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 <wchar.h>
#import "OFConstWideCString.h"

@implementation OFConstWideCString
- initWithConstWideCString: (const wchar_t*)str
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = wcslen(str);
			string = str;
		}
	}
	return self;
}

- (const wchar_t*)wcString
{
	return string;
}

- (OFString*)clone
{
	return [OFString newWithConstWideCString: string];
}

- (int)compare: (OFString*)str
{
	return wcscmp(string, [str wcString]);
}
@end

Deleted src/OFConstWideString.h version [03dfdece23].

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




























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * 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 <stddef.h>
#import <wchar.h>
#import "OFObject.h"

@interface OFConstWideString: OFObject
{
	const wchar_t *wstring;
	size_t	      length;
}

+ new: (const wchar_t*)wstr;
- init;
- init: (const wchar_t*)wstr;
- (const wchar_t*)wcString;
- (size_t)length;
- (int)compare: (OFConstWideString*)str;
@end

Deleted src/OFConstWideString.m version [c0a8ed45c4].

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






















































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * 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 <wchar.h>
#import "OFConstWideString.h"

@implementation OFConstWideString
+ new: (const wchar_t*)wstr
{
	return [[OFConstWideString alloc] init: wstr];
}

- init
{
	return [self init: NULL];
}

- init: (const wchar_t*)wstr
{
	if ((self = [super init])) {
		if (wstr == NULL) {
			length = 0;
			wstring = NULL;
		} else {
			length = wcslen(wstr);
			wstring = wstr;
		}
	}
	return self;
}

- (const wchar_t*)wcString
{
	return wstring;
}

- (size_t)length
{
	return length;
}

- (int)compare: (OFConstWideString*)str
{
	return wcscmp(wstring, [str wcString]);
}
@end

Modified src/OFExceptions.h from [03ab1df298] to [da96e169ec].

19
20
21
22
23
24
25







26
27
28
29
30
31
32
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39







+
+
+
+
+
+
+








@interface OFNoMemException: OFException
+      new: (id)obj
  withSize: (size_t)size;
-     init: (id)obj
  withSize: (size_t)size;
@end

@interface OFNotImplementedException: OFException
+	 new: (id)obj
  withMethod: (const char*)method;
-       init: (id)obj
  withMethod: (const char*)method;
@end

@interface OFMemNotPartOfObjException: OFException
+     new: (id)obj
  withPtr: (void*)ptr;
-    init: (id)obj
  withPtr: (void*)ptr;
@end

Modified src/OFExceptions.m from [f7b03ef0d0] to [864964c046].

33
34
35
36
37
38
39

40
















41
42
43
44
45
46
47
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







+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







}

-     init: (id)obj
  withSize: (size_t)size
{
	fprintf(stderr, "ERROR: Could not allocate %zu bytes for object %s!\n",
	    size, [obj name]);
	return [super init];

}
@end

@implementation OFNotImplementedException
+        new: (id)obj
  withMethod: (const char*)method
{
	return [[OFNotImplementedException alloc] init: obj
					    withMethod: method];
}

-       init: (id)obj
  withMethod: (const char*)method
{
	fprintf(stderr, "ERROR: Requested method %s not implemented in %s!\n",
	    method, [obj name]);
	return [super init];
}
@end

@implementation OFMemNotPartOfObjException
+     new: (id)obj
  withPtr: (void*)ptr

Modified src/OFString.h from [236184ed79] to [9a4ef12426].

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











+


-



-



-
-
-
+
+
+
+

+

-
+

+
-
+
-

/*
 * 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 <wchar.h>
#import <stddef.h>
#import "OFObject.h"
#import "OFConstString.h"

@interface OFString: OFObject
{
	char   *string;
	size_t length;
}

+ new: (const char*)str;
- init;
- init: (const char*)str;
+ newWithConstCString: (const char*)str;
+ newWithConstWideCString: (const wchar_t*)str;
+ newWithCString: (char*)str;
+ newWithWideCString: (wchar_t*)str;
- (char*)cString;
- (wchar_t*)wcString;
- (size_t)length;
- (OFString*)setTo: (OFConstString*)str;
- (OFString*)setTo: (OFString*)str;
- (OFString*)clone;
- (int)compare: (OFString*)str;
- (OFString*)append: (OFConstString*)str;
- (OFString*)append: (OFString*)str;
- (int)compare: (OFConstString*)str;
@end

Modified src/OFString.m from [68b2726756] to [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

Added src/OFWideCString.h version [80e2b819bc].




























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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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 <wchar.h>
#import <stddef.h>

#import "OFString.h"

@interface OFWideCString: OFString
{
	wchar_t	*string;
}

- initWithWideCString: (wchar_t*)str;
- (wchar_t*)wcString;
- (OFString*)clone;
- (int)compare: (OFString*)str;
- (OFString*)append: (OFString*)str;
@end

Added src/OFWideCString.m version [87572356ea].







































































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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 <wchar.h>
#import "OFWideCString.h"
#import "OFExceptions.h"

@implementation OFWideCString
- initWithWideCString: (wchar_t*)str
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = wcslen(str);
			string = [self getMem: (length + 1) * sizeof(wchar_t)];
			wmemcpy(string, str, length + 1);
		}
	}
	return self;
}

- (wchar_t*)wcString
{
	return string;
}

- (OFString*)clone
{
	return [OFString newWithWideCString: string];
}

- (int)compare: (OFString*)str
{
	return wcscmp(string, [str wcString]);
}

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

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

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

	newstr = [self resizeMem: string
			  toSize: (newlen + 1) * sizeof(wchar_t)];

	wmemcpy(newstr + length, [str wcString], strlength + 1);

	length = newlen;
	string = newstr;

	return self;
}
@end

Deleted src/OFWideString.h version [fa40106b5c].

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

































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * 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 <stddef.h>
#import <wchar.h>

#import "OFObject.h"
#import "OFConstWideString.h"

@interface OFWideString: OFObject
{
	wchar_t	*wstring;
	size_t	length;
}

+ new: (const wchar_t*)wstr;
- init;
- init: (const wchar_t*)wstr;
- (wchar_t*)wcString;
- (size_t)length;
- (OFWideString*)setTo: (OFConstWideString*)wstr;
- (OFWideString*)clone;
- (OFWideString*)append: (OFConstWideString*)wstr;
- (int)compare: (OFConstWideString*)str;
@end

Deleted src/OFWideString.m version [ffeec9ddfb].

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
112
















































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * 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 <wchar.h>
#import "OFWideString.h"
#import "OFExceptions.h"

@implementation OFWideString
+ new: (const wchar_t*)wstr
{
	return [[OFWideString alloc] init: wstr];
}

- init
{
	return [self init: NULL];
}

- init: (const wchar_t*)wstr
{
	if ((self = [super init])) {
		if (wstr == NULL) {
			length = 0;
			wstring = NULL;
		} else {
			length = wcslen(wstr);
			wstring = [self getMem: (length + 1) * sizeof(wchar_t)];
			wmemcpy(wstring, wstr, length + 1);
		}
	}
	return self;
}

- (wchar_t*)wcString
{
	return wstring;
}

- (size_t)length
{
	return length;
}

- (OFWideString*)setTo: (OFConstWideString*)wstr
{
	wchar_t *newstr;
	size_t  newlen;
	
	if ([wstr wcString] == NULL) {
		[self freeMem:wstring];

		length = 0;
		wstring = NULL;

		return self;
	}

	newlen = [wstr length];
	newstr = [self getMem: (newlen + 1) * sizeof(wchar_t)];
	wmemcpy(newstr, [wstr wcString], newlen + 1);

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

	length = newlen;
	wstring = newstr;

	return self;
}

- (OFWideString*)clone
{
	return [OFWideString new: wstring];
}

- (OFWideString*)append: (OFConstWideString*)wstr
{
	wchar_t	*newstr;
	size_t	newlen, strlength;

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

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

	newstr = [self resizeMem: wstring
			  toSize: (newlen + 1) * sizeof(wchar_t)];

	wmemcpy(newstr + length, [wstr wcString], strlength + 1);

	length = newlen;
	wstring = newstr;

	return self;
}

- (int)compare: (OFConstWideString*)str
{
	return wcscmp(wstring, [str wcString]);
}
@end

Modified tests/OFList/OFList.m from [bc3bf85f04] to [27298bf4ec].

28
29
30
31
32
33
34
35
36
37



38
39
40
41
42
43
44
28
29
30
31
32
33
34



35
36
37
38
39
40
41
42
43
44







-
-
-
+
+
+







{
	size_t	     i;
	OFList	     *list;
	OFListObject *iter;

	list = [OFList new];
 
	[list addNew: [OFString new: strings[0]]];
	[list addNew: [OFString new: strings[1]]];
	[list addNew: [OFString new: strings[2]]];
	[list addNew: [OFString newWithConstCString: strings[0]]];
	[list addNew: [OFString newWithConstCString: strings[1]]];
	[list addNew: [OFString newWithConstCString: strings[2]]];
 
	for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++)
		if (!strcmp([(OFString*)[iter data] cString], strings[i]))
			printf("Element %zu is expected element. GOOD!\n", i);
		else {
			printf("Element %zu is not expected element!\n", i);
			return 1;

Modified tests/OFString/OFString.m from [d5b6a278de] to [453b60b8cb].

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







-
-
+
+

-
+

-
+


-
+

-
+






-
+






-
+







#import "OFString.h"

/* TODO: Do real checks */

int
main()
{
	OFString *s1 = [OFString new: "test"];
	OFString *s2 = [[OFString alloc] init: ""];
	OFString *s1 = [OFString newWithCString: "test"];
	OFString *s2 = [OFString newWithCString: ""];
	OFString *s3;
	OFString *s4 = [OFString new];
	OFString *s4 = [OFString newWithConstCString: NULL];

	[s2 append: [OFConstString new: "123"]];
	[s2 append: [OFString newWithConstCString: "123"]];
	s3 = [s1 clone];

	[s4 setTo: (OFConstString*)s2];
	[s4 setTo: s2];

	if (![s1 compare: (OFConstString*)s3])
	if (![s1 compare: s3])
		puts("s1 and s3 match! GOOD!");
	else {
		puts("s1 and s3 don't match!");
		return 1;
	}

	if (![s2 compare: (OFConstString*)s4])
	if (![s2 compare: s4])
		puts("s2 and s4 match! GOOD!");
	else {
		puts("s1 and s3 don't match!");
		return 1;
	}

	if (!strcmp([[s1 append: (OFConstString*)s2] cString], "test123"))
	if (!strcmp([[s1 append: s2] cString], "test123"))
		puts("s1 appended with s2 is the expected string! GOOD!");
	else {
		puts("s1 appended with s2 is not the expected string!");
		return 1;
	}

	if (strlen([s1 cString]) == [s1 length] && [s1 length] == 7)

Modified tests/OFWideString/OFWideString.m from [890eff7e87] to [181ff63706].

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













-
+






-
-
-
-
+
+
+
+

-
+


-
+

-
+






-
+






-
+







/*
 * 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 <wchar.h>

#import "OFWideString.h"
#import "OFString.h"

/* TODO: Do real checks */

int
main()
{
	OFWideString *s1 = [OFWideString new: L"test"];
	OFWideString *s2 = [[OFWideString alloc] init: L""];
	OFWideString *s3;
	OFWideString *s4 = [OFWideString new];
	OFString *s1 = [OFString newWithWideCString: L"test"];
	OFString *s2 = [OFString newWithWideCString: L""];
	OFString *s3;
	OFString *s4 = [OFString newWithConstWideCString: NULL];

	[s2 append: [OFConstWideString new: L"123"]];
	[s2 append: [OFString newWithConstWideCString: L"123"]];
	s3 = [s1 clone];

	[s4 setTo: (OFConstWideString*)s2];
	[s4 setTo: s2];

	if (![s1 compare: (OFConstWideString*)s3])
	if (![s1 compare: s3])
		puts("s1 and s3 match! GOOD!");
	else {
		puts("s1 and s3 don't match!");
		return 1;
	}

	if (![s2 compare: (OFConstWideString*)s4])
	if (![s2 compare: s4])
		puts("s2 and s4 match! GOOD!");
	else {
		puts("s1 and s3 don't match!");
		return 1;
	}

	if (!wcscmp([[s1 append: (OFConstWideString*)s2] wcString], L"test123"))
	if (!wcscmp([[s1 append: s2] wcString], L"test123"))
		puts("s1 appended with s2 is the expected string! GOOD!");
	else {
		puts("s1 appended with s2 is not the expected string!");
		return 1;
	}

	if (wcslen([s1 wcString]) == [s1 length] && [s1 length] == 7)