ObjFW  Check-in [4a8fcc8716]

Overview
Comment:Add -[description] to OFXMLElement.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4a8fcc871661e7745a368537088cb5e370603f3ebad79fb680ac0cd9bb6afaaf
User & Date: js on 2010-12-11 20:13:19
Other Links: manifest | tags
Context
2010-12-11
20:27
Rename a few exception-related methods. check-in: 5e44debc07 user: js tags: trunk
20:13
Add -[description] to OFXMLElement. check-in: 4a8fcc8716 user: js tags: trunk
2010-12-10
11:21
Documentation fixes. check-in: fada60d54c user: js tags: trunk
Changes

Modified src/OFDataArray.h from [5c1e81dd26] to [c3f8c7f7f4].

170
171
172
173
174
175
176
177

178
179
180
181
170
171
172
173
174
175
176

177
178
179
180
181







-
+




/**
 * \brief A class for storing arbitrary big data in an array.
 *
 * The OFBigDataArray class is a class for storing arbitrary data in an array
 * and is designed to store large hunks of data. Therefore, it allocates
 * memory in pages rather than a chunk of memory for each item.
 */
@interface OFBigDataArray: OFDataArray <OFCopying>
@interface OFBigDataArray: OFDataArray
{
	size_t size;
}
@end

Modified src/OFXMLElement.h from [49ae19b7bd] to [ee4c57317a].

196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210







-
+







 */
- (OFArray*)children;

/**
 * \return A new autoreleased OFString representing the OFXMLElement as an
 * XML string
 */
- (OFString*)string;
- (OFString*)stringValue;

/**
 * Adds the specified attribute.
 *
 * \param attr The attribute to add
 */
- (void)addAttribute: (OFXMLAttribute*)attr;

Modified src/OFXMLElement.m from [4e57f733e3] to [6d5c2fce48].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


16
17
18
19
20
21
22
1
2
3
4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19
20
21
22













-
-
+
+







/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. 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.
 */

#include "config.h"

#include <assert.h>
#include <string.h>
#include <string.h>
#include <assert.h>

#import "OFXMLElement.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFXMLAttribute.h"
#import "OFAutoreleasePool.h"
186
187
188
189
190
191
192
193
194


195
196
197
198
199
200
201
186
187
188
189
190
191
192


193
194
195
196
197
198
199
200
201







-
-
+
+







}

- (OFArray*)children
{
	return [[children copy] autorelease];
}

- (OFString*)_stringWithParentNamespaces: (OFDictionary*)parent_namespaces
		  parentDefaultNamespace: (OFString*)parent_default_ns
- (OFString*)_stringValueWithParentNamespaces: (OFDictionary*)parent_namespaces
		       parentDefaultNamespace: (OFString*)parent_default_ns
{
	OFAutoreleasePool *pool, *pool2;
	char *str_c;
	size_t len, i, j, attrs_count;
	OFString *prefix = nil;
	OFXMLAttribute **attrs_carray;
	OFString *ret, *tmp;
326
327
328
329
330
331
332
333

334
335
336
337
338
339
340
326
327
328
329
330
331
332

333
334
335
336
337
338
339
340







-
+







		append = [tmp methodForSelector:
		    @selector(appendCStringWithoutUTF8Checking:)];

		for (j = 0; j < children_count; j++)
			append(tmp, @selector(
			    appendCStringWithoutUTF8Checking:),
			    [[children_carray[j]
			    _stringWithParentNamespaces: all_namespaces
			    _stringValueWithParentNamespaces: all_namespaces
			    parentDefaultNamespace: defaultNamespace] cString]);

		len += [tmp cStringLength] + [name cStringLength] + 2;
		@try {
			str_c = [self resizeMemory: str_c
					    toSize: len];
		} @catch (id e) {
377
378
379
380
381
382
383
384

385
386
387







388
389
390
391
392
393
394
377
378
379
380
381
382
383

384
385


386
387
388
389
390
391
392
393
394
395
396
397
398
399







-
+

-
-
+
+
+
+
+
+
+







					   length: len];
	} @finally {
		[self freeMemory: str_c];
	}
	return ret;
}

- (OFString*)string
- (OFString*)stringValue
{
	return [self _stringWithParentNamespaces: nil
			  parentDefaultNamespace: nil];
	return [self _stringValueWithParentNamespaces: nil
			       parentDefaultNamespace: nil];
}

- (OFString*)description
{
	return [self stringValue];
}

- (void)addAttribute: (OFXMLAttribute*)attr
{
	if (name == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

Modified tests/OFXMLElementBuilderTests.m from [5f20b80e90] to [7c6e7637bc].

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













-







/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. 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.
 */

#include "config.h"

#include <string.h>
#include <assert.h>

#import "OFXMLElement.h"
#import "OFXMLParser.h"
#import "OFXMLElementBuilder.h"
#import "OFAutoreleasePool.h"

33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48

49
50
51

52
53
54
55
56
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46

47



48
49
50
51
52
53







-
+







-
+
-
-
-
+





}

- (void)XMLElementBuilderTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFXMLParser *p = [OFXMLParser parser];
	OFXMLElementBuilder *builder = [OFXMLElementBuilder elementBuilder];
	const char *str = "<foo>bar<![CDATA[f<oo]]>baz<qux/>"
	OFString *str = @"<foo>bar<![CDATA[f<oo]]>baz<qux/>"
	    " <qux xmlns:qux='urn:qux'><qux:bar/><x qux:y='z'/></qux>"
	    "</foo>";

	[p setDelegate: builder];
	[builder setDelegate: self];

	TEST(@"Building element from parsed XML",
	    R([p parseBuffer: str
	    R([p parseString: str]) &&
		    withSize: strlen(str)]) &&
    	    elem != nil && !strcmp([[elem string] cString], str))

	    elem != nil && [[elem stringValue] isEqual: str])

	[elem release];
	[pool drain];
}
@end

Modified tests/OFXMLElementTests.m from [56acb16688] to [5a91def578].

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







-
+




-
+








-
+







+
-
+



-
+



-
+



-
+




-
+


+
-
+









-
+




+
-
+
-
-
-
-
+
+
+





- (void)XMLElementTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFXMLElement *elem[4];

	TEST(@"+[elementWithName:]",
	    (elem[0] = [OFXMLElement elementWithName: @"foo"]) &&
	    [[elem[0] string] isEqual: @"<foo/>"])
	    [[elem[0] stringValue] isEqual: @"<foo/>"])

	TEST(@"+[elementWithName:stringValue:]",
	    (elem[1] = [OFXMLElement elementWithName: @"foo"
					 stringValue: @"b&ar"]) &&
	    [[elem[1] string] isEqual: @"<foo>b&amp;ar</foo>"])
	    [[elem[1] stringValue] isEqual: @"<foo>b&amp;ar</foo>"])

	TEST(@"+[elementWithName:namespace:]",
	    (elem[2] = [OFXMLElement elementWithName: @"foo"
					   namespace: @"urn:objfw:test"]) &&
	    R([elem[2] addAttributeWithName: @"test"
				stringValue: @"test"]) &&
	    R([elem[2] setPrefix: @"objfw-test"
		    forNamespace: @"urn:objfw:test"]) &&
	    [[elem[2] string] isEqual: @"<objfw-test:foo test='test'/>"])
	    [[elem[2] stringValue] isEqual: @"<objfw-test:foo test='test'/>"])

	TEST(@"+[elementWithName:namespace:stringValue:]",
	    (elem[3] = [OFXMLElement elementWithName: @"foo"
					   namespace: @"urn:objfw:test"
					 stringValue: @"x"]) &&
	    R([elem[3] setPrefix: @"objfw-test"
		    forNamespace: @"urn:objfw:test"]) &&
	    [[elem[3] stringValue] isEqual:
	    [[elem[3] string] isEqual: @"<objfw-test:foo>x</objfw-test:foo>"])
	    @"<objfw-test:foo>x</objfw-test:foo>"])

	TEST(@"+[elementWithCharacters:]",
	    (elem[3] = [OFXMLElement elementWithCharacters: @"<foo>"]) &&
	    [[elem[3] string] isEqual: @"&lt;foo&gt;"])
	    [[elem[3] stringValue] isEqual: @"&lt;foo&gt;"])

	TEST(@"+[elementWithCDATA:]",
	    (elem[3] = [OFXMLElement elementWithCDATA: @"<foo>"]) &&
	    [[elem[3] string] isEqual: @"<![CDATA[<foo>]]>"]);
	    [[elem[3] stringValue] isEqual: @"<![CDATA[<foo>]]>"]);

	TEST(@"+[elementWithComment:]",
	    (elem[3] = [OFXMLElement elementWithComment: @" comment "]) &&
	    [[elem[3] string] isEqual: @"<!-- comment -->"])
	    [[elem[3] stringValue] isEqual: @"<!-- comment -->"])

	TEST(@"-[addAttributeWithName:stringValue:]",
	    R([elem[0] addAttributeWithName: @"foo"
				stringValue: @"b&ar"]) &&
	    [[elem[0] string] isEqual: @"<foo foo='b&amp;ar'/>"] &&
	    [[elem[0] stringValue] isEqual: @"<foo foo='b&amp;ar'/>"] &&
	    R([elem[1] addAttributeWithName: @"foo"
				stringValue: @"b&ar"]) &&
	    [[elem[1] stringValue] isEqual:
	    [[elem[1] string] isEqual: @"<foo foo='b&amp;ar'>b&amp;ar</foo>"])
	    @"<foo foo='b&amp;ar'>b&amp;ar</foo>"])

	TEST(@"-[setPrefix:forNamespace:]",
	    R([elem[1] setPrefix: @"objfw-test"
		    forNamespace: @"urn:objfw:test"]))

	TEST(@"-[addAttributeWithName:namespace:stringValue:]",
	    R([elem[1] addAttributeWithName: @"foo"
				  namespace: @"urn:objfw:test"
				stringValue: @"bar"]) &&
	    [[elem[1] string] isEqual:
	    [[elem[1] stringValue] isEqual:
	    @"<foo foo='b&amp;ar' objfw-test:foo='bar'>b&amp;ar</foo>"])

	TEST(@"-[addChild:]",
	    R([elem[0] addChild: [OFXMLElement elementWithName: @"bar"]]) &&
	    [[elem[0] stringValue] isEqual:
	    [[elem[0] string] isEqual: @"<foo foo='b&amp;ar'><bar/></foo>"] &&
	    @"<foo foo='b&amp;ar'><bar/></foo>"] &&
	    R([elem[2] addChild:
	    [OFXMLElement elementWithName: @"bar"
				namespace: @"urn:objfw:test"]]) &&
	    [[elem[2] string] isEqual:
	    R([elem[2] addChild: [OFXMLElement elementWithName: @"bar"
		      namespace: @"urn:objfw:test"]]) &&
	    [[elem[2] stringValue] isEqual:
	    @"<objfw-test:foo test='test'><objfw-test:bar/></objfw-test:foo>"])

	[pool drain];
}
@end