ObjFW
OFXMLParser.h
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 #import "OFString.h"
18 #import "OFXMLAttribute.h"
19 
20 OF_ASSUME_NONNULL_BEGIN
21 
22 @class OFArray OF_GENERIC(ObjectType);
23 @class OFMutableData;
24 @class OFMutableArray OF_GENERIC(ObjectType);
25 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
26 @class OFStream;
27 @class OFXMLParser;
28 
35 @optional
43 - (void)parser: (OFXMLParser *)parser
44  foundProcessingInstructions: (OFString *)processingInstructions;
45 
57 - (void)parser: (OFXMLParser *)parser
58  didStartElement: (OFString *)name
59  prefix: (nullable OFString *)prefix
60  namespace: (nullable OFString *)ns
61  attributes: (nullable OFArray OF_GENERIC(OFXMLAttribute *) *)attributes;
62 
71 - (void)parser: (OFXMLParser *)parser
72  didEndElement: (OFString *)name
73  prefix: (nullable OFString *)prefix
74  namespace: (nullable OFString *)ns;
75 
85 - (void)parser: (OFXMLParser *)parser foundCharacters: (OFString *)characters;
86 
93 - (void)parser: (OFXMLParser *)parser foundCDATA: (OFString *)CDATA;
94 
101 - (void)parser: (OFXMLParser *)parser foundComment: (OFString *)comment;
102 
115 - (nullable OFString *)parser: (OFXMLParser *)parser
116  foundUnknownEntityNamed: (OFString *)entity;
117 @end
118 
127 OF_SUBCLASSING_RESTRICTED
129 {
130  id <OFXMLParserDelegate> _Nullable _delegate;
131  enum of_xml_parser_state {
132  OF_XMLPARSER_IN_BYTE_ORDER_MARK,
133  OF_XMLPARSER_OUTSIDE_TAG,
134  OF_XMLPARSER_TAG_OPENED,
135  OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS,
136  OF_XMLPARSER_IN_TAG_NAME,
137  OF_XMLPARSER_IN_CLOSE_TAG_NAME,
138  OF_XMLPARSER_IN_TAG,
139  OF_XMLPARSER_IN_ATTRIBUTE_NAME,
140  OF_XMLPARSER_EXPECT_ATTRIBUTE_EQUAL_SIGN,
141  OF_XMLPARSER_EXPECT_ATTRIBUTE_DELIMITER,
142  OF_XMLPARSER_IN_ATTRIBUTE_VALUE,
143  OF_XMLPARSER_EXPECT_TAG_CLOSE,
144  OF_XMLPARSER_EXPECT_SPACE_OR_TAG_CLOSE,
145  OF_XMLPARSER_IN_EXCLAMATION_MARK,
146  OF_XMLPARSER_IN_CDATA_OPENING,
147  OF_XMLPARSER_IN_CDATA,
148  OF_XMLPARSER_IN_COMMENT_OPENING,
149  OF_XMLPARSER_IN_COMMENT_1,
150  OF_XMLPARSER_IN_COMMENT_2,
151  OF_XMLPARSER_IN_DOCTYPE
152  } _state;
153  size_t _i, _last;
154  const char *_Nullable _data;
155  OFMutableData *_buffer;
156  OFString *_Nullable _name, *_Nullable _prefix;
158  OF_GENERIC(OFMutableDictionary OF_GENERIC(OFString *, OFString *) *)
159  *_namespaces;
160  OFMutableArray OF_GENERIC(OFXMLAttribute *) *_attributes;
161  OFString *_Nullable _attributeName, *_Nullable _attributePrefix;
162  char _delimiter;
163  OFMutableArray OF_GENERIC(OFString *) *_previous;
164  size_t _level;
165  bool _acceptProlog;
166  size_t _lineNumber;
167  bool _lastCarriageReturn, _finishedParsing;
168  of_string_encoding_t _encoding;
169  size_t _depthLimit;
170 }
171 
175 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
177 
181 @property (readonly, nonatomic) size_t lineNumber;
182 
186 @property (readonly, nonatomic) bool hasFinishedParsing;
187 
195 @property (nonatomic) size_t depthLimit;
196 
202 + (instancetype)parser;
203 
210 - (void)parseBuffer: (const char *)buffer length: (size_t)length;
211 
217 - (void)parseString: (OFString *)string;
218 
224 - (void)parseStream: (OFStream *)stream;
225 @end
226 
227 OF_ASSUME_NONNULL_END
of_string_encoding_t
The encoding of a string.
Definition: OFString.h:68
struct objc_object * id
A pointer to any object.
Definition: ObjFWRT.h:90
An abstract class for storing objects in an array.
Definition: OFArray.h:92
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:44
A class for storing and manipulating arbitrary data in an array.
Definition: OFMutableData.h:29
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:44
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A base class for different types of streams.
Definition: OFStream.h:191
A class for handling strings.
Definition: OFString.h:132
A representation of an attribute of an XML element as an object.
Definition: OFXMLAttribute.h:28
An event-based XML parser.
Definition: OFXMLParser.h:129
A protocol that needs to be implemented by delegates for OFXMLParser.
Definition: OFXMLParser.h:34