diff -r c640c9325439 -r 54a532a1558d CharacterArray.st --- a/CharacterArray.st Mon Mar 03 10:43:11 2008 +0100 +++ b/CharacterArray.st Mon Mar 03 10:51:20 2008 +0100 @@ -1431,7 +1431,6 @@ ^ true ! ! - !CharacterArray methodsFor:'character searching'! includesMatchCharacters @@ -3728,6 +3727,62 @@ " ! +continuesWith:aString startingAt:startIndex + "return true, if the receiver beginning at startIndex + contains the characters in aString." + + |sz "{Class: SmallInteger }" + idx "{Class: SmallInteger }"| + + sz := aString size. + idx := startIndex. + + 1 to:sz do:[:i | + (self at:idx) ~~ (aString at:i) ifTrue:[^ false]. + idx := idx + 1 + ]. + ^ true + + " + 'hello world' continuesWith:'world' startingAt:6 + 'hello world' continuesWith:'world' startingAt:7 + " + + "Created: 12.5.1996 / 15:46:40 / cg" + "Modified: 26.7.1996 / 19:08:36 / cg" +! + +countWords + "return the number of words, which are separated by separators" + + |tally "{ Class: SmallInteger }" + start "{ Class: SmallInteger }" + mySize "{ Class: SmallInteger }" + stop ch| + + tally := 0. + start := 1. + mySize := self size. + [start <= mySize] whileTrue:[ + ch := self at:start. + ch isSeparator ifTrue:[ + start := start + 1 + ] ifFalse:[ + stop := self indexOfSeparatorStartingAt:start. + (stop == 0) ifTrue:[ + stop := mySize + 1 + ]. + tally := tally + 1. + start := stop + ] + ]. + ^ tally + + " + 'hello world isnt this nice' countWords' + " +! + encoding "return the strings encoding, as a symbol. Here, by default, we assume unicode-encoding. @@ -4822,62 +4877,6 @@ !CharacterArray methodsFor:'testing'! -continuesWith:aString startingAt:startIndex - "return true, if the receiver beginning at startIndex - contains the characters in aString." - - |sz "{Class: SmallInteger }" - idx "{Class: SmallInteger }"| - - sz := aString size. - idx := startIndex. - - 1 to:sz do:[:i | - (self at:idx) ~~ (aString at:i) ifTrue:[^ false]. - idx := idx + 1 - ]. - ^ true - - " - 'hello world' continuesWith:'world' startingAt:6 - 'hello world' continuesWith:'world' startingAt:7 - " - - "Created: 12.5.1996 / 15:46:40 / cg" - "Modified: 26.7.1996 / 19:08:36 / cg" -! - -countWords - "return the number of words, which are separated by separators" - - |tally "{ Class: SmallInteger }" - start "{ Class: SmallInteger }" - mySize "{ Class: SmallInteger }" - stop ch| - - tally := 0. - start := 1. - mySize := self size. - [start <= mySize] whileTrue:[ - ch := self at:start. - ch isSeparator ifTrue:[ - start := start + 1 - ] ifFalse:[ - stop := self indexOfSeparatorStartingAt:start. - (stop == 0) ifTrue:[ - stop := mySize + 1 - ]. - tally := tally + 1. - start := stop - ] - ]. - ^ tally - - " - 'hello world isnt this nice' countWords' - " -! - endsWith:aStringOrCharacter "return true, if the receiver ends with something, aStringOrCharacter." @@ -4922,7 +4921,8 @@ ! isBinarySelector - "treating the receiver as a message selector, return true if its a binary selector" + "treating the receiver as a message selector, return true if its a binary selector. + Notice, that st/x does not have a size <= 2 limit for unaries" |binopChars| @@ -4961,6 +4961,44 @@ " ! +isKeywordSelector + "return true, iff there are only alphanumeric or underline characters separated by colons. + Must end with a colon." + + |state| + + state := #initial. + self do:[:char | + (state == #initial or:[ state == #gotColon]) ifTrue:[ + (char isLetter or:[ char == $_ ]) ifFalse:[^ false]. + state := #gotCharacter. + ] ifFalse:[ + char == $: ifTrue:[ + state := #gotColon. + ] ifFalse:[ + (char isLetterOrDigit or:[char == $_]) ifFalse:[^ false]. + ]. + ]. + ]. + ^ state == #gotColon. + + " + self assert:(':' isKeywordSelector not). + self assert:(':a' isKeywordSelector not). + self assert:('1:' isKeywordSelector not). + self assert:('a:' isKeywordSelector). + self assert:('_:' isKeywordSelector). + self assert:('_a:' isKeywordSelector). + self assert:('_1:' isKeywordSelector). + self assert:('_1::' isKeywordSelector not). + self assert:('_:_:' isKeywordSelector). + self assert:('a:b:' isKeywordSelector). + self assert:('aa:bb:' isKeywordSelector). + self assert:('aa:bb:a' isKeywordSelector not). + self assert:('1:2:' isKeywordSelector not). + " +! + isNameSpaceSelector "Answer true if the receiver contains chars which form a nameSpace selector name. These are of the form ':::', where ns is the NameSpace and sel is the regular selector. @@ -5336,7 +5374,7 @@ !CharacterArray class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.367 2008-02-29 10:12:29 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.368 2008-03-03 09:51:20 cg Exp $' ! ! CharacterArray initialize!