Differences From Artifact [497caa1df6]:
- File
src/OFXMLParser.m
— part of check-in
[2a27cf3000]
at
2016-01-03 00:41:26
on branch trunk
— Update copyright
While at it, also update the mail address. (user: js, size: 24409) [annotate] [blame] [check-ins using]
To Artifact [0b91cb99ed]:
- File src/OFXMLParser.m — part of check-in [e0b9167693] at 2016-02-21 15:37:42 on branch trunk — Make use of C99-style for loops (user: js, size: 24398) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
60 61 62 63 64 65 66 | } } static OFString* transformString(OFXMLParser *parser, OFDataArray *buffer, size_t cut, bool unescape) { | | | < < < | | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | } } static OFString* transformString(OFXMLParser *parser, OFDataArray *buffer, size_t cut, bool unescape) { char *items = [buffer items]; size_t length = [buffer count] - cut; bool hasEntities = false; OFString *ret; for (size_t i = 0; i < length; i++) { if (items[i] == '\r') { if (i + 1 < length && items[i + 1] == '\n') { [buffer removeItemAtIndex: i]; items = [buffer items]; i--; length--; |
︙ | ︙ | |||
102 103 104 105 106 107 108 | } static OFString* namespaceForPrefix(OFString *prefix, OFArray *namespaces) { OFDictionary *const *objects = [namespaces objects]; size_t count = [namespaces count]; | < | | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | } static OFString* namespaceForPrefix(OFString *prefix, OFArray *namespaces) { OFDictionary *const *objects = [namespaces objects]; size_t count = [namespaces count]; if (prefix == nil) prefix = @""; if (count - 1 > SSIZE_MAX) @throw [OFOutOfRangeException exception]; for (ssize_t i = count - 1; i >= 0; i--) { OFString *tmp; if ((tmp = [objects[i] objectForKey: prefix]) != nil) return tmp; } return nil; |
︙ | ︙ | |||
146 147 148 149 150 151 152 | } @implementation OFXMLParser @synthesize delegate = _delegate, depthLimit = _depthLimit; + (void)initialize { | < < | 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | } @implementation OFXMLParser @synthesize delegate = _delegate, depthLimit = _depthLimit; + (void)initialize { const SEL selectors_[OF_XMLPARSER_NUM_STATES] = { @selector(OF_inByteOrderMarkState), @selector(OF_outsideTagState), @selector(OF_tagOpenedState), @selector(OF_inProcessingInstructionsState), @selector(OF_inTagNameState), @selector(OF_inCloseTagNameState), |
︙ | ︙ | |||
172 173 174 175 176 177 178 | @selector(OF_inCommentOpeningState), @selector(OF_inCommentState1), @selector(OF_inCommentState2), @selector(OF_inDOCTYPEState) }; memcpy(selectors, selectors_, sizeof(selectors_)); | | | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | @selector(OF_inCommentOpeningState), @selector(OF_inCommentState1), @selector(OF_inCommentState2), @selector(OF_inDOCTYPEState) }; memcpy(selectors, selectors_, sizeof(selectors_)); for (size_t i = 0; i < OF_XMLPARSER_NUM_STATES; i++) { if (![self instancesRespondToSelector: selectors[i]]) @throw [OFInitializationFailedException exceptionWithClass: self]; lookupTable[i] = (state_function_t) [self instanceMethodForSelector: selectors[i]]; } |
︙ | ︙ | |||
395 396 397 398 399 400 401 | } } /* <?xml […]?> */ - (bool)OF_parseXMLProcessingInstructions: (OFString*)pi { const char *cString; | | > | | 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | } } /* <?xml […]?> */ - (bool)OF_parseXMLProcessingInstructions: (OFString*)pi { const char *cString; size_t length, last; int PIState = 0; OFString *attribute = nil; OFMutableString *value = nil; char piDelimiter = 0; bool hasVersion = false; if (!_acceptProlog) return false; _acceptProlog = false; pi = [pi substringWithRange: of_range(3, [pi length] - 3)]; pi = [pi stringByDeletingEnclosingWhitespaces]; cString = [pi UTF8String]; length = [pi UTF8StringLength]; last = 0; for (size_t i = 0; i < length; i++) { switch (PIState) { case 0: if (cString[i] == ' ' || cString[i] == '\t' || cString[i] == '\r' || cString[i] == '\n') continue; last = i; |
︙ | ︙ | |||
688 689 690 691 692 693 694 | /* Inside a tag, name found */ - (void)OF_inTagState { void *pool; OFString *namespace; OFXMLAttribute *const *attributesObjects; | | | 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | /* Inside a tag, name found */ - (void)OF_inTagState { void *pool; OFString *namespace; OFXMLAttribute *const *attributesObjects; size_t attributesCount; if (_data[_i] != '>' && _data[_i] != '/') { if (_data[_i] != ' ' && _data[_i] != '\t' && _data[_i] != '\n' && _data[_i] != '\r') { _last = _i; _state = OF_XMLPARSER_IN_ATTRIBUTE_NAME; _i--; |
︙ | ︙ | |||
710 711 712 713 714 715 716 | namespace = namespaceForPrefix(_prefix, _namespaces); if (_prefix != nil && namespace == nil) @throw [OFUnboundPrefixException exceptionWithPrefix: _prefix parser: self]; | | | 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | namespace = namespaceForPrefix(_prefix, _namespaces); if (_prefix != nil && namespace == nil) @throw [OFUnboundPrefixException exceptionWithPrefix: _prefix parser: self]; for (size_t j = 0; j < attributesCount; j++) resolveAttributeNamespace(attributesObjects[j], _namespaces, self); pool = objc_autoreleasePoolPush(); if ([_delegate respondsToSelector: @selector(parser:didStartElement:prefix:namespace:attributes:)]) |
︙ | ︙ |