equal
deleted
inserted
replaced
4727 "Modified: 30.6.1997 / 13:40:23 / cg" |
4727 "Modified: 30.6.1997 / 13:40:23 / cg" |
4728 ! |
4728 ! |
4729 |
4729 |
4730 withoutSeparators |
4730 withoutSeparators |
4731 "return a copy of myself without leading and trailing whitespace. |
4731 "return a copy of myself without leading and trailing whitespace. |
|
4732 (but whiteSpace in-between is preserved) |
4732 Whitespace is space, tab, newline, formfeed. |
4733 Whitespace is space, tab, newline, formfeed. |
4733 Use withoutSpaces, if you want to remove spaces only." |
4734 Use withoutSpaces, if you want to remove spaces only." |
4734 |
4735 |
4735 |startIndex "{ Class: SmallInteger }" |
4736 |startIndex "{ Class: SmallInteger }" |
4736 endIndex "{ Class: SmallInteger }" |
4737 endIndex "{ Class: SmallInteger }" |
4739 sz := self size. |
4740 sz := self size. |
4740 startIndex := 1. |
4741 startIndex := 1. |
4741 endIndex := sz. |
4742 endIndex := sz. |
4742 |
4743 |
4743 [(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[ |
4744 [(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[ |
4744 startIndex := startIndex + 1 |
4745 startIndex := startIndex + 1 |
4745 ]. |
4746 ]. |
4746 [(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[ |
4747 [(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[ |
4747 endIndex := endIndex - 1 |
4748 endIndex := endIndex - 1 |
4748 ]. |
4749 ]. |
4749 startIndex > endIndex ifTrue:[ |
4750 startIndex > endIndex ifTrue:[ |
4750 ^ '' |
4751 ^ '' |
4751 ]. |
4752 ]. |
4752 ((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
4753 ((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
4753 ^ self |
4754 ^ self |
4754 ]. |
4755 ]. |
4755 ^ self copyFrom:startIndex to:endIndex |
4756 ^ self copyFrom:startIndex to:endIndex |
4756 |
4757 |
4757 " |
4758 " |
4758 ' foo ' withoutSeparators |
4759 ' foo ' withoutSeparators |
4763 " |
4764 " |
4764 ! |
4765 ! |
4765 |
4766 |
4766 withoutSpaces |
4767 withoutSpaces |
4767 "return a copy of myself without leading and trailing spaces. |
4768 "return a copy of myself without leading and trailing spaces. |
|
4769 (but spaces in-between are preserved) |
4768 Notice: this does NOT remove tabs, newline or any other whitespace. |
4770 Notice: this does NOT remove tabs, newline or any other whitespace. |
4769 Use withoutSeparators for this." |
4771 Use withoutSeparators for this." |
4770 |
4772 |
4771 |startIndex "{ Class: SmallInteger }" |
4773 |startIndex "{ Class: SmallInteger }" |
4772 endIndex "{ Class: SmallInteger }" |
4774 endIndex "{ Class: SmallInteger }" |
4775 sz := self size. |
4777 sz := self size. |
4776 startIndex := 1. |
4778 startIndex := 1. |
4777 endIndex := sz. |
4779 endIndex := sz. |
4778 |
4780 |
4779 [(startIndex < endIndex) and:[(self at:startIndex) == Character space]] whileTrue:[ |
4781 [(startIndex < endIndex) and:[(self at:startIndex) == Character space]] whileTrue:[ |
4780 startIndex := startIndex + 1 |
4782 startIndex := startIndex + 1 |
4781 ]. |
4783 ]. |
4782 [(endIndex > 1) and:[(self at:endIndex) == Character space]] whileTrue:[ |
4784 [(endIndex > 1) and:[(self at:endIndex) == Character space]] whileTrue:[ |
4783 endIndex := endIndex - 1 |
4785 endIndex := endIndex - 1 |
4784 ]. |
4786 ]. |
4785 startIndex > endIndex ifTrue:[ |
4787 startIndex > endIndex ifTrue:[ |
4786 ^ '' |
4788 ^ '' |
4787 ]. |
4789 ]. |
4788 ((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
4790 ((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
4789 ^ self |
4791 ^ self |
4790 ]. |
4792 ]. |
4791 ^ self copyFrom:startIndex to:endIndex |
4793 ^ self copyFrom:startIndex to:endIndex |
4792 |
4794 |
4793 " |
4795 " |
4794 ' foo ' withoutSpaces |
4796 ' foo ' withoutSpaces |
4795 'foo ' withoutSpaces |
4797 'foo ' withoutSpaces |
4796 ' foo' withoutSpaces |
4798 ' foo' withoutSpaces |
4797 ' ' withoutSpaces |
4799 ' ' withoutSpaces |
|
4800 'a b' withoutSpaces |
4798 (' foo' , Character tab asString , ' ') withoutSpaces inspect |
4801 (' foo' , Character tab asString , ' ') withoutSpaces inspect |
4799 " |
4802 " |
4800 ! |
4803 ! |
4801 |
4804 |
4802 withoutTrailingSeparators |
4805 withoutTrailingSeparators |
5289 ! ! |
5292 ! ! |
5290 |
5293 |
5291 !CharacterArray class methodsFor:'documentation'! |
5294 !CharacterArray class methodsFor:'documentation'! |
5292 |
5295 |
5293 version |
5296 version |
5294 ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.158 1999-04-23 10:40:44 cg Exp $' |
5297 ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.159 1999-05-08 14:32:08 cg Exp $' |
5295 ! ! |
5298 ! ! |
5296 CharacterArray initialize! |
5299 CharacterArray initialize! |