CharacterArray.st
branchjv
changeset 17834 04ff72c5039a
parent 17815 956b46750806
child 17841 7abcc4aef871
equal deleted inserted replaced
17833:1602a49e146e 17834:04ff72c5039a
  1506     "added for visual works compatibility"
  1506     "added for visual works compatibility"
  1507     ^ true
  1507     ^ true
  1508 ! !
  1508 ! !
  1509 
  1509 
  1510 
  1510 
       
  1511 
  1511 !CharacterArray methodsFor:'character searching'!
  1512 !CharacterArray methodsFor:'character searching'!
  1512 
  1513 
  1513 includesMatchCharacters
  1514 includesMatchCharacters
  1514     "return true if the receiver includes any GLOB meta-match characters (i.e. $* or $#)
  1515     "return true if the receiver includes any GLOB meta-match characters (i.e. $* or $#)
  1515      for match operations; false if not.
  1516      for match operations; false if not.
  2328      'asd''f;d''dd;s' asCollectionOfSubstringsSeparatedBy:$; exceptIn:$'
  2329      'asd''f;d''dd;s' asCollectionOfSubstringsSeparatedBy:$; exceptIn:$'
  2329     "
  2330     "
  2330     "/ 'asd "hello bla" foo "bla bla" bar' asCollectionOfSubstringsSeparatedBy:$  exceptIn:$"
  2331     "/ 'asd "hello bla" foo "bla bla" bar' asCollectionOfSubstringsSeparatedBy:$  exceptIn:$"
  2331 !
  2332 !
  2332 
  2333 
  2333 asCollectionOfSubstringsSeparatedBy: aFieldSeparator textSeparator:aTextSeparatorOrNil
  2334 asCollectionOfSubstringsSeparatedBy:aFieldSeparator textSeparator:aTextSeparatorOrNil
  2334     "return a collection containing the words (separated by aFieldSeparator)
  2335     "return a collection containing the words (separated by aFieldSeparator) of the receiver.
  2335      of the receiver. This allows breaking up csv strings."
  2336      Individual words might be enclosed in aTextSeparator characters, in case they contain blanks or fieldSeparators.
  2336 
  2337      Typically used for CSV line parsing, with a $; as aFieldSeparator and $'' (dquote) as textSeparator."
  2337     ^ self asCollectionOfSubstringsSeparatedByAll: aFieldSeparator
  2338 
  2338 
  2339     |items myClass scanningWord
  2339 "/     '"First", "Second,SecondAdd", "Third"' asCollectionOfSubstringsSeparatedBy:',' textSeparator: '"'
  2340      inStream element|
  2340 "/     'First,Second,Third' asCollectionOfSubstringsSeparatedBy:',' textSeparator: nil
  2341 
       
  2342     aTextSeparatorOrNil isNil ifTrue:[
       
  2343         ^ self asCollectionOfSubstringsSeparatedByAll: aFieldSeparator
       
  2344     ].
       
  2345 
       
  2346     items := OrderedCollection new.
       
  2347     myClass := self species.
       
  2348 
       
  2349     inStream := ReadStream on:self.
       
  2350     [   
       
  2351         inStream skipSeparators.
       
  2352         inStream atEnd
       
  2353     ] whileFalse:[
       
  2354         inStream peek == aTextSeparatorOrNil ifTrue:[
       
  2355             inStream next.
       
  2356             element := ''.
       
  2357             scanningWord := true.
       
  2358             [ inStream atEnd not and:[scanningWord] ] whileTrue:[
       
  2359                 element := element , (inStream upTo:aTextSeparatorOrNil).
       
  2360                 (inStream peek == aTextSeparatorOrNil) ifTrue:[
       
  2361                     element := element , aTextSeparatorOrNil.    
       
  2362                     inStream next.
       
  2363                 ] ifFalse:[
       
  2364                     scanningWord := false.
       
  2365                 ].
       
  2366             ].
       
  2367             inStream upToAllExcluding:aFieldSeparator.
       
  2368         ] ifFalse:[
       
  2369             element := inStream upToAllExcluding:aFieldSeparator
       
  2370         ].
       
  2371         items add:element.
       
  2372     ].
       
  2373 
       
  2374     ^ items
       
  2375 
       
  2376     "
       
  2377      self assert:(('#First#, #Second,SecondAdd#, #Third#' asCollectionOfSubstringsSeparatedBy:',' textSeparator: $#)
       
  2378                   sameContentsAs:#('First' 'Second,SecondAdd' 'Third'))
       
  2379      self assert:(('#Fir##st#, #Second,SecondAdd#, #Third#' asCollectionOfSubstringsSeparatedBy:',' textSeparator: $#)
       
  2380                   sameContentsAs:#('Fir#st' 'Second,SecondAdd' 'Third'))
       
  2381      self assert:(('#Fir##st#, Second,SecondAdd, #Third#' asCollectionOfSubstringsSeparatedBy:',' textSeparator: $#)
       
  2382                   sameContentsAs:#('Fir#st' 'Second' 'SecondAdd' 'Third'))
       
  2383     "
       
  2384     "
       
  2385      'First,Second,Third' asCollectionOfSubstringsSeparatedBy:',' textSeparator: nil
       
  2386     "
       
  2387 
       
  2388     "Modified: / 07-04-2011 / 13:23:19 / cg"
  2341 !
  2389 !
  2342 
  2390 
  2343 asCollectionOfSubstringsSeparatedByAll:aSeparatorString
  2391 asCollectionOfSubstringsSeparatedByAll:aSeparatorString
  2344     "return a collection containing the lines (separated by aSeparatorString)
  2392     "return a collection containing the lines (separated by aSeparatorString)
  2345      of the receiver. If aSeparatorString occurs multiple times in a row,
  2393      of the receiver. If aSeparatorString occurs multiple times in a row,
  4723     "
  4771     "
  4724 
  4772 
  4725     "Created: 12.5.1996 / 20:09:29 / cg"
  4773     "Created: 12.5.1996 / 20:09:29 / cg"
  4726     "Modified: 17.4.1997 / 12:50:23 / cg"
  4774     "Modified: 17.4.1997 / 12:50:23 / cg"
  4727 ! !
  4775 ! !
       
  4776 
  4728 
  4777 
  4729 !CharacterArray methodsFor:'special string converting'!
  4778 !CharacterArray methodsFor:'special string converting'!
  4730 
  4779 
  4731 expandPlaceholdersWith:argArrayOrDictionary
  4780 expandPlaceholdersWith:argArrayOrDictionary
  4732     "return a copy of the receiver, where all %i escapes are
  4781     "return a copy of the receiver, where all %i escapes are
  5899 ! !
  5948 ! !
  5900 
  5949 
  5901 !CharacterArray class methodsFor:'documentation'!
  5950 !CharacterArray class methodsFor:'documentation'!
  5902 
  5951 
  5903 version
  5952 version
  5904     ^ '$Id: CharacterArray.st 10604 2011-02-04 23:09:23Z vranyj1 $'
  5953     ^ '$Id: CharacterArray.st 10632 2011-04-09 17:19:04Z vranyj1 $'
  5905 !
  5954 !
  5906 
  5955 
  5907 version_CVS
  5956 version_CVS
  5908     ^ 'Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.446 2011/01/09 09:38:33 cg Exp '
  5957     ^ 'Header: /var/local/cvs/stx/libbasic/CharacterArray.st,v 1.448 2011-04-07 11:23:33 cg Exp '
  5909 !
  5958 !
  5910 
  5959 
  5911 version_SVN
  5960 version_SVN
  5912     ^ '$Id: CharacterArray.st 10604 2011-02-04 23:09:23Z vranyj1 $'
  5961     ^ '$Id: CharacterArray.st 10632 2011-04-09 17:19:04Z vranyj1 $'
  5913 ! !
  5962 ! !
  5914 
  5963 
  5915 CharacterArray initialize!
  5964 CharacterArray initialize!
  5916 
  5965 
  5917 
  5966 
  5922 
  5971 
  5923 
  5972 
  5924 
  5973 
  5925 
  5974 
  5926 
  5975 
       
  5976