LMX.framework with my change at http://bitbucket.org/zacwest/lmx-currentindexfix/changeset/9c19b3a4067c/, fixes currentIndex being lost, and repeating elements when processing multiple chunks. Fixes #13362.
5 // Created by Peter Hosey on 2005-10-14.
6 // Copyright 2005 Peter Hosey. All rights reserved.
14 LMXParsedCompletely = 0, //Element stack reached zero depth, and there was no more XML to parse
15 LMXParsedIncomplete = -1, //Element stack is not empty; more data is wanted
16 LMXParsedCompletelyWithExtraData = -2, //Element stack reached zero depth, but there's still XML to parse
19 extern NSString *LMXStringFromParseResult(enum LMXParseResult result);
20 extern enum LMXParseResult LMXParseResultFromString(NSString *result);
22 @interface LMXParser : NSObject {
23 NSMutableData *dataToParse;
26 NSMutableArray *elementStack;
32 NSMutableString *characters;
33 NSMutableString *currentToken;
34 NSMutableString *entityName;
35 NSMutableString *comment;
37 NSMutableDictionary *overrideDict; //Stores any entities that we're using our own values instead of the DTD's values for
38 NSMutableDictionary *cacheDict; //Caches entity values
39 NSMutableDictionary *attributes;
40 NSString *attributeValue;
41 off_t charactersRunStartIndex, tokenRunStartIndex, entityNameRunStartIndex, commentRunStartIndex;
42 off_t greaterThanIndex;
43 unsigned reserved: 22;
44 unsigned inComment: 1;
45 //Start of a comment: <!--
46 // End of a comment: -->
47 unsigned hasBang: 1; //With has{First,Second}Hyphen, indicates a comment may be about to start (if a < is encountered)
48 unsigned hasSecondHyphen: 1; //With hasGreaterThan and hasFirstHyphen, part of the start of a comment
49 unsigned hasFirstHyphen: 1; //With hasGreaterThan, 1/3 of the end of a comment; else, 1/3 of the start of a comment
50 unsigned hasEqualSign: 1; //An attribute value has been recorded, and a = encountered
51 unsigned couldBeEndTag: 1; //A / has been encountered
52 unsigned isEmptyTag: 1; //A / was encountered immediately after a >
53 unsigned inEntity: 1; //In between & and ;
54 unsigned hasHashMark: 1; //A # was just encountered (if this is 1 when the & is encountered, it's a numeric entity; otherwise, the entity ends)
55 unsigned noNonWhitespaceSinceTagEnd: 1; //Used by / to check for a <blah/> tag
56 unsigned inTag: 1; //In between < and >
57 unsigned parsing: 1; //Set to 0 by -pause
58 char attributeQuoteChar; //One of '"', '\'', or '\0'
61 //How to get an autoreleased parser in only one message instead of three:
64 - initWithData:(NSData *)data;
68 - (NSString *)systemID;
69 - (void)setSystemID:(NSString *)sysID;
70 - (void)overrideEntityNamed:(NSString *)name withValue:(NSData *)val;
71 - (void)setOverriddenEntities:(NSDictionary *)entityDict;
72 - (NSData *)dataForEntityNamed:(NSString *)name;
76 - (enum LMXParseResult)parseChunk:(NSData *)data;
78 - (void)addData:(NSData *)data; //Add more data (in front of the existing data) without parsing
79 - (enum LMXParseResult)parse; //Begin/resume parsing without adding more data
83 //Either or both of these can be called by the delegate.
85 - (enum LMXParseResult)resume; //Synonym for -parse
87 //Calling -reset leaves the parser in the same state it was in (more or less) after it was inited.
88 //*Don't* call this from the delegate.
94 - setDelegate:newDelegate; //Returns old delegate.
96 - (void *)contextInfo;
97 - (void)setContextInfo:(void *)newContextInfo;
101 @interface LMXParser (LMXCompatibilityWithNSXMLParser)
103 - initWithData:(NSData *)data; //Same as -init, -addData:
105 - (void)abortParsing; //Compatibility synonym for -pause
109 @interface NSObject (LMXParserDelegate)
111 - (void)parserDidStartDocument:(LMXParser *)parser;
113 - (void)parser:(LMXParser *)parser elementEnded:(NSString *)elementName;
114 //Returns one or two UTF-16 code units, or nil.
115 - (NSData *)parser:(LMXParser *)parser resolveExternalEntityName:(NSString *)entityName systemID:(NSString *)systemID;
116 - (void)parser:(LMXParser *)parser foundCharacters:(NSString *)string;
117 - (void)parser:(LMXParser *)parser elementStarted:(NSString *)elementName attributes:(NSDictionary *)attributes;
119 - (void)parserDidEndDocument:(LMXParser *)parser;
120 - (void)parser:(LMXParser *)parser finishedParsingChunk:(NSData *)chunkData withResult:(enum LMXParseResult)result;