ObjFW
OFXMLParser.h
1 /*
2  * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFObject.h"
21 #import "OFString.h"
22 #import "OFXMLAttribute.h"
23 
24 OF_ASSUME_NONNULL_BEGIN
25 
26 @class OFArray OF_GENERIC(ObjectType);
27 @class OFMutableData;
28 @class OFMutableArray OF_GENERIC(ObjectType);
29 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
30 @class OFStream;
31 @class OFXMLParser;
32 
38 @protocol OFXMLParserDelegate <OFObject>
39 @optional
48 - (void)parser: (OFXMLParser *)parser
49  foundProcessingInstructionWithTarget: (OFString *)target
50  text: (nullable OFString *)text;
51 
63 - (void)parser: (OFXMLParser *)parser
64  didStartElement: (OFString *)name
65  prefix: (nullable OFString *)prefix
66  namespace: (nullable OFString *)nameSpace
67  attributes: (nullable OFArray OF_GENERIC(OFXMLAttribute *) *)attributes;
68 
77 - (void)parser: (OFXMLParser *)parser
78  didEndElement: (OFString *)name
79  prefix: (nullable OFString *)prefix
80  namespace: (nullable OFString *)nameSpace;
81 
91 - (void)parser: (OFXMLParser *)parser foundCharacters: (OFString *)characters;
92 
99 - (void)parser: (OFXMLParser *)parser foundCDATA: (OFString *)CDATA;
100 
107 - (void)parser: (OFXMLParser *)parser foundComment: (OFString *)comment;
108 
121 - (nullable OFString *)parser: (OFXMLParser *)parser
122  foundUnknownEntityNamed: (OFString *)entity;
123 @end
124 
133 OF_SUBCLASSING_RESTRICTED
135 {
136  id <OFXMLParserDelegate> _Nullable _delegate;
137  uint_least8_t _state;
138  size_t _i, _last;
139  const char *_Nullable _data;
140  OFMutableData *_buffer;
141  OFString *_Nullable _name, *_Nullable _prefix;
143  OF_GENERIC(OFMutableDictionary OF_GENERIC(OFString *, OFString *) *)
144  *_namespaces;
145  OFMutableArray OF_GENERIC(OFXMLAttribute *) *_attributes;
146  OFString *_Nullable _attributeName, *_Nullable _attributePrefix;
147  char _delimiter;
148  OFMutableArray OF_GENERIC(OFString *) *_previous;
149  size_t _level;
150  bool _acceptProlog;
151  size_t _lineNumber;
152  bool _lastCarriageReturn, _finishedParsing;
153  OFStringEncoding _encoding;
154  size_t _depthLimit;
155 }
156 
160 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
161  id <OFXMLParserDelegate> delegate;
162 
166 @property (readonly, nonatomic) size_t lineNumber;
167 
171 @property (readonly, nonatomic, getter=hasFinishedParsing) bool finishedParsing;
172 
180 @property (nonatomic) size_t depthLimit;
181 
187 + (instancetype)parser;
188 
199 - (void)parseBuffer: (const char *)buffer length: (size_t)length;
200 
210 - (void)parseString: (OFString *)string;
211 
221 - (void)parseStream: (OFStream *)stream;
222 @end
223 
224 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:107
A representation of an attribute of an XML element as an object.
Definition: OFXMLAttribute.h:32
OFStringEncoding
The encoding of a string.
Definition: OFString.h:65
The root class for all other classes inside ObjFW.
Definition: OFObject.h:690
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:47
A base class for different types of streams.
Definition: OFStream.h:278
A class for handling strings.
Definition: OFString.h:142
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:46
A protocol that needs to be implemented by delegates for OFXMLParser.
Definition: OFXMLParser.h:31
An event-based XML parser.
Definition: OFXMLParser.h:134
A class for storing and manipulating arbitrary data in an array.
Definition: OFMutableData.h:29