@@ -150,13 +150,13 @@ if ([cache length] > 0) { OFString *str; pool = [[OFAutoreleasePool alloc] init]; str = transform_string(cache, self); + str = [[str copy] autorelease]; [delegate xmlParser: self foundString: str]; - [pool release]; } [cache setToCString: ""]; @@ -168,10 +168,13 @@ /* Tag was just opened */ case OF_XMLPARSER_TAG_OPENED: if (buf[i] == '/') { last = i + 1; state = OF_XMLPARSER_IN_CLOSE_TAG_NAME; + } else if(buf[i] == '!') { + last = i + 1; + state = OF_XMLPARSER_IN_COMMENT_1; } else { state = OF_XMLPARSER_IN_TAG_NAME; i--; } break; @@ -433,10 +436,48 @@ last = i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } else if (buf[i] != ' ') @throw [OFMalformedXMLException newWithClass: isa]; + break; + + /* Comment */ + case OF_XMLPARSER_IN_COMMENT_1: + case OF_XMLPARSER_IN_COMMENT_2: + if (buf[i] != '-') + @throw [OFMalformedXMLException + newWithClass: isa]; + last = i + 1; + state++; + break; + case OF_XMLPARSER_IN_COMMENT_3: + if (buf[i] == '-') + state = OF_XMLPARSER_IN_COMMENT_4; + break; + case OF_XMLPARSER_IN_COMMENT_4: + if (buf[i] == '-') { + OFString *str; + + [cache appendCString: buf + last + withLength: i - last]; + + pool = [[OFAutoreleasePool alloc] init]; + str = [OFMutableString + stringWithCString: [cache cString] + length: [cache length] - 1]; + [str removeLeadingAndTrailingWhitespaces]; + [delegate xmlParser: self + foundComment: str]; + [pool release]; + + [cache setToCString: ""]; + + last = i + 1; + state = OF_XMLPARSER_EXPECT_CLOSE; + } else + state = OF_XMLPARSER_IN_COMMENT_3; + break; } } len = size - last; @@ -558,12 +599,17 @@ - (void)xmlParser: (OFXMLParser*)parser foundString: (OFString*)string { } + +- (void)xmlParser: (OFXMLParser*)parser + foundComment: (OFString*)comment +{ +} - (OFString*)xmlParser: (OFXMLParser*)parser foundUnknownEntityNamed: (OFString*)entity { return nil; } @end