Differences From Artifact [0dd447c3c4]:
- File
src/OFXMLParser.m
— part of check-in
[627511b032]
at
2020-11-14 12:23:55
on branch trunk
— Rename of_malloc and of_calloc
The new names should be more accurate. (user: js, size: 28057) [annotate] [blame] [check-ins using] [more...]
To Artifact [e395ba83dc]:
- File src/OFXMLParser.m — part of check-in [1b82d3bf4f] at 2021-03-07 20:25:21 on branch trunk — *.m: Fold methods into one line where it fits (user: js, size: 27690) [annotate] [blame] [check-ins using] [more...]
1 | /* | < < | | 1 2 3 4 5 6 7 8 9 | /* * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * |
︙ | ︙ | |||
91 92 93 94 95 96 97 | [OF_XMLPARSER_IN_DOCTYPE] = inDOCTYPEState }; static OF_INLINE void appendToBuffer(OFMutableData *buffer, const char *string, of_string_encoding_t encoding, size_t length) { | | | < | < | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | [OF_XMLPARSER_IN_DOCTYPE] = inDOCTYPEState }; static OF_INLINE void appendToBuffer(OFMutableData *buffer, const char *string, of_string_encoding_t encoding, size_t length) { if OF_LIKELY(encoding == OF_STRING_ENCODING_UTF_8) [buffer addItems: string count: length]; else { void *pool = objc_autoreleasePoolPush(); OFString *tmp = [OFString stringWithCString: string encoding: encoding length: length]; [buffer addItems: tmp.UTF8String count: tmp.UTF8StringLength]; objc_autoreleasePoolPop(pool); } } static OFString * transformString(OFXMLParser *parser, OFMutableData *buffer, size_t cut, bool unescape) |
︙ | ︙ | |||
128 129 130 131 132 133 134 | length--; } else items[i] = '\n'; } else if (items[i] == '&') hasEntities = true; } | | < | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | length--; } else items[i] = '\n'; } else if (items[i] == '&') hasEntities = true; } ret = [OFString stringWithUTF8String: items length: length]; if (unescape && hasEntities) { @try { return [ret stringByXMLUnescapingWithDelegate: parser]; } @catch (OFInvalidFormatException *e) { @throw [OFMalformedXMLException exceptionWithParser: parser]; |
︙ | ︙ | |||
238 239 240 241 242 243 244 | [_attributeName release]; [_attributePrefix release]; [_previous release]; [super dealloc]; } | | < | 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | [_attributeName release]; [_attributePrefix release]; [_previous release]; [super dealloc]; } - (void)parseBuffer: (const char *)buffer length: (size_t)length { _data = buffer; for (_i = _last = 0; _i < length; _i++) { size_t j = _i; lookupTable[_state](self); |
︙ | ︙ | |||
267 268 269 270 271 272 273 | if (length - _last > 0 && _state != OF_XMLPARSER_IN_TAG) appendToBuffer(_buffer, _data + _last, _encoding, length - _last); } - (void)parseString: (OFString *)string { | | < < | < < < < < < < < < < < < < < | 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | if (length - _last > 0 && _state != OF_XMLPARSER_IN_TAG) appendToBuffer(_buffer, _data + _last, _encoding, length - _last); } - (void)parseString: (OFString *)string { [self parseBuffer: string.UTF8String length: string.UTF8StringLength]; } - (void)parseStream: (OFStream *)stream { size_t pageSize = [OFSystemInfo pageSize]; char *buffer = of_alloc(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer length: pageSize]; [self parseBuffer: buffer length: length]; } } @finally { free(buffer); } } static void inByteOrderMarkState(OFXMLParser *self) { if (self->_data[self->_i] != "\xEF\xBB\xBF"[self->_level]) { if (self->_level == 0) { self->_state = OF_XMLPARSER_OUTSIDE_TAG; self->_i--; |
︙ | ︙ | |||
514 515 516 517 518 519 520 | [PI hasPrefix: @"xml\n"]) if (!parseXMLProcessingInstructions(self, PI)) @throw [OFMalformedXMLException exceptionWithParser: self]; if ([self->_delegate respondsToSelector: @selector(parser:foundProcessingInstructions:)]) | | | 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | [PI hasPrefix: @"xml\n"]) if (!parseXMLProcessingInstructions(self, PI)) @throw [OFMalformedXMLException exceptionWithParser: self]; if ([self->_delegate respondsToSelector: @selector(parser:foundProcessingInstructions:)]) [self->_delegate parser: self foundProcessingInstructions: PI]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; |
︙ | ︙ | |||
968 969 970 971 972 973 974 | appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); CDATA = transformString(self, self->_buffer, 2, false); if ([self->_delegate respondsToSelector: @selector(parser:foundCDATA:)]) | | < | 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 | appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); CDATA = transformString(self, self->_buffer, 2, false); if ([self->_delegate respondsToSelector: @selector(parser:foundCDATA:)]) [self->_delegate parser: self foundCDATA: CDATA]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = OF_XMLPARSER_OUTSIDE_TAG; |
︙ | ︙ | |||
1022 1023 1024 1025 1026 1027 1028 | appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); comment = transformString(self, self->_buffer, 2, false); if ([self->_delegate respondsToSelector: @selector(parser:foundComment:)]) | | < | 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 | appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); comment = transformString(self, self->_buffer, 2, false); if ([self->_delegate respondsToSelector: @selector(parser:foundComment:)]) [self->_delegate parser: self foundComment: comment]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = OF_XMLPARSER_OUTSIDE_TAG; |
︙ | ︙ | |||
1067 1068 1069 1070 1071 1072 1073 | } - (OFString *)string: (OFString *)string containsUnknownEntityNamed: (OFString *)entity { if ([_delegate respondsToSelector: @selector(parser:foundUnknownEntityNamed:)]) | | < | 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 | } - (OFString *)string: (OFString *)string containsUnknownEntityNamed: (OFString *)entity { if ([_delegate respondsToSelector: @selector(parser:foundUnknownEntityNamed:)]) return [_delegate parser: self foundUnknownEntityNamed: entity]; return nil; } @end |