ObjFW  Check-in [4360177618]

Overview
Comment:Remove wchar_t stuff, as that's not portable anyway.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4360177618d7440bb53147dc2313840ceccc9dea8d3709697db6add9e0b00bdf
User & Date: js on 2008-12-20 14:19:36
Other Links: manifest | tags
Context
2008-12-20
14:26
Fix printf in tests. check-in: b023058e08 user: js tags: trunk
14:19
Remove wchar_t stuff, as that's not portable anyway. check-in: 4360177618 user: js tags: trunk
2008-12-19
23:15
Add errno in exceptions where it's useful. check-in: e668c03098 user: js tags: trunk
Changes

Modified src/OFString.h from [d8d41ef5ac] to [80f285a39b].

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

/**
 * A class for storing and modifying strings.
 */
@interface OFString: OFObject
{
	wchar_t	*string;
	size_t  length;
}

/**
 * Creates a new OFString.
 * 
 * \return An initialized OFString
 */
+ new;

/**
 * Creates a new OFString from a C string.
 * 
 * \param str A C string to initialize the OFString with
 * \return A new OFString
 */
+ newFromCString: (const char*)str;

/**
 * Creates a new OFString from a wide C string.
 * 
 * \param str A wide C string to initialize the OFString with
 * \return A new OFString
 */
+ newFromWideCString: (const wchar_t*)str;

/**
 * Initializes an already allocated OFString.
 *
 * \return An initialized OFString
 */
- init;

/**
 * Initializes an already allocated OFString from a C string.
 * 
 * \param str A C string to initialize the OFString with
 * \return An initialized OFString
 */
- initFromCString: (const char*)str;

/**
 * Initializes an already allocated OFString from a wide C string.
 * 
 * \param str A wide C string to initialize the OFString with
 * \return An initialized OFString
 */
- initFromWideCString: (const wchar_t*)str;

/**
 * \return The OFString as a wide C string
 */
- (const wchar_t*)wideCString;

/**
 * \return The length of the OFString
 */
- (size_t)length;

/**
 * \return The OFString as a C string, if possible (if not, returns NULL).
 *         If not needed anymore, it is usefull to call freeMem:.
 */
- (char*)getCString;

/**
 * Clones the OFString, creating a new one.
 * 
 * \return A copy of the OFString
 */
- (OFString*)clone;












<
<







|
|

















<
<
<
<
<
<
<
<















<
<
<
<
<
<
<
<



|






<
<
<
<
<
<







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

/**
 * A class for storing and modifying strings.
 */
@interface OFString: OFObject
{
	char   *string;
	size_t length;
}

/**
 * Creates a new OFString.
 * 
 * \return An initialized OFString
 */
+ new;

/**
 * Creates a new OFString from a C string.
 * 
 * \param str A C string to initialize the OFString with
 * \return A new OFString
 */
+ newFromCString: (const char*)str;









/**
 * Initializes an already allocated OFString.
 *
 * \return An initialized OFString
 */
- init;

/**
 * Initializes an already allocated OFString from a C string.
 * 
 * \param str A C string to initialize the OFString with
 * \return An initialized OFString
 */
- initFromCString: (const char*)str;









/**
 * \return The OFString as a wide C string
 */
- (const char*)cString;

/**
 * \return The length of the OFString
 */
- (size_t)length;







/**
 * Clones the OFString, creating a new one.
 * 
 * \return A copy of the OFString
 */
- (OFString*)clone;

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
 * Append a C string to the OFString.
 *
 * \param str A C string to append
 */
- appendCString: (const char*)str;

/**
 * Append a wide C string to the OFString.
 *
 * \param str A wide C string to append
 */
- appendWideCString: (const wchar_t*)str;

/**
 * Reverse the OFString.
 */
- reverse;

/**
 * Upper the OFString.







<
<
<
<
<
<
<







93
94
95
96
97
98
99







100
101
102
103
104
105
106
/**
 * Append a C string to the OFString.
 *
 * \param str A C string to append
 */
- appendCString: (const char*)str;








/**
 * Reverse the OFString.
 */
- reverse;

/**
 * Upper the OFString.

Modified src/OFString.m from [9f7f197b86] to [737d54ed05].

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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
 * the packaging of this file.
 */

#import "config.h"

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

#import "OFString.h"
#import "OFExceptions.h"

@implementation OFString
+ new
{
	return [[self alloc] init];
}

+ newFromCString: (const char*)str
{
	return [[self alloc] initFromCString: str];
}

+ newFromWideCString: (const wchar_t*)str
{
	return [[self alloc] initFromWideCString: str];
}

- init
{
	if ((self = [super init])) {
		length = 0;
		string = NULL;
	}

	return self;
}

- initFromCString: (const char*)str
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			if ((length = mbstowcs(NULL, str, 0)) == (size_t)-1) {
				[super free];
				@throw [OFCharsetConversionFailedException
				    newWithObject: nil];
			}

			string = [self getMemForNItems: length + 1
						ofSize: sizeof(wchar_t)];

			if (mbstowcs(string, str, length + 1) != length) {
				[super free];
				return nil;
			}
		}
	}

	return self;
}

- initFromWideCString: (const wchar_t*)str
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = wcslen(str);
			string = [self getMemForNItems: length + 1
						ofSize: sizeof(wchar_t)];
			wmemcpy(string, str, length + 1);
		}
	}

	return self;
}

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

- (size_t)length
{
	return length;
}

- (char*)getCString
{
	char *str;
	size_t len;

	if ((len = wcstombs(NULL, string, 0)) == (size_t)-1)
		@throw [OFCharsetConversionFailedException newWithObject: self];

	str = [self getMemWithSize: len + 1];

	if (wcstombs(str, string, len + 1) != len) {
		[self freeMem: str];
		@throw [OFCharsetConversionFailedException newWithObject: self];
	}

	return str;
}

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

- (OFString*)setTo: (OFString*)str
{
	[self free];
	return (self = [str clone]);
}

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

- append: (OFString*)str
{
	return [self appendWideCString: [str wideCString]];
}

- appendCString: (const char*)str
{
	wchar_t	*newstr, *tmpstr;
	size_t	newlen, strlength;

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

	if ((strlength = mbstowcs(NULL, str, 0)) == (size_t)-1)
		@throw [OFCharsetConversionFailedException newWithObject: self];

	tmpstr = [self getMemForNItems: strlength + 1
				ofSize: sizeof(wchar_t)];

	if (mbstowcs(tmpstr, str, strlength) != strlength) {
		[self freeMem: tmpstr];
		@throw [OFCharsetConversionFailedException newWithObject: self];
	}

	newlen = length + strlength;
	newstr = [self resizeMem: string
			toNItems: newlen + 1
			  ofSize: sizeof(wchar_t)];

	wmemcpy(newstr + length, tmpstr, strlength + 1);

	length = newlen;
	string = newstr;

	[self freeMem: tmpstr];

	return self;
}

- appendWideCString: (const wchar_t*)str
{
	wchar_t	*newstr;
	size_t	newlen, strlength;

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

	strlength = wcslen(str);
	newlen = length + strlength;

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

	wmemcpy(newstr + length, str, strlength + 1);

	length = newlen;
	string = newstr;

	return self;
}








|
<















<
<
<
<
<

















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






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









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


|










|




|




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


|

|



|
<

|







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
 * the packaging of this file.
 */

#import "config.h"

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


#import "OFString.h"
#import "OFExceptions.h"

@implementation OFString
+ new
{
	return [[self alloc] init];
}

+ newFromCString: (const char*)str
{
	return [[self alloc] initFromCString: str];
}






- init
{
	if ((self = [super init])) {
		length = 0;
		string = NULL;
	}

	return self;
}

- initFromCString: (const char*)str
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {





			length = strlen(str);
			string = [self getMemWithSize: length + 1];


			memcpy(string, str, length + 1);



		}
	}

	return self;
}


















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

- (size_t)length
{
	return length;
}



















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

- (OFString*)setTo: (OFString*)str
{
	[self free];
	return (self = [str clone]);
}

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

- append: (OFString*)str
{
	return [self appendCString: [str cString]];
}

- appendCString: (const char*)str
{


































	char   *newstr;
	size_t newlen, strlength;

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

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

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


	memcpy(newstr + length, str, strlength + 1);

	length = newlen;
	string = newstr;

	return self;
}

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
}

- upper
{
	size_t i = length;

	while (i--) 
		string[i] = towupper(string[i]);

	return self;
}

- lower
{
	size_t i = length;

	while (i--) 
		string[i] = towlower(string[i]);

	return self;
}
@end







|









|




122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
}

- upper
{
	size_t i = length;

	while (i--) 
		string[i] = toupper(string[i]);

	return self;
}

- lower
{
	size_t i = length;

	while (i--) 
		string[i] = tolower(string[i]);

	return self;
}
@end

Modified src/OFXMLFactory.h from [74179aac78] to [3e158df444].

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

/**
 * The OFXMLFactory class provides an easy way to create XML stanzas.
 */
@interface OFXMLFactory: OFObject {}
/**
 * XML-escapes a C string.
 *
 * \param s The C string to escape
 * \return The escaped C string.
 *	   You need to free it manually!
 */
+ (char*)escapeCString: (const char*)s;

/**
 * XML-escapes a wide C string.
 *
 * \param s The wide C string to escape
 * \return The escaped wide C string.
 *	   You need to free it manually!
 */
+ (wchar_t*)escapeWideCString: (const wchar_t*)s;

/**
 * Creates an XML stanza.
 *
 * \param name The name of the tag as a C string
 * \param close A boolean whether the tag should be closed
 * \param data Data that should be inside the tag as a C string.
 *	  It will NOT be escaped, so you can also include other stanzas.
 * \param ... Field / value pairs for the tag in the form "field", "value" as
 *	  C strings.
 *	  Last element must be NULL.
 *	  Example: "field1", "value1", "field2", "value2", NULL
 * \return The created XML stanza as a C string.
 *	   You need to free it manually!
 */
+ (char*)createStanza: (const char*)name
	 withCloseTag: (BOOL)close
	      andData: (const char*)data, ...;

/**
 * Creates an XML stanza as a wide C string.
 *
 * \param name The name of the tag as a wide C string
 * \param close A boolean whether the tag should be closed
 * \param data Data that should be inside the tag as a wide C string.
 *	  It will NOT be escaped, so you can also include other stanzas.
 * \param ... Field / value pairs for the tag in the form "field", "value" as
 *	  wide C strings.
 *	  Last element must be NULL.
 *	  Example: L"field1", L"value1", L"field2", L"value2", NULL
 * \return The created XML stanza as a wide C string.
 *	   You need to free it manually!
 */
+ (wchar_t*)createWideStanza: (const wchar_t*)name
		withCloseTag: (BOOL)close
		     andData: (const wchar_t*)data, ...;

/**
 * Concats an array of C strings into one C string and frees the array of C
 * strings.
 *
 * \param strs An array of C strings
 * \return The concatenated C strings.
 *	   You need to free it manually!
 */
+ (char*)concatAndFreeCStrings: (char**)strs;

/**
 * Concats an array of wide C strings into one wide C string and frees the
 * array of wide C strings.
 *
 * \param strs An array of wide C strings
 * \return The concatenated wide C strings.
 *	   You need to free it manually!
 */
+ (wchar_t*)concatAndFreeWideCStrings: (wchar_t**)strs;
@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
/*
 * 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 "OFObject.h"

/**
 * The OFXMLFactory class provides an easy way to create XML stanzas.
 */
@interface OFXMLFactory: OFObject {}
/**
 * XML-escapes a C string.
 *
 * \param s The C string to escape
 * \return The escaped C string.
 *	   You need to free it manually!
 */
+ (char*)escapeCString: (const char*)s;










/**
 * Creates an XML stanza.
 *
 * \param name The name of the tag as a C string
 * \param close A boolean whether the tag should be closed
 * \param data Data that should be inside the tag as a C string.
 *	  It will NOT be escaped, so you can also include other stanzas.
 * \param ... Field / value pairs for the tag in the form "field", "value" as
 *	  C strings.
 *	  Last element must be NULL.
 *	  Example: "field1", "value1", "field2", "value2", NULL
 * \return The created XML stanza as a C string.
 *	   You need to free it manually!
 */
+ (char*)createStanza: (const char*)name
	 withCloseTag: (BOOL)close
	      andData: (const char*)data, ...;



















/**
 * Concats an array of C strings into one C string and frees the array of C
 * strings.
 *
 * \param strs An array of C strings
 * \return The concatenated C strings.
 *	   You need to free it manually!
 */
+ (char*)concatAndFreeCStrings: (char**)strs;










@end

Modified src/OFXMLFactory.m from [cb13f5e9ce] to [6c7f478ccb].

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 */

#import "config.h"

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

#import "OFXMLFactory.h"
#import "OFExceptions.h"
#import "OFMacros.h"

/*
 * We don't use OFString in this file for performance reasons!







<







10
11
12
13
14
15
16

17
18
19
20
21
22
23
 */

#import "config.h"

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


#import "OFXMLFactory.h"
#import "OFExceptions.h"
#import "OFMacros.h"

/*
 * We don't use OFString in this file for performance reasons!
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
{
	char *str2;
	size_t len2;

	if (add > SIZE_MAX - *len)
		@throw [OFOutOfRangeException newWithObject: nil];
	len2 = *len + add;
	
	if ((str2 = realloc(*str, len2)) == NULL) {
		if (*str)
			free(*str);
		*str = NULL;
		return NO;
	}

	*str = str2;
	*len = len2;

	return YES;
}

static inline BOOL
xf_resize_wchars(wchar_t **str, size_t *len, size_t add)
{
	wchar_t *str2;
	size_t len2;

	if (add > SIZE_MAX - *len)
		@throw [OFOutOfRangeException newWithObject: nil];
	len2 = *len + add;

	if (len2 > SIZE_MAX / sizeof(wchar_t))
		@throw [OFOutOfRangeException newWithObject: nil];
	
	if ((str2 = realloc(*str, len2 * sizeof(wchar_t))) == NULL) {
		if (*str)
			free(*str);
		*str = NULL;
		return NO;
	}

	*str = str2;







|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







32
33
34
35
36
37
38
39
40


























41
42
43
44
45
46
47
{
	char *str2;
	size_t len2;

	if (add > SIZE_MAX - *len)
		@throw [OFOutOfRangeException newWithObject: nil];
	len2 = *len + add;

	if ((str2 = realloc(*str, len2)) == NULL) {


























		if (*str)
			free(*str);
		*str = NULL;
		return NO;
	}

	*str = str2;
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

	if (!xf_resize_chars(str, len, add_len))
		return NO;

	memcpy(*str + *pos, add, add_len);
	*pos += add_len;

	return YES;
}

static inline BOOL
xf_add2wchars(wchar_t **str, size_t *len, size_t *pos, const wchar_t *add)
{
	size_t add_len;

	add_len = wcslen(add);

	if (!xf_resize_wchars(str, len, add_len))
		return NO;

	wmemcpy(*str + *pos, add, add_len);
	*pos += add_len;

	return YES;
}

@implementation OFXMLFactory
+ (char*)escapeCString: (const char*)s
{
	char *ret;







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







59
60
61
62
63
64
65
















66
67
68
69
70
71
72

	if (!xf_resize_chars(str, len, add_len))
		return NO;

	memcpy(*str + *pos, add, add_len);
	*pos += add_len;

















	return YES;
}

@implementation OFXMLFactory
+ (char*)escapeCString: (const char*)s
{
	char *ret;
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
		case '&':
			if (OF_UNLIKELY(!xf_add2chars(&ret, &nlen, &j,
			    "&amp;")))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: nlen + 5];
			break;
		default:
			ret[j++] = s[i];
			break;
		}
	}

	ret[j] = 0;
	return ret;
}

+ (wchar_t*)escapeWideCString: (const wchar_t*)s
{
	wchar_t *ret;
	size_t i, j, len, nlen;

	len = nlen = wcslen(s);
	if (SIZE_MAX - len < 1)
		@throw [OFOutOfRangeException newWithObject: nil];
	nlen++;

	if (nlen > SIZE_MAX / sizeof(wchar_t))
		@throw [OFOutOfRangeException newWithObject: nil];

	if ((ret = malloc(nlen * sizeof(wchar_t))) == NULL)
		@throw [OFNoMemException newWithObject: nil
					       andSize: nlen * sizeof(wchar_t)];

	for (i = j = 0; i < len; i++) {
		switch (s[i]) {
		case L'<':
			if (OF_UNLIKELY(!xf_add2wchars(&ret, &nlen, &j,
			    L"&lt;")))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: (nlen + 4) *
						   sizeof(wchar_t)];
			break;
		case L'>':
			if (OF_UNLIKELY(!xf_add2wchars(&ret, &nlen, &j,
			    L"&gt;")))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: (nlen + 4) *
						   sizeof(wchar_t)];
			break;
		case L'"':
			if (OF_UNLIKELY(!xf_add2wchars(&ret, &nlen, &j,
			    L"&quot;")))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: (nlen + 6) *
						   sizeof(wchar_t)];
			break;
		case L'\'':
			if (OF_UNLIKELY(!xf_add2wchars(&ret, &nlen, &j,
			    L"&apos;")))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: (nlen + 6) *
						   sizeof(wchar_t)];
			break;
		case L'&':
			if (OF_UNLIKELY(!xf_add2wchars(&ret, &nlen, &j,
			    L"&amp;")))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: (nlen + 5) *
						   sizeof(wchar_t)];
			break;
		default:
			ret[j++] = s[i];
			break;
		}
	}

	ret[j] = 0;







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







112
113
114
115
116
117
118





































































119
120
121
122
123
124
125
		case '&':
			if (OF_UNLIKELY(!xf_add2chars(&ret, &nlen, &j,
			    "&amp;")))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: nlen + 5];
			break;





































































		default:
			ret[j++] = s[i];
			break;
		}
	}

	ret[j] = 0;
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
	/* End of tag */
	if (close) {
		if (data == NULL) {
			if (!xf_resize_chars(&xml, &len, 2 - 1))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: len + 2 - 1];
	
			xml[i++] = '/';
			xml[i++] = '>';
		} else {
			if (!xf_resize_chars(&xml, &len, 1 + strlen(data) +
			    2 + strlen(name) + 1 - 1))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: len + 1 + strlen(data) + 2 +
						   strlen(name) + 1 - 1];
	
			xml[i++] = '>';
			memcpy(xml + i, data, strlen(data));
			i += strlen(data);
			xml[i++] = '<';
			xml[i++] = '/';
			memcpy(xml + i, name, strlen(name));
			i += strlen(name);
			xml[i++] = '>';
		}
	} else
		xml[i++] = '>';

	xml[i] = 0;
	return xml;
}

+ (wchar_t*)createWideStanza: (const wchar_t*)name
		withCloseTag: (BOOL)close
		     andData: (const wchar_t*)data, ...
{
	wchar_t *arg, *val, *xml;
	size_t i, len;
	va_list args;

	/* Start of tag */
	len = wcslen(name);
	if (SIZE_MAX - len < 3)
		@throw [OFOutOfRangeException newWithObject: nil];
	len += 3;

	if (len > SIZE_MAX / sizeof(wchar_t))
		@throw [OFOutOfRangeException newWithObject: nil];

	if ((xml = malloc(len * sizeof(wchar_t))) == NULL)
		@throw [OFNoMemException newWithObject: nil
					       andSize: len * sizeof(wchar_t)];

	i = 0;
	xml[i++] = L'<';
	wmemcpy(xml + i, name, wcslen(name));
	i += wcslen(name);

	/* Arguments */
	va_start(args, data);
	while ((arg = va_arg(args, wchar_t*)) != NULL &&
	    (val = va_arg(args, wchar_t*)) != NULL) {
		wchar_t *esc_val;

		if (OF_UNLIKELY((esc_val =
		    [OFXMLFactory escapeWideCString: val]) == NULL)) {
			/*
			 * escapeWideCString already throws an exception,
			 * no need to throw a second one here.
			 */
			free(xml);
			return NULL;
		}

		if (OF_UNLIKELY(!xf_resize_wchars(&xml, &len, 1 + wcslen(arg) +
		    2 + wcslen(esc_val) + 1))) {
			free(esc_val);
			@throw [OFNoMemException
			    newWithObject: nil
				  andSize: (len + 1 + wcslen(arg) + 2 +
					   wcslen(esc_val) + 1) *
					   sizeof(wchar_t)];
		}

		xml[i++] = L' ';
		wmemcpy(xml + i, arg, wcslen(arg));
		i += wcslen(arg);
		xml[i++] = L'=';
		xml[i++] = L'\'';
		wmemcpy(xml + i, esc_val, wcslen(esc_val));
		i += wcslen(esc_val);
		xml[i++] = L'\'';

		free(esc_val);
	}
	va_end(args);

	/* End of tag */
	if (close) {
		if (data == NULL) {
			if (!xf_resize_wchars(&xml, &len, 2 - 1))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: (len + 2 - 1) *
						   sizeof(wchar_t)];
	
			xml[i++] = L'/';
			xml[i++] = L'>';
		} else {
			if (!xf_resize_wchars(&xml, &len, 1 + wcslen(data) +
			    2 + wcslen(name) + 1 - 1))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: (len + 1 + wcslen(data) + 2 +
						   wcslen(name) + 1 - 1) *
						   sizeof(wchar_t)];
	
			xml[i++] = L'>';
			wmemcpy(xml + i, data, wcslen(data));
			i += wcslen(data);
			xml[i++] = L'<';
			xml[i++] = L'/';
			wmemcpy(xml + i, name, wcslen(name));
			i += wcslen(name);
			xml[i++] = L'>';
		}
	} else
		xml[i++] = L'>';

	xml[i] = 0;
	return xml;
}

+ (char*)concatAndFreeCStrings: (char**)strs
{
	char *ret;
	size_t i, len, pos;

	if (strs[0] == NULL)
		return NULL;

	len = strlen(*strs);
	if (SIZE_MAX - len < 1)
		@throw [OFOutOfRangeException newWithObject: nil];
	len++;
	
	if ((ret = malloc(len)) == NULL)
		@throw [OFNoMemException newWithObject: nil
					       andSize: len];

	memcpy(ret, strs[0], len - 1);
	pos = len - 1;

	for (i = 1; strs[i] != NULL; i++) {
		if (OF_UNLIKELY(!xf_add2chars(&ret, &len, &pos, strs[i]))) {
			free(ret);
			@throw [OFNoMemException
			    newWithObject: nil
				  andSize: len + strlen(strs[i])];
		}
	}

	for (i = 0; strs[i] != NULL; i++)
		free(strs[i]);

	ret[pos] = 0;
	return ret;
}

+ (wchar_t*)concatAndFreeWideCStrings: (wchar_t**)strs
{
	wchar_t *ret;
	size_t i, len, pos;

	if (strs[0] == NULL)
		return NULL;

	len = wcslen(*strs);
	if (SIZE_MAX - len < 1)
		@throw [OFOutOfRangeException newWithObject: nil];
	len++;

	if (len > SIZE_MAX - sizeof(wchar_t))
		@throw [OFOutOfRangeException newWithObject: nil];

	if ((ret = malloc(len * sizeof(wchar_t))) == NULL)
		@throw [OFNoMemException newWithObject: nil
					       andSize: len * sizeof(wchar_t)];

	wmemcpy(ret, strs[0], len - 1);
	pos = len - 1;

	for (i = 1; strs[i] != NULL; i++) {
		if (!xf_add2wchars(&ret, &len, &pos, strs[i])) {
			free(ret);
			@throw [OFNoMemException
			    newWithObject: nil
				  andSize: (wcslen(strs[i]) + len) *
					   sizeof(wchar_t)];
		}
	}

	for (i = 0; strs[i] != NULL; i++)
		free(strs[i]);

	ret[pos] = 0;
	return ret;
}
@end







|









|












<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
















|
















<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219





































































































220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252








































253
254
255
256
257
258
259
	/* End of tag */
	if (close) {
		if (data == NULL) {
			if (!xf_resize_chars(&xml, &len, 2 - 1))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: len + 2 - 1];

			xml[i++] = '/';
			xml[i++] = '>';
		} else {
			if (!xf_resize_chars(&xml, &len, 1 + strlen(data) +
			    2 + strlen(name) + 1 - 1))
				@throw [OFNoMemException
				    newWithObject: nil
					  andSize: len + 1 + strlen(data) + 2 +
						   strlen(name) + 1 - 1];

			xml[i++] = '>';
			memcpy(xml + i, data, strlen(data));
			i += strlen(data);
			xml[i++] = '<';
			xml[i++] = '/';
			memcpy(xml + i, name, strlen(name));
			i += strlen(name);
			xml[i++] = '>';
		}
	} else
		xml[i++] = '>';






































































































	xml[i] = 0;
	return xml;
}

+ (char*)concatAndFreeCStrings: (char**)strs
{
	char *ret;
	size_t i, len, pos;

	if (strs[0] == NULL)
		return NULL;

	len = strlen(*strs);
	if (SIZE_MAX - len < 1)
		@throw [OFOutOfRangeException newWithObject: nil];
	len++;

	if ((ret = malloc(len)) == NULL)
		@throw [OFNoMemException newWithObject: nil
					       andSize: len];

	memcpy(ret, strs[0], len - 1);
	pos = len - 1;

	for (i = 1; strs[i] != NULL; i++) {
		if (OF_UNLIKELY(!xf_add2chars(&ret, &len, &pos, strs[i]))) {
			free(ret);
			@throw [OFNoMemException
			    newWithObject: nil
				  andSize: len + strlen(strs[i])];
		}
	}









































	for (i = 0; strs[i] != NULL; i++)
		free(strs[i]);

	ret[pos] = 0;
	return ret;
}
@end

Modified tests/OFList/OFList.m from [4f9ae6f06a] to [2042f99cd4].

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

#define _ISOC99_SOURCE

#import <string.h>
#import <wchar.h>

#import "OFString.h"
#import "OFList.h"

#define NUM_TESTS 5
#define SUCCESS								\
{									\
	wprintf(L"\r\033[1;%dmTests successful: %d/%d\033[0m",		\
	    (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS);		\
	fflush(stdout);							\
}
#define FAIL								\
{									\
	wprintf(L"\r\033[K\033[1;31mTest %d/%d failed!\033[m\n",	\
	    i + 1, NUM_TESTS);						\
	return 1;							\
}
#define CHECK(cond)							\
	if (cond)							\
		SUCCESS							\
	else								\
		FAIL							\
	i++;
 
const wchar_t *strings[] = {
	L"First String Object",
	L"Second String Object",
	L"Third String Object"
};

int
main()
{
	size_t	     i;
	OFList	     *list;
	OFListObject *iter;

	list = [OFList new];
 
	[list addNew: [OFString newFromWideCString: strings[0]]];
	[list addNew: [OFString newFromWideCString: strings[1]]];
	[list addNew: [OFString newFromWideCString: strings[2]]];
 
	for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++)
		if (!wcscmp([(OFString*)[iter data] wideCString], strings[i]))
			SUCCESS
		else
			FAIL

	CHECK(!wcscmp([(OFString*)[[list first] data] wideCString], strings[0]))
	CHECK(!wcscmp([(OFString*)[[list last] data] wideCString], strings[2]))

	wprintf(L"\n");
 
	[list freeIncludingData];

	return 0;
}













<
<
|
|







|





|










|
|
|
|











|
|
|


|




|
|

|





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



#import <stdio.h>
#import <string.h>

#import "OFString.h"
#import "OFList.h"

#define NUM_TESTS 5
#define SUCCESS								\
{									\
	printf("\r\033[1;%dmTests successful: %d/%d\033[0m",		\
	    (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS);		\
	fflush(stdout);							\
}
#define FAIL								\
{									\
	printf("\r\033[K\033[1;31mTest %d/%d failed!\033[m\n",		\
	    i + 1, NUM_TESTS);						\
	return 1;							\
}
#define CHECK(cond)							\
	if (cond)							\
		SUCCESS							\
	else								\
		FAIL							\
	i++;
 
const char *strings[] = {
	"First String Object",
	"Second String Object",
	"Third String Object"
};

int
main()
{
	size_t	     i;
	OFList	     *list;
	OFListObject *iter;

	list = [OFList new];
 
	[list addNew: [OFString newFromCString: strings[0]]];
	[list addNew: [OFString newFromCString: strings[1]]];
	[list addNew: [OFString newFromCString: strings[2]]];
 
	for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++)
		if (!strcmp([(OFString*)[iter data] cString], strings[i]))
			SUCCESS
		else
			FAIL

	CHECK(!strcmp([(OFString*)[[list first] data] cString], strings[0]))
	CHECK(!strcmp([(OFString*)[[list last] data] cString], strings[2]))

	puts("");
 
	[list freeIncludingData];

	return 0;
}

Modified tests/OFString/OFString.m from [8dc320290e] to [acd4c64051].

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
	if (![s2 compareTo: s4])
		puts("s2 and s4 match! GOOD!");
	else {
		puts("s2 and s4 don't match!");
		return 1;
	}

	if (!strcmp([[s1 append: s2] getCString], "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 getCString]) == [s1 length] && [s1 length] == 7)
		puts("s1 has the expected length. GOOD!");
	else {
		puts("s1 does not have the expected length!");
		return 1;
	}

	if (!strcmp([[s1 reverse] getCString], "321tset"))
		puts("Reversed s1 is expected string! GOOD!");
	else {
		puts("Reversed s1 is NOT the expected string!");
		return 1;
	}

	if (!strcmp([[s1 upper] getCString], "321TSET"))
		puts("Upper s1 is expected string! GOOD!");
	else {
		puts("Upper s1 is NOT expected string!");
		return 1;
	}

	if (!strcmp([[s1 lower] getCString], "321tset"))
		puts("Lower s1 is expected string! GOOD!");
	else {
		puts("Lower s1 is NOT expected string!");
		return 1;
	}

	/* Also clears all the memory of the returned C strings */







|






|






|






|






|







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
	if (![s2 compareTo: s4])
		puts("s2 and s4 match! GOOD!");
	else {
		puts("s2 and s4 don't match!");
		return 1;
	}

	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)
		puts("s1 has the expected length. GOOD!");
	else {
		puts("s1 does not have the expected length!");
		return 1;
	}

	if (!strcmp([[s1 reverse] cString], "321tset"))
		puts("Reversed s1 is expected string! GOOD!");
	else {
		puts("Reversed s1 is NOT the expected string!");
		return 1;
	}

	if (!strcmp([[s1 upper] cString], "321TSET"))
		puts("Upper s1 is expected string! GOOD!");
	else {
		puts("Upper s1 is NOT expected string!");
		return 1;
	}

	if (!strcmp([[s1 lower] cString], "321tset"))
		puts("Lower s1 is expected string! GOOD!");
	else {
		puts("Lower s1 is NOT expected string!");
		return 1;
	}

	/* Also clears all the memory of the returned C strings */

Modified tests/OFXMLFactory/OFXMLFactory.m from [7fe10add51] to [38666c43a6].

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

#define _ISOC99_SOURCE

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

#import "OFXMLFactory.h"

#define NUM_TESTS 10

static int i;

inline void
check_result(char *result, const char *should)
{
	/* Use wprintf here so we don't mix printf and wprintf! */
	i++;

	if (!strcmp(result, should)) {
		wprintf(L"\r\033[1;%dmchar* tests successful:    %2d/%d\033[0m",
		    (i == NUM_TESTS ? 32 : 33), i, NUM_TESTS);
		fflush(stdout);
	} else {
		wprintf(L"\r\033[K\033[1;31mchar* test %d/%d failed!\033[0m\n",
		    i, NUM_TESTS);
		wprintf(L"%s is NOT expected result!\n", result);
		exit(1);
	}

	free(result);
}

inline void
check_result_wide(wchar_t *result, const wchar_t *should)
{
	i++;

	if (!wcscmp(result, should)) {
		wprintf(L"\r\033[1;%dmwchar_t* tests successful: %2d/%d\033[0m",
		    (i == NUM_TESTS ? 32 : 33), i, NUM_TESTS);
		fflush(stdout);
	} else {
		wprintf(L"\r\033[K\033[1;31mwchar_t* test %d/%d failed!\033[0m"
		    "\n", i, NUM_TESTS);
		wprintf(L"%s is NOT expected result!\n", result);
		exit(1);
	}

	free(result);
}

inline void













<
<


<










<



|



|

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







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



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


#import "OFXMLFactory.h"

#define NUM_TESTS 10

static int i;

inline void
check_result(char *result, const char *should)
{

	i++;

	if (!strcmp(result, should)) {
		printf("\r\033[1;%dmTests successful: %2d/%d\033[0m",
		    (i == NUM_TESTS ? 32 : 33), i, NUM_TESTS);
		fflush(stdout);
	} else {
		printf("\r\033[K\033[1;31mTest %d/%d failed!\033[0m\n",
		    i, NUM_TESTS);
		printf("%s is NOT expected result!\n", result);



















		exit(1);
	}

	free(result);
}

inline void
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
117
118
119
120
121
	strs[2] = s3;
	strs[3] = NULL;

	check_result([OFXMLFactory concatAndFreeCStrings: strs],
	    "<foo>bar<test/>");
}

inline void
test_concat_wide()
{
	const wchar_t *c1 = L"<foo>", *c2 = L"bar", *c3 = L"<test/>";
	wchar_t *s1, *s2, *s3;
	wchar_t *strs[4];

	if ((s1 = malloc((wcslen(c1) + 1) * sizeof(wchar_t))) == NULL ||
	    (s2 = malloc((wcslen(c2) + 1) * sizeof(wchar_t))) == NULL ||
	    (s3 = malloc((wcslen(c3) + 1) * sizeof(wchar_t))) == NULL)
		exit(1);

	wcsncpy(s1, c1, wcslen(c1) + 1);
	wcsncpy(s2, c2, wcslen(c2) + 1);
	wcsncpy(s3, c3, wcslen(c3) + 1);

	strs[0] = s1;
	strs[1] = s2;
	strs[2] = s3;
	strs[3] = NULL;

	check_result_wide([OFXMLFactory concatAndFreeWideCStrings: strs],
	    L"<foo>bar<test/>");
}

inline void
test_create_stanza()
{
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: NO
					andData: NULL,
						 NULL],







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







60
61
62
63
64
65
66

























67
68
69
70
71
72
73
	strs[2] = s3;
	strs[3] = NULL;

	check_result([OFXMLFactory concatAndFreeCStrings: strs],
	    "<foo>bar<test/>");
}


























inline void
test_create_stanza()
{
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: NO
					andData: NULL,
						 NULL],
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
						 "bar", "b'az",
						 "x", "y",
						 "a", "b",
						 NULL],
	    "<foo bar='b&apos;az' x='y' a='b'>bar</foo>");
}

inline void
test_create_stanza_wide()
{
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: NO
						 andData: NULL,
							  NULL],
	    L"<foo>");

	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: NO
						 andData: NULL,
							  L"bar", L"baz",
							  L"blub", L"asd",
							  NULL],
	    L"<foo bar='baz' blub='asd'>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: NULL,
							  NULL],
	    L"<foo/>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: L"bar",
							  NULL],
	    L"<foo>bar</foo>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: NULL,
							  L"bar", L"b&az",
							  NULL],
	    L"<foo bar='b&amp;az'/>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: L"bar",
							  L"bar", L"b'az",
							  NULL],
	    L"<foo bar='b&apos;az'>bar</foo>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: NULL,
							  L"bar", L"b&az",
							  L"x", L"asd\"",
							  NULL],
	    L"<foo bar='b&amp;az' x='asd&quot;'/>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: L"bar",
							  L"bar", L"b'az",
							  L"x", L"y",
							  L"a", L"b",
							  NULL],
	    L"<foo bar='b&apos;az' x='y' a='b'>bar</foo>");
}

inline void
test_escape()
{
	check_result([OFXMLFactory escapeCString: "<hallo> &welt'\"!&"],
	    "&lt;hallo&gt; &amp;welt&apos;&quot;!&amp;");
}

inline void
test_escape_wide()
{
	check_result_wide(
	    [OFXMLFactory escapeWideCString: L"<hallo> &welt'\"!&"],
	    L"&lt;hallo&gt; &amp;welt&apos;&quot;!&amp;");
}


int main()
{
	i = 0;
	test_escape();
       	test_create_stanza();
       	test_concat();
	wprintf(L"\n");

	i = 0;
	test_escape_wide();
	test_create_stanza_wide();
	test_concat_wide();
	wprintf(L"\n");

	return 0;
}








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<





<
<
<
<
<
<
<
<
<







<
|
<
<
<
<
<



115
116
117
118
119
120
121
122























































123
124
125
126
127









128
129
130
131
132
133
134

135





136
137
138
						 "bar", "b'az",
						 "x", "y",
						 "a", "b",
						 NULL],
	    "<foo bar='b&apos;az' x='y' a='b'>bar</foo>");
}

inline void























































test_escape()
{
	check_result([OFXMLFactory escapeCString: "<hallo> &welt'\"!&"],
	    "&lt;hallo&gt; &amp;welt&apos;&quot;!&amp;");
}










int main()
{
	i = 0;
	test_escape();
       	test_create_stanza();
       	test_concat();

	puts("");






	return 0;
}