CharacterArray.st
changeset 7797 49e53638191f
parent 7780 ffaeccf9e075
child 7876 56ab739f1843
equal deleted inserted replaced
7796:29285c99ec71 7797:49e53638191f
  3528 asCollectionOfWords
  3528 asCollectionOfWords
  3529     "return a collection containing the words (separated by whitespace) 
  3529     "return a collection containing the words (separated by whitespace) 
  3530      of the receiver. Multiple occurences of whitespace characters will
  3530      of the receiver. Multiple occurences of whitespace characters will
  3531      be treated like one - i.e. whitespace is skipped."
  3531      be treated like one - i.e. whitespace is skipped."
  3532 
  3532 
  3533     |words
  3533     |words|
  3534      start  "{ Class:SmallInteger }" 
       
  3535      stop   "{ Class:SmallInteger }" 
       
  3536      mySize "{ Class:SmallInteger }"|
       
  3537 
  3534 
  3538     words := OrderedCollection new.
  3535     words := OrderedCollection new.
  3539     start := 1.
  3536     self asCollectionOfWordsDo:[:w | words add:w].
  3540     mySize := self size.
       
  3541     [start <= mySize] whileTrue:[
       
  3542 	start := self indexOfNonSeparatorStartingAt:start.
       
  3543 	start == 0 ifTrue:[
       
  3544 	    ^ words
       
  3545 	].
       
  3546 	stop := self indexOfSeparatorStartingAt:start.
       
  3547 	stop == 0 ifTrue:[
       
  3548 	    words add:(self copyFrom:start to:mySize).
       
  3549 	    ^ words
       
  3550 	].
       
  3551 	words add:(self copyFrom:start to:(stop - 1)).
       
  3552 	start := stop
       
  3553     ].
       
  3554     ^ words
  3537     ^ words
  3555 
  3538 
  3556     "
  3539     "
  3557      'hello world isnt this nice' asCollectionOfWords
  3540      'hello world isnt this nice' asCollectionOfWords
  3558      '    hello    world   isnt   this   nice  ' asCollectionOfWords
  3541      '    hello    world   isnt   this   nice  ' asCollectionOfWords
  3559      'hello' asCollectionOfWords
  3542      'hello' asCollectionOfWords
  3560      '' asCollectionOfWords
  3543      '' asCollectionOfWords
  3561      '      ' asCollectionOfWords
  3544      '      ' asCollectionOfWords
       
  3545     "
       
  3546 !
       
  3547 
       
  3548 asCollectionOfWordsDo:aBlock
       
  3549     "evaluate aBlock for each word (separated by whitespace) of the receiver. 
       
  3550      Multiple occurences of whitespace characters will be treated like one 
       
  3551      - i.e. whitespace is skipped.
       
  3552      Returns the number of words (i.e. the number of invocations of aBlock)."
       
  3553 
       
  3554     |count  "{ Class:SmallInteger }"
       
  3555      start  "{ Class:SmallInteger }" 
       
  3556      stop   "{ Class:SmallInteger }" 
       
  3557      mySize "{ Class:SmallInteger }"|
       
  3558 
       
  3559     count := 0.
       
  3560     start := 1.
       
  3561     mySize := self size.
       
  3562     [start <= mySize] whileTrue:[
       
  3563         start := self indexOfNonSeparatorStartingAt:start.
       
  3564         start == 0 ifTrue:[
       
  3565             ^ count
       
  3566         ].
       
  3567         stop := self indexOfSeparatorStartingAt:start.
       
  3568         stop == 0 ifTrue:[
       
  3569             aBlock value:(self copyFrom:start to:mySize).
       
  3570             ^ count + 1
       
  3571         ].
       
  3572         aBlock value:(self copyFrom:start to:(stop - 1)).
       
  3573         start := stop.
       
  3574         count := count + 1
       
  3575     ].
       
  3576     ^ count
       
  3577 
       
  3578     "
       
  3579      'hello world isnt this nice' asCollectionOfWordsDo:[:w | Transcript showCR:w]
       
  3580      '    hello    world   isnt   this   nice  ' asCollectionOfWordsDo:[:w | Transcript showCR:w]
       
  3581      'hello' asCollectionOfWordsDo:[:w | Transcript showCR:w]
       
  3582      '' asCollectionOfWordsDo:[:w | Transcript showCR:w]
       
  3583      '      ' asCollectionOfWordsDo:[:w | Transcript showCR:w]
  3562     "
  3584     "
  3563 !
  3585 !
  3564 
  3586 
  3565 asComposedText
  3587 asComposedText
  3566     "ST-80 compatibility 
  3588     "ST-80 compatibility 
  6562 ! !
  6584 ! !
  6563 
  6585 
  6564 !CharacterArray class methodsFor:'documentation'!
  6586 !CharacterArray class methodsFor:'documentation'!
  6565 
  6587 
  6566 version
  6588 version
  6567     ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.263 2003-11-25 17:04:23 cg Exp $'
  6589     ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.264 2003-12-05 13:04:48 cg Exp $'
  6568 ! !
  6590 ! !
  6569 
  6591 
  6570 CharacterArray initialize!
  6592 CharacterArray initialize!