Frameworks/LMX.framework/Versions/A/Headers/LMXParser.h
author Zachary West <zacw@adium.im>
Thu Nov 26 10:59:17 2009 -0500 (2009-11-26)
changeset 2830 fd43f6298e71
parent 0 e22ad6bc8b46
child 3349 327927ad486c
permissions -rw-r--r--
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.
     1 //
     2 //  LMXParser.h
     3 //  LMX
     4 //
     5 //  Created by Peter Hosey on 2005-10-14.
     6 //  Copyright 2005 Peter Hosey. All rights reserved.
     7 //
     8 
     9 #include <sys/types.h>
    10 
    11 @class NSString;
    12 
    13 enum LMXParseResult {
    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
    17 };
    18 
    19 extern NSString *LMXStringFromParseResult(enum LMXParseResult result);
    20 extern enum LMXParseResult LMXParseResultFromString(NSString *result);
    21 
    22 @interface LMXParser : NSObject {
    23 	NSMutableData *dataToParse;
    24 	off_t currentIndex;
    25 
    26 	NSMutableArray *elementStack;
    27 
    28 	id delegate;
    29 	void *contextInfo;
    30 
    31 	//Parser state
    32 	NSMutableString *characters;
    33 	NSMutableString *currentToken;
    34 	NSMutableString *entityName;
    35 	NSMutableString *comment;
    36 	NSString *systemID;
    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'
    59 }
    60 
    61 //How to get an autoreleased parser in only one message instead of three:
    62 + parser;
    63 
    64 - initWithData:(NSData *)data;
    65 
    66 #pragma mark -
    67 
    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;
    73 
    74 #pragma mark -
    75 
    76 - (enum LMXParseResult)parseChunk:(NSData *)data;
    77 
    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
    80 
    81 #pragma mark -
    82 
    83 //Either or both of these can be called by the delegate.
    84 - (void)pause;
    85 - (enum LMXParseResult)resume; //Synonym for -parse
    86 
    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.
    89 - (void)reset;
    90 
    91 #pragma mark -
    92 
    93 - delegate;
    94 - setDelegate:newDelegate; //Returns old delegate.
    95 
    96 - (void *)contextInfo;
    97 - (void)setContextInfo:(void *)newContextInfo;
    98 
    99 @end
   100 
   101 @interface LMXParser (LMXCompatibilityWithNSXMLParser)
   102 
   103 - initWithData:(NSData *)data; //Same as -init, -addData:
   104 
   105 - (void)abortParsing; //Compatibility synonym for -pause
   106 
   107 @end
   108 
   109 @interface NSObject (LMXParserDelegate)
   110 
   111 - (void)parserDidStartDocument:(LMXParser *)parser;
   112 
   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;
   118 
   119 - (void)parserDidEndDocument:(LMXParser *)parser;
   120 - (void)parser:(LMXParser *)parser finishedParsingChunk:(NSData *)chunkData withResult:(enum LMXParseResult)result;
   121 
   122 @end