ObjFW  Check-in [344f03e297]

Overview
Comment:Rename CData -> Data in createStanza:withCloseTag:andData:,...
Actually, it can be any data, not only cdata.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 344f03e29773975bb51796ce2a7b14163ee4d14369d514e0a4d0198e3b92f7f6
User & Date: js on 2008-11-01 18:10:12
Other Links: manifest | tags
Context
2008-11-01
18:21
Reduce object calls in OFHashes. check-in: 9c0e2dbc57 user: js tags: trunk
18:10
Rename CData -> Data in createStanza:withCloseTag:andData:,...
Actually, it can be any data, not only cdata.
check-in: 344f03e297 user: js tags: trunk
17:56
Make some things static so they don't get exported. check-in: bb17c57aa1 user: js tags: trunk
Changes

Modified src/OFXMLFactory.h from [eed267924f] to [49fd914643].

11
12
13
14
15
16
17
18
19
20

#import "OFObject.h"

@interface OFXMLFactory: OFObject
+ (char*)escapeCString: (const char*)s;
+ (char*)createStanza: (const char*)name
	 withCloseTag: (BOOL)close
	     andCData: (const char*)cdata, ...;
+ (char*)concatAndFreeCStrings: (char **)strs;
@end







|


11
12
13
14
15
16
17
18
19
20

#import "OFObject.h"

@interface OFXMLFactory: OFObject
+ (char*)escapeCString: (const char*)s;
+ (char*)createStanza: (const char*)name
	 withCloseTag: (BOOL)close
	      andData: (const char*)data, ...;
+ (char*)concatAndFreeCStrings: (char **)strs;
@end

Modified src/OFXMLFactory.m from [4580b46438] to [331396bf91].

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

	ret[j] = 0;
	return ret;
}

+ (char*)createStanza: (const char*)name
	 withCloseTag: (BOOL)close
	     andCData: (const char*)cdata, ...
{
	char *arg, *val, *xml;
	size_t i, len;
	va_list args;

	/* Start of tag */
	len = strlen(name) + 3;
	if ((xml = malloc(len)) == NULL) {
		[[OFNoMemException newWithObject: nil
					 andSize: len] raise];
		return NULL;
	}

	i = 0;
	xml[i++] = '<';
	memcpy(xml + i, name, strlen(name));
	i += strlen(name);

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

		if ((esc_val = [OFXMLFactory escapeCString: val]) == NULL) {
			/*
			 * escapeCString already throws an exception,







|



















|







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

	ret[j] = 0;
	return ret;
}

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

	/* Start of tag */
	len = strlen(name) + 3;
	if ((xml = malloc(len)) == NULL) {
		[[OFNoMemException newWithObject: nil
					 andSize: len] raise];
		return NULL;
	}

	i = 0;
	xml[i++] = '<';
	memcpy(xml + i, name, strlen(name));
	i += strlen(name);

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

		if ((esc_val = [OFXMLFactory escapeCString: val]) == NULL) {
			/*
			 * escapeCString already throws an exception,
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

		free(esc_val);
	}
	va_end(args);

	/* End of tag */
	if (close) {
		if (cdata == NULL) {
			if (!xmlfactory_resize(&xml, &len, 2 - 1)) {
				[[OFNoMemException newWithObject: nil
							 andSize: len + 2 - 1]
				    raise];
				return NULL;
			}
	
			xml[i++] = '/';
			xml[i++] = '>';
		} else {
			if (!xmlfactory_resize(&xml, &len, 1 + strlen(cdata) +
			    2 + strlen(name) + 1 - 1)) {
				[[OFNoMemException newWithObject: nil
							 andSize: len + 1 +
								  strlen(
								      cdata) +
								  2 +
								  strlen(name) +
								  1 - 1]
				    raise];
				return NULL;
			}
	
			xml[i++] = '>';
			memcpy(xml + i, cdata, strlen(cdata));
			i += strlen(cdata);
			xml[i++] = '<';
			xml[i++] = '/';
			memcpy(xml + i, name, strlen(name));
			i += strlen(name);
			xml[i++] = '>';
		}
	} else







|










|



|
<








|
|







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

		free(esc_val);
	}
	va_end(args);

	/* End of tag */
	if (close) {
		if (data == NULL) {
			if (!xmlfactory_resize(&xml, &len, 2 - 1)) {
				[[OFNoMemException newWithObject: nil
							 andSize: len + 2 - 1]
				    raise];
				return NULL;
			}
	
			xml[i++] = '/';
			xml[i++] = '>';
		} else {
			if (!xmlfactory_resize(&xml, &len, 1 + strlen(data) +
			    2 + strlen(name) + 1 - 1)) {
				[[OFNoMemException newWithObject: nil
							 andSize: len + 1 +
								  strlen(data) +

								  2 +
								  strlen(name) +
								  1 - 1]
				    raise];
				return NULL;
			}
	
			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

Modified tests/OFXMLFactory/OFXMLFactory.m from [ef338cc4f6] to [f0f6816ece].

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
}

inline void
test_create_stanza()
{
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: NO
				       andCData: NULL,
						 NULL],
	    "<foo>");

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








|





|






|




|




|





|





|






|







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
}

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

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