Differences From Artifact [04405d22e4]:
- File src/OFXMLParser.m — part of check-in [889f63ab01] at 2010-06-06 23:31:32 on branch trunk — Fix a warning with Apple GCC 4.0.1. (user: js, size: 16299) [annotate] [blame] [check-ins using]
To Artifact [379d043fd1]:
- File
src/OFXMLParser.m
— part of check-in
[9d79d92d9a]
at
2010-06-12 19:47:43
on branch trunk
— Several OFXMLParser improvements. See details.
* found* renamed to didFind*.
* Support for parsing CDATA.
* Handle comments with - correctly.
* Don't strip leading and trailing whitespaces in comments.
* Rename a few states for more clarity.
* More OFXMLParser tests. (user: js, size: 18855) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
184 185 186 187 188 189 190 | if ([cache cStringLength] > 0) { OFString *str; pool = [[OFAutoreleasePool alloc] init]; str = transform_string(cache, self); [delegate xmlParser: self | | < > > < | 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | if ([cache cStringLength] > 0) { OFString *str; pool = [[OFAutoreleasePool alloc] init]; str = transform_string(cache, self); [delegate xmlParser: self didFindString: str]; [pool release]; } [cache setToCString: ""]; last = i + 1; state = OF_XMLPARSER_TAG_OPENED; } break; /* Tag was just opened */ case OF_XMLPARSER_TAG_OPENED: if (buf[i] == '/') { state = OF_XMLPARSER_IN_CLOSE_TAG_NAME; last = i + 1; } else if(buf[i] == '!') { state = OF_XMLPARSER_IN_CDATA_OR_COMMENT; last = i + 1; } else { state = OF_XMLPARSER_IN_TAG_NAME; i--; } break; /* Inside a tag, no name yet */ |
︙ | ︙ | |||
525 526 527 528 529 530 531 532 | last = i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } else if (buf[i] != ' ' && buf[i] != '\n' && buf[i] != '\r') @throw [OFMalformedXMLException newWithClass: isa]; break; | | | > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | > > > > | < | < | | | > | | | 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 | last = i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } else if (buf[i] != ' ' && buf[i] != '\n' && buf[i] != '\r') @throw [OFMalformedXMLException newWithClass: isa]; break; /* CDATA or comment */ case OF_XMLPARSER_IN_CDATA_OR_COMMENT: if (buf[i] == '-') state = OF_XMLPARSER_IN_COMMENT_OPENING; else if (buf[i] == '[') state = OF_XMLPARSER_IN_CDATA_OPENING_1; else @throw [OFMalformedXMLException newWithClass: isa]; last = i + 1; break; /* CDATA */ case OF_XMLPARSER_IN_CDATA_OPENING_1: if (buf[i] == 'C') state = OF_XMLPARSER_IN_CDATA_OPENING_2; else @throw [OFMalformedXMLException newWithClass: isa]; last = i + 1; break; case OF_XMLPARSER_IN_CDATA_OPENING_2: if (buf[i] == 'D') state = OF_XMLPARSER_IN_CDATA_OPENING_3; else @throw [OFMalformedXMLException newWithClass: isa]; last = i + 1; break; case OF_XMLPARSER_IN_CDATA_OPENING_3: if (buf[i] == 'A') state = OF_XMLPARSER_IN_CDATA_OPENING_4; else @throw [OFMalformedXMLException newWithClass: isa]; last = i + 1; break; case OF_XMLPARSER_IN_CDATA_OPENING_4: if (buf[i] == 'T') state = OF_XMLPARSER_IN_CDATA_OPENING_5; else @throw [OFMalformedXMLException newWithClass: isa]; last = i + 1; break; case OF_XMLPARSER_IN_CDATA_OPENING_5: if (buf[i] == 'A') state = OF_XMLPARSER_IN_CDATA_OPENING_6; else @throw [OFMalformedXMLException newWithClass: isa]; last = i + 1; break; case OF_XMLPARSER_IN_CDATA_OPENING_6: if (buf[i] == '[') state = OF_XMLPARSER_IN_CDATA_1; else @throw [OFMalformedXMLException newWithClass: isa]; last = i + 1; break; case OF_XMLPARSER_IN_CDATA_1: if (buf[i] == ']') state = OF_XMLPARSER_IN_CDATA_2; break; case OF_XMLPARSER_IN_CDATA_2: if (buf[i] == ']') state = OF_XMLPARSER_IN_CDATA_3; else state = OF_XMLPARSER_IN_CDATA_1; break; case OF_XMLPARSER_IN_CDATA_3: if (buf[i] == '>') { OFMutableString *cdata; size_t len; pool = [[OFAutoreleasePool alloc] init]; [cache appendCStringWithoutUTF8Checking: buf + last length: i - last]; cdata = [[cache mutableCopy] autorelease]; len = [cdata length]; [cdata removeCharactersFromIndex: len - 2 toIndex: len]; [delegate xmlParser: self didFindString: cdata]; [pool release]; [cache setToCString: ""]; last = i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } else if (buf[i] != ']') state = OF_XMLPARSER_IN_CDATA_1; break; /* Comment */ case OF_XMLPARSER_IN_COMMENT_OPENING: if (buf[i] != '-') @throw [OFMalformedXMLException newWithClass: isa]; last = i + 1; state = OF_XMLPARSER_IN_COMMENT_1; break; case OF_XMLPARSER_IN_COMMENT_1: if (buf[i] == '-') state = OF_XMLPARSER_IN_COMMENT_2; break; case OF_XMLPARSER_IN_COMMENT_2: state = (buf[i] == '-' ? OF_XMLPARSER_IN_COMMENT_3 : OF_XMLPARSER_IN_COMMENT_1); break; case OF_XMLPARSER_IN_COMMENT_3: if (buf[i] == '>') { OFMutableString *comment; size_t len; pool = [[OFAutoreleasePool alloc] init]; [cache appendCStringWithoutUTF8Checking: buf + last length: i - last]; comment = [[cache mutableCopy] autorelease]; len = [comment length]; [comment removeCharactersFromIndex: len - 2 toIndex: len]; [delegate xmlParser: self didFindComment: comment]; [pool release]; [cache setToCString: ""]; last = i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } else @throw [OFMalformedXMLException newWithClass: isa]; break; } } len = size - last; /* In OF_XMLPARSER_IN_TAG, there can be only spaces */ if (len > 0 && state != OF_XMLPARSER_IN_TAG) [cache appendCStringWithoutUTF8Checking: buf + last length: len]; } - (OFString*)didFindUnknownEntityNamed: (OFString*)entity { return [delegate xmlParser: self didFindUnknownEntityNamed: entity]; } @end @implementation OFString (OFXMLUnescaping) - (OFString*)stringByXMLUnescaping { return [self stringByXMLUnescapingWithHandler: nil]; |
︙ | ︙ | |||
657 658 659 660 661 662 663 | OFAutoreleasePool *pool; OFString *n, *tmp; pool = [[OFAutoreleasePool alloc] init]; n = [OFString stringWithCString: entity length: len]; | | | 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | OFAutoreleasePool *pool; OFString *n, *tmp; pool = [[OFAutoreleasePool alloc] init]; n = [OFString stringWithCString: entity length: len]; tmp = [h didFindUnknownEntityNamed: n]; if (tmp == nil) @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendString: tmp]; [pool release]; |
︙ | ︙ | |||
701 702 703 704 705 706 707 | didEndTagWithName: (OFString*)name prefix: (OFString*)prefix namespace: (OFString*)ns { } - (void)xmlParser: (OFXMLParser*)parser | | | | | | 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 | didEndTagWithName: (OFString*)name prefix: (OFString*)prefix namespace: (OFString*)ns { } - (void)xmlParser: (OFXMLParser*)parser didFindString: (OFString*)string { } - (void)xmlParser: (OFXMLParser*)parser didFindComment: (OFString*)comment { } - (OFString*)xmlParser: (OFXMLParser*)parser didFindUnknownEntityNamed: (OFString*)entity { return nil; } @end |