ObjFW  Check-in [4ea5f3f7fd]

Overview
Comment:Rename +[elementWithText:] to +[elementWithCharacters:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4ea5f3f7fd437821a404d687cdcf4a7c5af6a98953412dde91133b69752ea6cc
User & Date: js on 2010-07-02 20:45:34
Other Links: manifest | tags
Context
2010-07-02
20:56
Add support for CDATA to OFXMLElement. check-in: e2499be5c1 user: js tags: trunk
20:45
Rename +[elementWithText:] to +[elementWithCharacters:]. check-in: 4ea5f3f7fd user: js tags: trunk
2010-06-27
12:21
Fix a wrong typedef in threading.h. check-in: e45069a556 user: js tags: trunk
Changes

Modified src/OFPlugin.m from [7906a08f5e] to [510d0be2d3].

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

#import "OFPlugin.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"

#ifdef _WIN32
#define dlopen(file, mode) LoadLibrary(file)
#define dlsym(handle, symbol) GetProcAddress(handle, symbol)
#define dlclose(handle) FreeLibrary(handle)
#endif

@implementation OFPlugin
+ pluginFromFile: (OFString*)path
{
	OFAutoreleasePool *pool;
	OFMutableString *file;







|
|
|







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

#import "OFPlugin.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"

#ifdef _WIN32
# define dlopen(file, mode) LoadLibrary(file)
# define dlsym(handle, symbol) GetProcAddress(handle, symbol)
# define dlclose(handle) FreeLibrary(handle)
#endif

@implementation OFPlugin
+ pluginFromFile: (OFString*)path
{
	OFAutoreleasePool *pool;
	OFMutableString *file;

Modified src/OFXMLElement.h from [ab1302a21f] to [c4cba39561].

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
	OFString *name;
	OFString *namespace;
	OFString *defaultNamespace;
	OFMutableArray *attributes;
	OFMutableDictionary *namespaces;
	OFMutableArray *children;
	OFString *text;
	OFMutableString *comment;
}

/**
 * \param name The name for the element
 * \return A new autoreleased OFXMLElement with the specified element name
 */







|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
	OFString *name;
	OFString *namespace;
	OFString *defaultNamespace;
	OFMutableArray *attributes;
	OFMutableDictionary *namespaces;
	OFMutableArray *children;
	OFString *characters;
	OFMutableString *comment;
}

/**
 * \param name The name for the element
 * \return A new autoreleased OFXMLElement with the specified element name
 */
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
 *	   namespace and value
 */
+ elementWithName: (OFString*)name
	namespace: (OFString*)ns
      stringValue: (OFString*)stringval;

/**
 * Creates a new element, only consisting of the specified text.
 *
 * \param text The text the element represents
 * \return A new autoreleased OFXMLElement consisting of the specified text

 */
+ elementWithText: (OFString*)text;

/**
 * Creates a new element, only consisting of the specified comment.
 *
 * \param comment The comment the element represents
 * \return A new autoreleased OFXMLElement consisting of the specified comment
 */
+ elementWithComment: (OFString*)text;

/**
 * Initializes an already allocated OFXMLElement with the specified element
 * name.
 *
 * \param name The name for the element
 * \return An initialized OFXMLElement with the specified element name







|

|
|
>

|







|







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
 *	   namespace and value
 */
+ elementWithName: (OFString*)name
	namespace: (OFString*)ns
      stringValue: (OFString*)stringval;

/**
 * Creates a new element, only consisting of the specified characters.
 *
 * \param chars The characters the element represents
 * \return A new autoreleased OFXMLElement consisting of the specified
 *	   characters
 */
+ elementWithCharacters: (OFString*)chars;

/**
 * Creates a new element, only consisting of the specified comment.
 *
 * \param comment The comment the element represents
 * \return A new autoreleased OFXMLElement consisting of the specified comment
 */
+ elementWithComment: (OFString*)comment;

/**
 * Initializes an already allocated OFXMLElement with the specified element
 * name.
 *
 * \param name The name for the element
 * \return An initialized OFXMLElement with the specified element name
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
 */
- initWithName: (OFString*)name
     namespace: (OFString*)ns
   stringValue: (OFString*)stringval;

/**
 * Initializes an already allocated OFXMLElement so that it only consists of the
 * specified text.
 *
 * \param text The text the element represents
 * \return An initialized OFXMLElement consisting of the specified text
 */
- initWithText: (OFString*)text;

/**
 * Initializes an already allocated OFXMLElement so that it only consists of the
 * specified comment.
 *
 * \param comment The comment the element represents
 * \return An initialized OFXMLElement consisting of the specified comment
 */
- initWithComment: (OFString*)text;

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








|

|
|

|








|







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
 */
- initWithName: (OFString*)name
     namespace: (OFString*)ns
   stringValue: (OFString*)stringval;

/**
 * Initializes an already allocated OFXMLElement so that it only consists of the
 * specified characters.
 *
 * \param chars The characters the element represents
 * \return An initialized OFXMLElement consisting of the specified characters
 */
- initWithCharacters: (OFString*)chars;

/**
 * Initializes an already allocated OFXMLElement so that it only consists of the
 * specified comment.
 *
 * \param comment The comment the element represents
 * \return An initialized OFXMLElement consisting of the specified comment
 */
- initWithComment: (OFString*)comment;

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

Modified src/OFXMLElement.m from [9fef639632] to [05eb8e5213].

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
      stringValue: (OFString*)stringval
{
	return [[[self alloc] initWithName: name
				 namespace: ns
			       stringValue: stringval] autorelease];
}

+ elementWithText: (OFString*)text
{
	return [[[self alloc] initWithText: text] autorelease];
}

+ elementWithComment: (OFString*)comment
{
	return [[[self alloc] initWithComment: comment] autorelease];
}








|

|







47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
      stringValue: (OFString*)stringval
{
	return [[[self alloc] initWithName: name
				 namespace: ns
			       stringValue: stringval] autorelease];
}

+ elementWithCharacters: (OFString*)chars
{
	return [[[self alloc] initWithCharacters: chars] autorelease];
}

+ elementWithComment: (OFString*)comment
{
	return [[[self alloc] initWithComment: comment] autorelease];
}

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
	self = [super init];

	name = [name_ copy];
	namespace = [ns copy];

	if (stringval != nil) {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];;
		[self addChild: [OFXMLElement elementWithText: stringval]];

		[pool release];
	}

	namespaces = [[OFMutableDictionary alloc] initWithKeysAndObjects:
	    @"http://www.w3.org/XML/1998/namespace", @"xml",
	    @"http://www.w3.org/2000/xmlns/", @"xmlns", nil];

	return self;
}

- initWithText: (OFString*)text_
{
	self = [super init];

	text = [text_ copy];

	return self;
}

- initWithComment: (OFString*)comment_
{
	self = [super init];







|
>










|



|







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
	self = [super init];

	name = [name_ copy];
	namespace = [ns copy];

	if (stringval != nil) {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];;
		[self addChild:
		    [OFXMLElement elementWithCharacters: stringval]];
		[pool release];
	}

	namespaces = [[OFMutableDictionary alloc] initWithKeysAndObjects:
	    @"http://www.w3.org/XML/1998/namespace", @"xml",
	    @"http://www.w3.org/2000/xmlns/", @"xmlns", nil];

	return self;
}

- initWithCharacters: (OFString*)chars
{
	self = [super init];

	characters = [chars copy];

	return self;
}

- initWithComment: (OFString*)comment_
{
	self = [super init];
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
	size_t len, i, j, attrs_count;
	OFString *prefix = nil;
	OFXMLAttribute **attrs_carray;
	OFString *ret, *tmp;
	OFMutableDictionary *all_namespaces;
	OFString *def_ns;

	if (text != nil)
		return [text stringByXMLEscaping];

	if (comment != nil) {
		OFMutableString *str;

		str = [OFMutableString stringWithString: @"<!--"];
		[str appendString: comment];
		[str appendString: @"-->"];







|
|







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
	size_t len, i, j, attrs_count;
	OFString *prefix = nil;
	OFXMLAttribute **attrs_carray;
	OFString *ret, *tmp;
	OFMutableDictionary *all_namespaces;
	OFString *def_ns;

	if (characters != nil)
		return [characters stringByXMLEscaping];

	if (comment != nil) {
		OFMutableString *str;

		str = [OFMutableString stringWithString: @"<!--"];
		[str appendString: comment];
		[str appendString: @"-->"];
427
428
429
430
431
432
433
434
435
436
437
438
439
- (void)dealloc
{
	[name release];
	[namespace release];
	[attributes release];
	[namespaces release];
	[children release];
	[text release];
	[comment release];

	[super dealloc];
}
@end







|





428
429
430
431
432
433
434
435
436
437
438
439
440
- (void)dealloc
{
	[name release];
	[namespace release];
	[attributes release];
	[namespaces release];
	[children release];
	[characters release];
	[comment release];

	[super dealloc];
}
@end

Modified tests/OFXMLElementTests.m from [e3337d2bec] to [3f6cbf99e7].

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
	    (elem[3] = [OFXMLElement elementWithName: @"foo"
					   namespace: @"urn:objfw:test"
					 stringValue: @"x"]) &&
	    R([elem[3] setPrefix: @"objfw-test"
		    forNamespace: @"urn:objfw:test"]) &&
	    [[elem[3] string] isEqual: @"<objfw-test:foo>x</objfw-test:foo>"])

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

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

	TEST(@"-[addAttributeWithName:stringValue:]",







|
|







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
	    (elem[3] = [OFXMLElement elementWithName: @"foo"
					   namespace: @"urn:objfw:test"
					 stringValue: @"x"]) &&
	    R([elem[3] setPrefix: @"objfw-test"
		    forNamespace: @"urn:objfw:test"]) &&
	    [[elem[3] string] isEqual: @"<objfw-test:foo>x</objfw-test:foo>"])

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

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

	TEST(@"-[addAttributeWithName:stringValue:]",