ObjFW  Diff

Differences From Artifact [5cb4fa05d6]:

To Artifact [ba94b5bb12]:


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







+
+
-
+

-
+


-
+




-
+
















-
+


-
+












-
+
















-
+




-
+









-
+




-
+








-
+





-
+
-

-
+


-
+






-
+





-
-
+
+


#import "OFXMLNode+Private.h"
#import "OFString.h"
#import "OFXMLElement.h"

#import "OFInvalidArgumentException.h"

@implementation OFXMLComment
@synthesize text = _text;

+ (instancetype)commentWithString: (OFString *)string
+ (instancetype)commentWithText: (OFString *)text
{
	return [[[self alloc] initWithString: string] autorelease];
	return [[[self alloc] initWithText: text] autorelease];
}

- (instancetype)initWithString: (OFString *)string
- (instancetype)initWithText: (OFString *)text
{
	self = [super of_init];

	@try {
		_comment = [string copy];
		_text = [text copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	self = [super of_init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		if (![element.name isEqual: self.className] ||
		    ![element.namespace isEqual: OF_SERIALIZATION_NS])
		    ![element.namespace isEqual: OFSerializationNS])
			@throw [OFInvalidArgumentException exception];

		_comment = [element.stringValue copy];
		_text = [element.stringValue copy];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_comment release];
	[_text release];

	[super dealloc];
}

- (bool)isEqual: (id)object
{
	OFXMLComment *comment;

	if (object == self)
		return true;

	if (![object isKindOfClass: [OFXMLComment class]])
		return false;

	comment = object;

	return ([comment->_comment isEqual: _comment]);
	return ([comment->_text isEqual: _text]);
}

- (unsigned long)hash
{
	return _comment.hash;
	return _text.hash;
}

- (OFString *)stringValue
{
	return @"";
}

- (OFString *)XMLString
{
	return [OFString stringWithFormat: @"<!--%@-->", _comment];
	return [OFString stringWithFormat: @"<!--%@-->", _text];
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
{
	return [OFString stringWithFormat: @"<!--%@-->", _comment];
	return [OFString stringWithFormat: @"<!--%@-->", _text];
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
				 level: (unsigned int)level
{
	OFString *ret;

	if (indentation > 0 && level > 0) {
		char *whitespaces = of_alloc((level * indentation) + 1, 1);
		char *whitespaces = OFAllocMemory((level * indentation) + 1, 1);
		memset(whitespaces, ' ', level * indentation);
		whitespaces[level * indentation] = 0;

		@try {
			ret = [OFString stringWithFormat: @"%s<!--%@-->",
							  whitespaces,
							  whitespaces, _text];
							  _comment];
		} @finally {
			free(whitespaces);
			OFFreeMemory(whitespaces);
		}
	} else
		ret = [OFString stringWithFormat: @"<!--%@-->", _comment];
		ret = [OFString stringWithFormat: @"<!--%@-->", _text];

	return ret;
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"<!--%@-->", _comment];
	return [OFString stringWithFormat: @"<!--%@-->", _text];
}

- (OFXMLElement *)XMLElementBySerializing
{
	return [OFXMLElement elementWithName: self.className
				   namespace: OF_SERIALIZATION_NS
				 stringValue: _comment];
				   namespace: OFSerializationNS
				 stringValue: _text];
}
@end