Changeset 106 for trunk/NewView/StringUtilsUnit.pas
- Timestamp:
- Apr 11, 2007, 8:41:25 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/NewView/StringUtilsUnit.pas
r105 r106 17 17 StrLF = chr(10); 18 18 StrCRLF = StrCR + StrLF; 19 Quote = '''';20 DoubleQuote = '"';19 StrSingleQuote = ''''; 20 StrDoubleQuote = '"'; 21 21 22 22 … … 107 107 Function StrInDoubleQuotes(const aString : String) : String; 108 108 109 // Extract all fields in a String delimited by whitespace (blank or tab). 110 // use double quotes if you need blanks in the strings 111 Procedure StrExtractStringsQuoted(Var aResult: TStrings; const aReceiver: String ); 109 112 110 113 Implementation … … 557 560 end; 558 561 562 559 563 Function StrInDoubleQuotes(const aString : String) : String; 560 564 begin 561 Result := DoubleQuote + aString + DoubleQuote; 562 end; 563 564 565 Result := StrDoubleQuote + aString + StrDoubleQuote; 566 end; 567 568 569 Procedure StrExtractStringsQuoted(Var aResult: TStrings; const aReceiver: String ); 570 Var 571 tmpState : (WHITESPACE, INSIDE, START_QUOTE, INSIDE_QUOTED, INSIDE_QUOTED_START_QUOTE); 572 tmpCurrentParsePosition : Integer; 573 tmpCurrentChar : Char; 574 tmpPart : String; 575 576 Begin 577 if (length(aReceiver) < 1) then exit; 578 579 tmpState := WHITESPACE; 580 tmpPart := ''; 581 582 tmpCurrentParsePosition := 1; 583 584 for tmpCurrentParsePosition:=1 to length(aReceiver) do 585 begin 586 tmpCurrentChar := aReceiver[tmpCurrentParsePosition]; 587 588 Case tmpCurrentChar of 589 ' ', StrTAB : 590 begin 591 592 Case tmpState of 593 594 WHITESPACE : 595 begin 596 // nothing 597 end; 598 599 INSIDE : 600 begin 601 aResult.add(tmpPart); 602 tmpPart := ''; 603 tmpState := WHITESPACE; 604 end; 605 606 INSIDE_QUOTED : 607 begin 608 tmpPart := tmpPart + tmpCurrentChar; 609 end; 610 611 START_QUOTE : 612 begin 613 tmpPart := tmpPart + tmpCurrentChar; 614 tmpState := INSIDE_QUOTED; 615 end; 616 617 INSIDE_QUOTED_START_QUOTE : 618 begin 619 aResult.add(tmpPart); 620 tmpPart := ''; 621 tmpState := WHITESPACE; 622 end; 623 end; 624 end; 625 626 StrDoubleQuote : 627 begin 628 629 Case tmpState of 630 631 WHITESPACE : 632 begin 633 tmpState := START_QUOTE; 634 end; 635 636 INSIDE : 637 begin 638 aResult.add(tmpPart); 639 tmpPart := ''; 640 tmpState := START_QUOTE; 641 end; 642 643 INSIDE_QUOTED : 644 begin 645 tmpState := INSIDE_QUOTED_START_QUOTE; 646 end; 647 648 START_QUOTE : 649 begin 650 tmpState := INSIDE_QUOTED_START_QUOTE; 651 end; 652 653 INSIDE_QUOTED_START_QUOTE : 654 begin 655 tmpPart := tmpPart + tmpCurrentChar; 656 tmpState := INSIDE_QUOTED; 657 end; 658 end; 659 end; 660 661 else 662 begin 663 Case tmpState of 664 665 WHITESPACE : 666 begin 667 tmpPart := tmpPart + tmpCurrentChar; 668 tmpState := INSIDE; 669 end; 670 671 INSIDE, INSIDE_QUOTED : 672 begin 673 tmpPart := tmpPart + tmpCurrentChar; 674 end; 675 676 START_QUOTE : 677 begin 678 tmpPart := tmpPart + tmpCurrentChar; 679 tmpState := INSIDE_QUOTED; 680 end; 681 682 INSIDE_QUOTED_START_QUOTE : 683 begin 684 aResult.add(tmpPart); 685 tmpPart := tmpCurrentChar; 686 tmpState := INSIDE; 687 end; 688 end; 689 end; 690 691 end; 692 end; 693 694 Case tmpState of 695 WHITESPACE, START_QUOTE : {nothing to do}; 696 697 INSIDE, INSIDE_QUOTED, INSIDE_QUOTED_START_QUOTE : 698 begin 699 aResult.add(tmpPart); 700 end; 701 end; 702 end; 565 703 END.
Note:
See TracChangeset
for help on using the changeset viewer.