ObjFW  Check-in [d4b3f8ea70]

Overview
Comment:Split XML processing instructions into target/data
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d4b3f8ea703fe6522a2509d38c866e99c2ebc4b938a7a76a4f24b9ac0a5caeaf
User & Date: js on 2021-04-09 01:28:08
Other Links: manifest | tags
Context
2021-04-13
21:43
Simplify OFValue check-in: e41940c022 user: js tags: trunk
2021-04-09
01:28
Split XML processing instructions into target/data check-in: d4b3f8ea70 user: js tags: trunk
2021-04-08
19:30
OFXMLComment: Add a property for the text check-in: f7713f3033 user: js tags: trunk
Changes

Modified src/Makefile from [7d07fd2fda] to [06838b11b3].

93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107







-
+







       OFXMLCharacters.m		\
       OFXMLComment.m			\
       OFXMLElement.m			\
       OFXMLElement+Serialization.m	\
       OFXMLElementBuilder.m		\
       OFXMLNode.m			\
       OFXMLParser.m			\
       OFXMLProcessingInstructions.m	\
       OFXMLProcessingInstruction.m	\
       OFZIPArchive.m			\
       OFZIPArchiveEntry.m		\
       base64.m				\
       crc16.m				\
       crc32.m				\
       huffman_tree.m			\
       of_asprintf.m			\

Modified src/OFXMLElementBuilder.m from [07f6f7fa7b] to [a53bbdbeea].

12
13
14
15
16
17
18
19

20
21
22


23
24

25
26

27
28
29
30
31
32
33
12
13
14
15
16
17
18

19
20


21
22
23

24
25

26
27
28
29
30
31
32
33







-
+

-
-
+
+

-
+

-
+







 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFXMLElementBuilder.h"
#import "OFXMLElement.h"
#import "OFArray.h"
#import "OFXMLAttribute.h"
#import "OFXMLCharacters.h"
#import "OFXMLCDATA.h"
#import "OFXMLCDATA.h"
#import "OFXMLCharacters.h"
#import "OFXMLComment.h"
#import "OFXMLProcessingInstructions.h"
#import "OFXMLElement.h"
#import "OFXMLParser.h"
#import "OFArray.h"
#import "OFXMLProcessingInstruction.h"

#import "OFMalformedXMLException.h"

@implementation OFXMLElementBuilder
@synthesize delegate = _delegate;

+ (instancetype)builder
52
53
54
55
56
57
58
59
60



61
62
63



64
65
66
67
68
69
70
52
53
54
55
56
57
58


59
60
61
62


63
64
65
66
67
68
69
70
71
72







-
-
+
+
+

-
-
+
+
+







- (void)dealloc
{
	[_stack release];

	[super dealloc];
}

-		 (void)parser: (OFXMLParser *)parser
  foundProcessingInstructions: (OFString *)pi
-			  (void)parser: (OFXMLParser *)parser
  foundProcessingInstructionWithTarget: (OFString *)target
				  data: (OFString *)data
{
	OFXMLProcessingInstructions *node = [OFXMLProcessingInstructions
	    processingInstructionsWithString: pi];
	OFXMLProcessingInstruction *node = [OFXMLProcessingInstruction
	    processingInstructionWithTarget: target
				       data: data];
	OFXMLElement *parent = _stack.lastObject;

	if (parent != nil)
		[parent addChild: node];
	else if ([_delegate respondsToSelector:
	    @selector(elementBuilder:didBuildParentlessNode:)])
		[_delegate elementBuilder: self didBuildParentlessNode: node];

Modified src/OFXMLParser.h from [96fc0ba278] to [2b3552397a].

30
31
32
33
34
35
36
37
38


39
40
41



42
43
44



45
46
47
48
49
50
51
30
31
32
33
34
35
36


37
38
39


40
41
42
43


44
45
46
47
48
49
50
51
52
53







-
-
+
+

-
-
+
+
+

-
-
+
+
+







 * @protocol OFXMLParserDelegate OFXMLParser.h ObjFW/OFXMLParser.h
 *
 * @brief A protocol that needs to be implemented by delegates for OFXMLParser.
 */
@protocol OFXMLParserDelegate <OFObject>
@optional
/**
 * @brief This callback is called when the XML parser found processing
 *	  instructions.
 * @brief This callback is called when the XML parser found a processing
 *	  instruction.
 *
 * @param parser The parser which found processing instructions
 * @param processingInstructions The processing instructions
 * @param parser The parser which found a processing instruction
 * @param target The target of the processing instruction
 * @param data The data of the processing instruction
 */
-		 (void)parser: (OFXMLParser *)parser
  foundProcessingInstructions: (OFString *)processingInstructions;
-			  (void)parser: (OFXMLParser *)parser
  foundProcessingInstructionWithTarget: (OFString *)target
				  data: (OFString *)data;

/**
 * @brief This callback is called when the XML parser found the start of a new
 *	  tag.
 *
 * @param parser The parser which found a new tag
 * @param name The name of the tag which just started
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144







-
+







@interface OFXMLParser: OFObject
{
	id <OFXMLParserDelegate> _Nullable _delegate;
	enum of_xml_parser_state {
		OF_XMLPARSER_IN_BYTE_ORDER_MARK,
		OF_XMLPARSER_OUTSIDE_TAG,
		OF_XMLPARSER_TAG_OPENED,
		OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS,
		OF_XMLPARSER_IN_PROCESSING_INSTRUCTION,
		OF_XMLPARSER_IN_TAG_NAME,
		OF_XMLPARSER_IN_CLOSE_TAG_NAME,
		OF_XMLPARSER_IN_TAG,
		OF_XMLPARSER_IN_ATTRIBUTE_NAME,
		OF_XMLPARSER_EXPECT_ATTRIBUTE_EQUAL_SIGN,
		OF_XMLPARSER_EXPECT_ATTRIBUTE_DELIMITER,
		OF_XMLPARSER_IN_ATTRIBUTE_VALUE,

Modified src/OFXMLParser.m from [e395ba83dc] to [02a95773a3].

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







-
-
+
+
-

-
-
+



+
+

+















-
+







#include "config.h"

#define OF_XML_PARSER_M

#include <string.h>

#import "OFXMLParser.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFArray.h"
#import "OFCharacterSet.h"
#import "OFDictionary.h"
#import "OFData.h"
#import "OFXMLAttribute.h"
#import "OFStream.h"
#import "OFDictionary.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif
#import "OFStream.h"
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFXMLAttribute.h"

#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFMalformedXMLException.h"
#import "OFOutOfRangeException.h"
#import "OFUnboundPrefixException.h"

@interface OFXMLParser () <OFStringXMLUnescapingDelegate>
@end

static void inByteOrderMarkState(OFXMLParser *);
static void outsideTagState(OFXMLParser *);
static void tagOpenedState(OFXMLParser *);
static void inProcessingInstructionsState(OFXMLParser *);
static void inProcessingInstructionState(OFXMLParser *);
static void inTagNameState(OFXMLParser *);
static void inCloseTagNameState(OFXMLParser *);
static void inTagState(OFXMLParser *);
static void inAttributeNameState(OFXMLParser *);
static void expectAttributeEqualSignState(OFXMLParser *);
static void expectAttributeDelimiterState(OFXMLParser *);
static void inAttributeValueState(OFXMLParser *);
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
64
65
66
67
68
69
70

71

72
73
74
75
76
77
78







-
+
-







static void inCommentState2(OFXMLParser *);
static void inDOCTYPEState(OFXMLParser *);
typedef void (*state_function_t)(OFXMLParser *);
static state_function_t lookupTable[] = {
	[OF_XMLPARSER_IN_BYTE_ORDER_MARK] = inByteOrderMarkState,
	[OF_XMLPARSER_OUTSIDE_TAG] = outsideTagState,
	[OF_XMLPARSER_TAG_OPENED] = tagOpenedState,
	[OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS] =
	[OF_XMLPARSER_IN_PROCESSING_INSTRUCTION] = inProcessingInstructionState,
	    inProcessingInstructionsState,
	[OF_XMLPARSER_IN_TAG_NAME] = inTagNameState,
	[OF_XMLPARSER_IN_CLOSE_TAG_NAME] = inCloseTagNameState,
	[OF_XMLPARSER_IN_TAG] = inTagState,
	[OF_XMLPARSER_IN_ATTRIBUTE_NAME] = inAttributeNameState,
	[OF_XMLPARSER_EXPECT_ATTRIBUTE_EQUAL_SIGN] =
	    expectAttributeEqualSignState,
	[OF_XMLPARSER_EXPECT_ATTRIBUTE_DELIMITER] =
348
349
350
351
352
353
354
355

356
357
358
359
360
361
362
348
349
350
351
352
353
354

355
356
357
358
359
360
361
362







-
+







	if (self->_finishedParsing && self->_data[self->_i] != '!' &&
	    self->_data[self->_i] != '?')
		@throw [OFMalformedXMLException exceptionWithParser: self];

	switch (self->_data[self->_i]) {
	case '?':
		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS;
		self->_state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTION;
		self->_level = 0;
		break;
	case '/':
		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_IN_CLOSE_TAG_NAME;
		self->_acceptProlog = false;
		break;
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
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







-
+














-
-
-
-
-
+
+







		self->_i--;
		break;
	}
}

/* <?xml […]?> */
static bool
parseXMLProcessingInstructions(OFXMLParser *self, OFString *pi)
parseXMLProcessingInstruction(OFXMLParser *self, OFString *data)
{
	const char *cString;
	size_t length, last;
	int PIState = 0;
	OFString *attribute = nil;
	OFMutableString *value = nil;
	char piDelimiter = 0;
	bool hasVersion = false;

	if (!self->_acceptProlog)
		return false;

	self->_acceptProlog = false;

	pi = [pi substringFromIndex: 3];
	pi = pi.stringByDeletingEnclosingWhitespaces;

	cString = pi.UTF8String;
	length = pi.UTF8StringLength;
	cString = data.UTF8String;
	length = data.UTF8StringLength;

	last = 0;
	for (size_t i = 0; i < length; i++) {
		switch (PIState) {
		case 0:
			if (cString[i] == ' ' || cString[i] == '\t' ||
			    cString[i] == '\r' || cString[i] == '\n')
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
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
513
514
515
516
517
518







-
+

-
+





-
+
+
+





+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+



-
-
+
+

-
+
+








	if (PIState != 0 || !hasVersion)
		return false;

	return true;
}

/* Inside processing instructions */
/* Inside processing instruction */
static void
inProcessingInstructionsState(OFXMLParser *self)
inProcessingInstructionState(OFXMLParser *self)
{
	if (self->_data[self->_i] == '?')
		self->_level = 1;
	else if (self->_level == 1 && self->_data[self->_i] == '>') {
		void *pool = objc_autoreleasePoolPush();
		OFString *PI;
		OFString *PI, *target, *data = nil;
		OFCharacterSet *whitespaceCS;
		size_t pos;

		appendToBuffer(self->_buffer, self->_data + self->_last,
		    self->_encoding, self->_i - self->_last);
		PI = transformString(self, self->_buffer, 1, false);

		whitespaceCS = [OFCharacterSet
		    characterSetWithCharactersInString: @" \r\n\r"];
		pos = [PI indexOfCharacterFromSet: whitespaceCS];
		if (pos != OF_NOT_FOUND) {
			target = [PI substringToIndex: pos];
			data = [[PI substringFromIndex: pos + 1]
			    stringByDeletingEnclosingWhitespaces];
		if ([PI isEqual: @"xml"] || [PI hasPrefix: @"xml "] ||
		    [PI hasPrefix: @"xml\t"] || [PI hasPrefix: @"xml\r"] ||
		    [PI hasPrefix: @"xml\n"])
			if (!parseXMLProcessingInstructions(self, PI))

			if (data.length == 0)
				data = nil;
		} else
			target = PI;

		if ([target caseInsensitiveCompare: @"xml"] == OF_ORDERED_SAME)
			if (!parseXMLProcessingInstruction(self, data))
				@throw [OFMalformedXMLException
				    exceptionWithParser: self];

		if ([self->_delegate respondsToSelector:
		    @selector(parser:foundProcessingInstructions:)])
		if ([self->_delegate respondsToSelector: @selector(
		    parser:foundProcessingInstructionWithTarget:data:)])
			[self->_delegate parser: self
			    foundProcessingInstructions: PI];
			    foundProcessingInstructionWithTarget: target
							    data: data];

		objc_autoreleasePoolPop(pool);

		[self->_buffer removeAllItems];

		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_OUTSIDE_TAG;
544
545
546
547
548
549
550
551
552
553

554
555
556
557
558
559
560
555
556
557
558
559
560
561



562
563
564
565
566
567
568
569







-
-
-
+







				length: tmp - bufferCString];
	} else {
		self->_name = [bufferString copy];
		self->_prefix = nil;
	}

	if (self->_data[self->_i] == '>' || self->_data[self->_i] == '/') {
		OFString *namespace;

		namespace = namespaceForPrefix(self->_prefix,
		OFString *namespace = namespaceForPrefix(self->_prefix,
		    self->_namespaces);

		if (self->_prefix != nil && namespace == nil)
			@throw [OFUnboundPrefixException
			    exceptionWithPrefix: self->_prefix
					 parser: self];

Renamed and modified src/OFXMLProcessingInstructions.h [9211767771] to src/OFXMLProcessingInstruction.h [86de9b9bcd].

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







-
-
+
+

-
+

-
+

-
-
+
+



+
+
+
+
+
+
+
+
+
+
-
+
+

+
-
-
+
+

-
+
+


-
-
+
+

+
-
-
+
+

-
+
+





 */

#import "OFXMLNode.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class OFXMLProcessingInstructions \
 *	  OFXMLProcessingInstructions.h ObjFW/OFXMLProcessingInstructions.h
 * @class OFXMLProcessingInstruction \
 *	  OFXMLProcessingInstruction.h ObjFW/OFXMLProcessingInstruction.h
 *
 * @brief A class for representing XML processing instructions.
 * @brief A class for representing an XML processing instruction.
 */
@interface OFXMLProcessingInstructions: OFXMLNode
@interface OFXMLProcessingInstruction: OFXMLNode
{
	OFString *_processingInstructions;
	OF_RESERVE_IVARS(OFXMLProcessingInstructions, 4)
	OFString *_target, *_data;
	OF_RESERVE_IVARS(OFXMLProcessingInstruction, 4)
}

/**
 * @brief The target of the processing instruction.
 */
@property (readonly, nonatomic) OFString *target;

/**
 * @brief The data of the processing instruction.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *data;

/**
 * @brief Creates a new OFXMLProcessingInstructions with the specified string.
 * @brief Creates a new OFXMLProcessingInstruction with the specified target
 *	  and data.
 *
 * @param target The target for the processing instruction
 * @param string The string for the processing instructions
 * @return A new OFXMLProcessingInstructions
 * @param data The data for the processing instruction
 * @return A new OFXMLProcessingInstruction
 */
+ (instancetype)processingInstructionsWithString: (OFString *)string;
+ (instancetype)processingInstructionWithTarget: (OFString *)target
					   data: (OFString *)data;

/**
 * @brief Initializes an already allocated OFXMLProcessingInstructions with the
 *	  specified string.
 * @brief Initializes an already allocated OFXMLProcessingInstruction with the
 *	  specified target and data.
 *
 * @param target The target for the processing instruction
 * @param string The string for the processing instructions
 * @return An initialized OFXMLProcessingInstructions
 * @param data The data for the processing instruction
 * @return An initialized OFXMLProcessingInstruction
 */
- (instancetype)initWithString: (OFString *)string;
- (instancetype)initWithTarget: (OFString *)target
			  data: (OFString *)data OF_DESIGNATED_INITIALIZER;

- (instancetype)initWithSerialization: (OFXMLElement *)element;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/OFXMLProcessingInstructions.m [aed6fd90fa] to src/OFXMLProcessingInstruction.m [14a03b0d16].

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







-
-
-
+
+
+

+



-
-
+
+
+
+
+

-
+
+


-
+
+




+
-
+










-
-


+





+
+
+
+
+
+
-
+












+
-
+






-
+




-
+


-
+

+
+
+
-
-
+
+
+
+
+




+
+
+
+
+
+
+
-
+









+
-
+
+
+
+




-
+





-
-

+





+
-
-
+
+
+
+
+
+



-
-
-

-
+
+
+




-
+




-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

 * file.
 */

#include "config.h"

#include <string.h>

#import "OFXMLProcessingInstructions.h"
#import "OFXMLNode+Private.h"
#import "OFString.h"
#import "OFXMLProcessingInstruction.h"
#import "OFString.h"
#import "OFXMLAttribute.h"
#import "OFXMLElement.h"
#import "OFXMLNode+Private.h"

#import "OFInvalidArgumentException.h"

@implementation OFXMLProcessingInstructions
+ (instancetype)processingInstructionsWithString: (OFString *)string
@implementation OFXMLProcessingInstruction
@synthesize target = _target, data = _data;

+ (instancetype)processingInstructionWithTarget: (OFString *)target
					   data: (OFString *)data
{
	return [[[self alloc] initWithString: string] autorelease];
	return [[[self alloc] initWithTarget: target
					data: data] autorelease];
}

- (instancetype)initWithString: (OFString *)string
- (instancetype)initWithTarget: (OFString *)target
			  data: (OFString *)data
{
	self = [super of_init];

	@try {
		_target = [target copy];
		_processingInstructions = [string copy];
		_data = [data copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

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

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFXMLAttribute *targetAttr;

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

		targetAttr = [element attributeForName: @"target"
					     namespace: OF_SERIALIZATION_NS];
		if (targetAttr.stringValue.length == 0)
			@throw [OFInvalidArgumentException exception];

		self = [self initWithTarget: targetAttr.stringValue
		_processingInstructions = [element.stringValue copy];
				       data: element.stringValue];

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

	return self;
}

- (void)dealloc
{
	[_target release];
	[_processingInstructions release];
	[_data release];

	[super dealloc];
}

- (bool)isEqual: (id)object
{
	OFXMLProcessingInstructions *processingInstructions;
	OFXMLProcessingInstruction *processingInstruction;

	if (object == self)
		return true;

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

	processingInstructions = object;
	processingInstruction = object;

	if (![processingInstruction->_target isEqual: _target])
		return false;

	return [processingInstructions->_processingInstructions
	    isEqual: _processingInstructions];
	if (processingInstruction->_data != _data &&
	    ![processingInstruction->_data isEqual: _data])
		return false;

	return true;
}

- (unsigned long)hash
{
	unsigned long hash;

	OF_HASH_INIT(hash);
	OF_HASH_ADD_HASH(hash, _target.hash);
	OF_HASH_ADD_HASH(hash, _data.hash);
	OF_HASH_FINALIZE(hash);

	return _processingInstructions.hash;
	return hash;
}

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

- (OFString *)XMLString
{
	if (_data.length > 0)
	return [OFString stringWithFormat: @"<?%@?>", _processingInstructions];
		return [OFString stringWithFormat: @"<?%@ %@?>",
						   _target, _data];
	else
		return [OFString stringWithFormat: @"<?%@?>", _target];
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
{
	return [OFString stringWithFormat: @"<?%@?>", _processingInstructions];
	return self.XMLString;
}

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

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

		@try {
			if (_data.length > 0)
			ret = [OFString stringWithFormat:
			    @"%s<?%@?>", whitespaces, _processingInstructions];
				ret = [OFString stringWithFormat:
				    @"%s<?%@ %@?>", whitespaces,
				    _target, _data];
			else
				ret = [OFString stringWithFormat:
				    @"%s<?%@?>", whitespaces, _target];
		} @finally {
			free(whitespaces);
		}
	} else
		ret = [OFString stringWithFormat: @"<?%@?>",
						  _processingInstructions];

	return ret;
		return ret;
	} else
		return self.XMLString;
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"<?%@?>", _processingInstructions];
	return self.XMLString;
}

- (OFXMLElement *)XMLElementBySerializing
{
	return [OFXMLElement elementWithName: self.className
				   namespace: OF_SERIALIZATION_NS
				 stringValue: _processingInstructions];
}
	OFXMLElement *ret = [OFXMLElement elementWithName: self.className
						namespace: OF_SERIALIZATION_NS
					      stringValue: _data];
	void *pool = objc_autoreleasePoolPush();

	[ret addAttribute: [OFXMLAttribute attributeWithName: @"target"
						 stringValue: _target]];

	objc_autoreleasePoolPop(pool);

	return ret;
}
@end

Modified src/ObjFW.h from [2e31ed4971] to [35df895e07].

112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126







-
+








#import "OFXMLAttribute.h"
#import "OFXMLElement.h"
#import "OFXMLAttribute.h"
#import "OFXMLCharacters.h"
#import "OFXMLCDATA.h"
#import "OFXMLComment.h"
#import "OFXMLProcessingInstructions.h"
#import "OFXMLProcessingInstruction.h"
#import "OFXMLParser.h"
#import "OFXMLElementBuilder.h"

#import "OFMessagePackExtension.h"

#import "OFApplication.h"
#import "OFSystemInfo.h"

Modified tests/OFXMLParserTests.m from [c56cc9efc9] to [20f4783b1c].

20
21
22
23
24
25
26
27

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

27
28
29
30
31
32
33
34







-
+








#import "TestsAppDelegate.h"

static OFString *module = @"OFXMLParser";
static int i = 0;

enum event_type {
	PROCESSING_INSTRUCTIONS,
	PROCESSING_INSTRUCTION,
	TAG_OPEN,
	TAG_CLOSE,
	STRING,
	CDATA,
	COMMENT
};

44
45
46
47
48
49
50
51
52



53
54
55
56


57
58
59
60
61
62
63
44
45
46
47
48
49
50


51
52
53
54
55


56
57
58
59
60
61
62
63
64







-
-
+
+
+


-
-
+
+







	OFString *msg;

	i++;
	msg = [OFString stringWithFormat: @"Parsing part #%d", i];

	switch (i) {
	case 1:
		TEST(msg, type == PROCESSING_INSTRUCTIONS &&
		    [string isEqual: @"xml version='1.0'"])
		TEST(msg, type == PROCESSING_INSTRUCTION &&
		    [name isEqual: @"xml"] &&
		    [string isEqual: @"version='1.0'"])
		break;
	case 2:
		TEST(msg, type == PROCESSING_INSTRUCTIONS &&
		    [string isEqual: @"p?i"])
		TEST(msg, type == PROCESSING_INSTRUCTION &&
		    [name isEqual: @"p?i"] && string == nil)
		break;
	case 3:
		TEST(msg, type == TAG_OPEN && [name isEqual: @"root"] &&
		    prefix == nil && ns == nil && attrs.count == 0)
		break;
	case 4:
		TEST(msg, type == STRING && [string isEqual: @"\n\n "])
228
229
230
231
232
233
234
235
236



237
238
239
240


241
242
243
244

245
246
247
248
249
250
251
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







-
-
+
+
+


-
-
+
+



-
+







	case 32:
		TEST(msg, type == TAG_CLOSE && [name isEqual: @"root"] &&
		    prefix == nil && ns == nil);
		break;
	}
}

-		 (void)parser: (OFXMLParser *)parser
  foundProcessingInstructions: (OFString *)pi
-			  (void)parser: (OFXMLParser *)parser
  foundProcessingInstructionWithTarget: (OFString *)target
				  data: (OFString *)data
{
	[self	    parser: parser
	    didCreateEvent: PROCESSING_INSTRUCTIONS
		      name: nil
	    didCreateEvent: PROCESSING_INSTRUCTION
		      name: target
		    prefix: nil
		 namespace: nil
		attributes: nil
		    string: pi];
		    string: data];
}

-    (void)parser: (OFXMLParser *)parser
  didStartElement: (OFString *)name
	   prefix: (OFString *)prefix
	namespace: (OFString *)ns
       attributes: (OFArray *)attrs
367
368
369
370
371
372
373
374

375
376
377
378
379

380
381
382
383
384

385
386
387
388
389
390
369
370
371
372
373
374
375

376
377
378
379
380

381
382
383
384
385

386
387
388
389
390
391
392







-
+




-
+




-
+






	EXPECT_EXCEPTION(@"Detection of junk after the document #1",
	    OFMalformedXMLException, [parser parseString: @"a"])

	EXPECT_EXCEPTION(@"Detection of junk after the document #2",
	    OFMalformedXMLException, [parser parseString: @"<!["])

	parser = [OFXMLParser parser];
	EXPECT_EXCEPTION(@"Detection of invalid XML processing instructions #1",
	EXPECT_EXCEPTION(@"Detection of invalid XML processing instruction #1",
	    OFMalformedXMLException,
	    [parser parseString: @"<?xml version='2.0'?>"])

	parser = [OFXMLParser parser];
	EXPECT_EXCEPTION(@"Detection of invalid XML processing instructions #2",
	EXPECT_EXCEPTION(@"Detection of invalid XML processing instruction #2",
	    OFInvalidEncodingException,
	    [parser parseString: @"<?xml encoding='UTF-7'?>"])

	parser = [OFXMLParser parser];
	EXPECT_EXCEPTION(@"Detection of invalid XML processing instructions #3",
	EXPECT_EXCEPTION(@"Detection of invalid XML processing instruction #3",
	    OFMalformedXMLException,
	    [parser parseString: @"<x><?xml?></x>"])

	objc_autoreleasePoolPop(pool);
}
@end