5669 ! |
5669 ! |
5670 |
5670 |
5671 searchBlockForString:aString ignoreCase:ignoreCase match:doMatchArg |
5671 searchBlockForString:aString ignoreCase:ignoreCase match:doMatchArg |
5672 "return a block to search for a string." |
5672 "return a block to search for a string." |
5673 |
5673 |
5674 |checkBlock pattern doMatch| |
5674 |checkBlock lineCheckBlock pattern doMatch |
|
5675 quickCheckString firstMatchIndex lastMatchIndex| |
5675 |
5676 |
5676 doMatch := doMatchArg. |
5677 doMatch := doMatchArg. |
5677 aString includesMatchCharacters ifFalse:[ |
5678 aString includesMatchCharacters ifFalse:[ |
5678 doMatch := false. |
5679 doMatch := false. |
5679 ]. |
5680 ]. |
5680 doMatch ifTrue:[ |
5681 doMatch ifTrue:[ |
5681 "a matchString" |
5682 "a matchString" |
5682 pattern := aString. |
5683 pattern := aString. |
|
5684 |
|
5685 firstMatchIndex := aString indexOfAny:'*#['. |
|
5686 lastMatchIndex := aString lastIndexOfAny:'*#['. |
|
5687 "/ which is longer - left or right part |
|
5688 firstMatchIndex-1 "nleft" > (aString size-lastMatchIndex) "nright" ifTrue:[ |
|
5689 "/ use left part as quickSearch |
|
5690 quickCheckString := aString copyTo:firstMatchIndex-1 |
|
5691 ] ifFalse:[ |
|
5692 "/ use right part as quickSearch |
|
5693 quickCheckString := aString copyFrom:lastMatchIndex+1 |
|
5694 ]. |
|
5695 |
5683 aString first == $* ifFalse:[ |
5696 aString first == $* ifFalse:[ |
5684 pattern := '*',pattern |
5697 pattern := '*',pattern |
5685 ]. |
5698 ]. |
5686 aString last == $* ifFalse:[ |
5699 aString last == $* ifFalse:[ |
5687 pattern := pattern,'*' |
5700 pattern := pattern,'*' |
5688 ]. |
5701 ]. |
|
5702 "/ when doing a match, be careful to not match acrosss lines |
5689 ignoreCase ifTrue:[ |
5703 ignoreCase ifTrue:[ |
5690 checkBlock := [:src | pattern match:src caseSensitive:false] |
5704 lineCheckBlock := [:line | pattern match:line caseSensitive:false] |
5691 ] ifFalse:[ |
5705 ] ifFalse:[ |
5692 checkBlock := [:src | pattern match:src caseSensitive:true] |
5706 lineCheckBlock := [:line | pattern match:line caseSensitive:true] |
5693 ] |
5707 ]. |
|
5708 quickCheckString size > 1 ifTrue:[ |
|
5709 ignoreCase ifTrue:[ |
|
5710 checkBlock := [:src | |
|
5711 (src includesString:quickCheckString caseSensitive:false) |
|
5712 and:[ (lineCheckBlock value:src) |
|
5713 and:[ src asStringCollection contains:lineCheckBlock ]]]. |
|
5714 ] ifFalse:[ |
|
5715 checkBlock := [:src | |
|
5716 (src includesString:quickCheckString caseSensitive:true) |
|
5717 and:[ (lineCheckBlock value:src) |
|
5718 and:[ src asStringCollection contains:lineCheckBlock ]]]. |
|
5719 ] |
|
5720 ] ifFalse:[ |
|
5721 checkBlock := [:src | |
|
5722 (lineCheckBlock value:src) |
|
5723 and:[ src asStringCollection contains:lineCheckBlock ]]. |
|
5724 ]. |
5694 ] ifFalse:[ |
5725 ] ifFalse:[ |
5695 ignoreCase ifTrue:[ |
5726 ignoreCase ifTrue:[ |
5696 checkBlock := [:src | src includesString:aString caseSensitive:false] |
5727 checkBlock := [:src | src includesString:aString caseSensitive:false] |
5697 ] ifFalse:[ |
5728 ] ifFalse:[ |
5698 checkBlock := [:src | src includesString:aString caseSensitive:true] |
5729 checkBlock := [:src | src includesString:aString caseSensitive:true] |
5716 ! |
5747 ! |
5717 |
5748 |
5718 searchBlockForStringLiteral:aString ignoreCase:ignoreCase match:doMatchArg |
5749 searchBlockForStringLiteral:aString ignoreCase:ignoreCase match:doMatchArg |
5719 "return a block to search for a string-literal." |
5750 "return a block to search for a string-literal." |
5720 |
5751 |
5721 |pattern doMatch checkLiteral checkSource quickCheckString firstMatchIndex lastMatchIndex| |
5752 |pattern doMatch checkLiteral checkSource |
|
5753 quickCheckString firstMatchIndex lastMatchIndex| |
5722 |
5754 |
5723 aString isEmpty ifTrue:[^ [:cls :mthd :sel | true ]]. |
5755 aString isEmpty ifTrue:[^ [:cls :mthd :sel | true ]]. |
5724 |
5756 |
5725 doMatch := doMatchArg. |
5757 doMatch := doMatchArg. |
5726 (aString includesMatchCharacters) ifFalse:[ |
5758 (aString includesMatchCharacters) ifFalse:[ |
5736 pattern := pattern,'*' |
5768 pattern := pattern,'*' |
5737 ]. |
5769 ]. |
5738 checkLiteral := [:lit | pattern match:lit caseSensitive:ignoreCase not]. |
5770 checkLiteral := [:lit | pattern match:lit caseSensitive:ignoreCase not]. |
5739 firstMatchIndex := aString indexOfAny:'*#['. |
5771 firstMatchIndex := aString indexOfAny:'*#['. |
5740 lastMatchIndex := aString lastIndexOfAny:'*#['. |
5772 lastMatchIndex := aString lastIndexOfAny:'*#['. |
5741 "/ which is longer - left or right part |
5773 "/ which is longer - left or right part? |
5742 firstMatchIndex-1 "nleft" > (aString size-lastMatchIndex) "nright" ifTrue:[ |
5774 firstMatchIndex-1 "nleft" > (aString size-lastMatchIndex) "nright" ifTrue:[ |
5743 "/ use left part as quickSearch |
5775 "/ use left part as quickSearch |
5744 quickCheckString := aString copyTo:firstMatchIndex-1 |
5776 quickCheckString := aString copyTo:firstMatchIndex-1 |
5745 ] ifFalse:[ |
5777 ] ifFalse:[ |
5746 "/ use right part as quickSearch |
5778 "/ use right part as quickSearch |