Overview
Comment: | Reduce the number of states and correctly handle \t in OFXMLParser. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
e23674756b35396bcc1d98aa44fb0d36 |
User & Date: | js on 2010-11-15 08:21:13 |
Other Links: | manifest | tags |
Context
2010-11-15
| ||
23:20 | Fix forgotten call to -[description] in -[componentsJoinedByString]. check-in: 1a68929cbb user: js tags: trunk | |
08:21 | Reduce the number of states and correctly handle \t in OFXMLParser. check-in: e23674756b user: js tags: trunk | |
2010-11-14
| ||
23:49 | Handle <!DOCTYPE> in OFXMLParser. check-in: 2d28a0fda4 user: js tags: trunk | |
Changes
Modified src/OFXMLParser.h from [76fd487c9d] to [13cc038ae9].
︙ | ︙ | |||
122 123 124 125 126 127 128 | OF_XMLPARSER_IN_TAG, OF_XMLPARSER_IN_ATTR_NAME, OF_XMLPARSER_EXPECT_DELIM, OF_XMLPARSER_IN_ATTR_VALUE, OF_XMLPARSER_EXPECT_CLOSE, OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE, OF_XMLPARSER_IN_EXCLAMATIONMARK, | | < < < < < < < | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | OF_XMLPARSER_IN_TAG, OF_XMLPARSER_IN_ATTR_NAME, OF_XMLPARSER_EXPECT_DELIM, OF_XMLPARSER_IN_ATTR_VALUE, OF_XMLPARSER_EXPECT_CLOSE, OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE, OF_XMLPARSER_IN_EXCLAMATIONMARK, OF_XMLPARSER_IN_CDATA_OPENING, OF_XMLPARSER_IN_CDATA_1, OF_XMLPARSER_IN_CDATA_2, OF_XMLPARSER_IN_COMMENT_OPENING, OF_XMLPARSER_IN_COMMENT_1, OF_XMLPARSER_IN_COMMENT_2, OF_XMLPARSER_IN_DOCTYPE, OF_XMLPARSER_NUM_STATES } state; OFMutableString *cache; OFString *name; OFString *prefix; OFMutableArray *namespaces; |
︙ | ︙ |
Modified src/OFXMLParser.m from [bafad23096] to [e26bece34a].
︙ | ︙ | |||
91 92 93 94 95 96 97 | @selector(_parseInTagWithBuffer:i:last:), @selector(_parseInAttributeNameWithBuffer:i:last:), @selector(_parseExpectDelimiterWithBuffer:i:last:), @selector(_parseInAttributeValueWithBuffer:i:last:), @selector(_parseExpectCloseWithBuffer:i:last:), @selector(_parseExpectSpaceOrCloseWithBuffer:i:last:), @selector(_parseInExclamationMarkWithBuffer:i:last:), | | < < < < < < < | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | @selector(_parseInTagWithBuffer:i:last:), @selector(_parseInAttributeNameWithBuffer:i:last:), @selector(_parseExpectDelimiterWithBuffer:i:last:), @selector(_parseInAttributeValueWithBuffer:i:last:), @selector(_parseExpectCloseWithBuffer:i:last:), @selector(_parseExpectSpaceOrCloseWithBuffer:i:last:), @selector(_parseInExclamationMarkWithBuffer:i:last:), @selector(_parseInCDATAOpeningWithBuffer:i:last:), @selector(_parseInCDATA1WithBuffer:i:last:), @selector(_parseInCDATA2WithBuffer:i:last:), @selector(_parseInCommentOpeningWithBuffer:i:last:), @selector(_parseInComment1WithBuffer:i:last:), @selector(_parseInComment2WithBuffer:i:last:), @selector(_parseInDoctypeWithBuffer:i:last:), }; memcpy(selectors, sels, sizeof(sels)); for (i = 0; i < OF_XMLPARSER_NUM_STATES; i++) { if (![self instancesRespondToSelector: selectors[i]]) @throw [OFInitializationFailedException |
︙ | ︙ | |||
361 362 363 364 365 366 367 | - (void)_parseInTagNameWithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { const char *cache_c, *tmp; size_t len, cache_len; | | | < | 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | - (void)_parseInTagNameWithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { const char *cache_c, *tmp; size_t len, cache_len; if (buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' && buf[*i] != '\r' && buf[*i] != '>' && buf[*i] != '/') return; if ((len = *i - *last) > 0) [cache appendCStringWithoutUTF8Checking: buf + *last length: len]; cache_c = [cache cString]; cache_len = [cache cStringLength]; |
︙ | ︙ | |||
455 456 457 458 459 460 461 | last: (size_t*)last { OFAutoreleasePool *pool; const char *cache_c, *tmp; size_t len, cache_len; OFString *ns; | | | | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | last: (size_t*)last { OFAutoreleasePool *pool; const char *cache_c, *tmp; size_t len, cache_len; OFString *ns; if (buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' && buf[*i] != '\r' && buf[*i] != '>') return; if ((len = *i - *last) > 0) [cache appendCStringWithoutUTF8Checking: buf + *last length: len]; cache_c = [cache cString]; cache_len = [cache cStringLength]; |
︙ | ︙ | |||
523 524 525 526 527 528 529 | last: (size_t*)last { OFAutoreleasePool *pool; OFString *ns; OFXMLAttribute **attrs_c; size_t j, attrs_cnt; | < | > | 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | last: (size_t*)last { OFAutoreleasePool *pool; OFString *ns; OFXMLAttribute **attrs_c; size_t j, attrs_cnt; if (buf[*i] != '>' && buf[*i] != '/') { if (buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' && buf[*i] != '\r') { *last = *i; state = OF_XMLPARSER_IN_ATTR_NAME; (*i)--; } return; } |
︙ | ︙ | |||
575 576 577 578 579 580 581 | namespace: ns]; [namespaces removeNObjects: 1]; } else if (prefix != nil) { OFString *str = [OFString stringWithFormat: @"%s:%s", [prefix cString], [name cString]]; | < | 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | namespace: ns]; [namespaces removeNObjects: 1]; } else if (prefix != nil) { OFString *str = [OFString stringWithFormat: @"%s:%s", [prefix cString], [name cString]]; [previous addObject: str]; } else [previous addObject: name]; [pool release]; [name release]; |
︙ | ︙ | |||
655 656 657 658 659 660 661 | OFAutoreleasePool *pool; OFString *attr_val; size_t len; if (buf[*i] != delim) return; | < | 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | OFAutoreleasePool *pool; OFString *attr_val; size_t len; if (buf[*i] != delim) return; if ((len = *i - *last) > 0) [cache appendCStringWithoutUTF8Checking: buf + *last length: len]; pool = [[OFAutoreleasePool alloc] init]; attr_val = transform_string(cache, self); |
︙ | ︙ | |||
708 709 710 711 712 713 714 | - (void)_parseExpectSpaceOrCloseWithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { if (buf[*i] == '>') { *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; | | > | | > | | | | | < < < < | < < < < < | < < | < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > > > > < < < < < < < < < < < | > < | 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | - (void)_parseExpectSpaceOrCloseWithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { if (buf[*i] == '>') { *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } else if (buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' && buf[*i] != '\r') @throw [OFMalformedXMLException newWithClass: isa]; } /* In <! */ - (void)_parseInExclamationMarkWithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { if (buf[*i] == '-') state = OF_XMLPARSER_IN_COMMENT_OPENING; else if (buf[*i] == '[') { state = OF_XMLPARSER_IN_CDATA_OPENING; level = 0; } else if (buf[*i] == 'D') { state = OF_XMLPARSER_IN_DOCTYPE; level = 0; } else @throw [OFMalformedXMLException newWithClass: isa]; *last = *i + 1; } /* CDATA */ - (void)_parseInCDATAOpeningWithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { if (buf[*i] != "CDATA["[level]) @throw [OFMalformedXMLException newWithClass: isa]; if (++level == 6) { state = OF_XMLPARSER_IN_CDATA_1; level = 0; } *last = *i + 1; } - (void)_parseInCDATA1WithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { if (buf[*i] == ']') level++; else level = 0; if (level == 2) state = OF_XMLPARSER_IN_CDATA_2; } - (void)_parseInCDATA2WithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { OFAutoreleasePool *pool; OFMutableString *cdata; size_t len; if (buf[*i] != '>') { state = OF_XMLPARSER_IN_CDATA_1; level = (buf[*i] == ']' ? 1 : 0); return; } pool = [[OFAutoreleasePool alloc] init]; [cache appendCStringWithoutUTF8Checking: buf + *last length: *i - *last]; cdata = [[cache mutableCopy] autorelease]; len = [cdata length]; |
︙ | ︙ | |||
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 | last: (size_t*)last { if (buf[*i] != '-') @throw [OFMalformedXMLException newWithClass: isa]; *last = *i + 1; state = OF_XMLPARSER_IN_COMMENT_1; } - (void)_parseInComment1WithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { if (buf[*i] == '-') state = OF_XMLPARSER_IN_COMMENT_2; } - (void)_parseInComment2WithBuffer: (const char*)buf i: (size_t*)i | > > > > > > < < < < < < < < < < | 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 | last: (size_t*)last { if (buf[*i] != '-') @throw [OFMalformedXMLException newWithClass: isa]; *last = *i + 1; state = OF_XMLPARSER_IN_COMMENT_1; level = 0; } - (void)_parseInComment1WithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { if (buf[*i] == '-') level++; else level = 0; if (level == 2) state = OF_XMLPARSER_IN_COMMENT_2; } - (void)_parseInComment2WithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { OFAutoreleasePool *pool; OFMutableString *comment; size_t len; if (buf[*i] != '>') @throw [OFMalformedXMLException newWithClass: isa]; pool = [[OFAutoreleasePool alloc] init]; [cache appendCStringWithoutUTF8Checking: buf + *last length: *i - *last]; comment = [[cache mutableCopy] autorelease]; len = [comment length]; |
︙ | ︙ |
Modified tests/OFXMLParserTests.m from [da9c2e0fdf] to [95a1fadf31].
︙ | ︙ | |||
52 53 54 55 56 57 58 | TEST(msg, et == TAG_START && [name isEqual: @"root"] && prefix == nil && ns == nil && [attrs count] == 0) break; case 2: TEST(msg, et == STRING && [string isEqual: @"\n "]) break; case 3: | | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | TEST(msg, et == TAG_START && [name isEqual: @"root"] && prefix == nil && ns == nil && [attrs count] == 0) break; case 2: TEST(msg, et == STRING && [string isEqual: @"\n "]) break; case 3: TEST(msg, et == CDATA && [string isEqual: @"f<]]]oo"]) break; case 4: TEST(msg, et == TAG_START && [name isEqual: @"bar"] && prefix == nil && ns == nil && attrs == nil) break; case 5: TEST(msg, et == TAG_END && [name isEqual: @"bar"] && |
︙ | ︙ | |||
299 300 301 302 303 304 305 | } - (void)XMLParserTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLParser *parser; const char *str = "<?xml version='1.0'?><!DOCTYPE <<><<>>>><root>\n" | | | 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | } - (void)XMLParserTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLParser *parser; const char *str = "<?xml version='1.0'?><!DOCTYPE <<><<>>>><root>\n" " <![CDATA[f<]]]oo]]><bar/>\n" " <foobar xmlns='urn:objfw:test:foobar'>\n" " <qux xmlns:foo='urn:objfw:test:foo'>\n" " <foo:bla foo:bla='bla' blafoo='foo'>\n" " <blup foo:qux='asd' quxqux='test'/>\n" " <bla:bla\r\rxmlns:bla=\"urn:objfw:test:bla\" qux='qux'\r\n" " bla:foo='blafoo'/>\n" " <abc xmlns='urn:objfw:test:abc' abc='abc' foo:abc='abc'/>\n" |
︙ | ︙ |