SeqColl.st
changeset 263 e0195b4ad1ac
parent 260 cefb485445a7
child 266 f4a7a506a995
equal deleted inserted replaced
262:39f91e7b1ab1 263:e0195b4ad1ac
    19 
    19 
    20 SequenceableCollection comment:'
    20 SequenceableCollection comment:'
    21 COPYRIGHT (c) 1989 by Claus Gittinger
    21 COPYRIGHT (c) 1989 by Claus Gittinger
    22 	      All Rights Reserved
    22 	      All Rights Reserved
    23 
    23 
    24 $Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.21 1995-02-17 13:04:25 claus Exp $
    24 $Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.22 1995-02-17 16:57:21 claus Exp $
    25 '!
    25 '!
    26 
    26 
    27 !SequenceableCollection class methodsFor:'documentation'!
    27 !SequenceableCollection class methodsFor:'documentation'!
    28 
    28 
    29 copyright
    29 copyright
    40 "
    40 "
    41 !
    41 !
    42 
    42 
    43 version
    43 version
    44 "
    44 "
    45 $Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.21 1995-02-17 13:04:25 claus Exp $
    45 $Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.22 1995-02-17 16:57:21 claus Exp $
    46 "
    46 "
    47 !
    47 !
    48 
    48 
    49 documentation
    49 documentation
    50 "
    50 "
   148 
   148 
   149 !SequenceableCollection methodsFor:'converting'!
   149 !SequenceableCollection methodsFor:'converting'!
   150 
   150 
   151 asStringWithCRs
   151 asStringWithCRs
   152     "return a string generated by concatenating my elements 
   152     "return a string generated by concatenating my elements 
   153      (which must be strings) and embedding cr characters in between.
   153      (which must be strings or nil) and embedding cr characters in between.
   154      Nil entries and empty strings are counted as empty lines."
   154      Nil entries and empty strings are counted as empty lines."
   155 
   155 
   156     ^ self asStringWithCRsFrom:1 to:(self size)
   156     ^ self asStringWithCRsFrom:1 to:(self size)
   157 !
   157 !
   158 
   158 
   159 asStringWithCRsFrom:firstLine to:lastLine
   159 asStringWithCRsFrom:firstLine to:lastLine
   160     "return a string generated by concatenating some of my elements 
   160     "return a string generated by concatenating some of my elements 
   161      (which must be strings) and embedding cr characters in between.
   161      (which must be strings or nil) and embedding cr characters in between.
   162      Nil entries and empty strings are counted as empty lines."
   162      Nil entries and empty strings are counted as empty lines."
   163 
   163 
   164     ^ self asStringWithCRsFrom:firstLine to:lastLine compressTabs:false withCR:true
   164     ^ self asStringWithCRsFrom:firstLine to:lastLine compressTabs:false withCR:true
   165 !
   165 !
   166 
   166 
   167 asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs
   167 asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs
   168     "return part of myself as a string with embedded cr's.
   168     "return part of myself as a string with embedded cr's.
   169      My elements must be strings.
   169      My elements must be strings or nil.
   170      If the argument compressTabs is true, leading spaces are converted
   170      If the argument compressTabs is true, leading spaces are converted
   171      to tab-characters (8col tabs).
   171      to tab-characters (8col tabs).
   172      Nil entries and empty strings are taken as empty lines."
   172      Nil entries and empty strings are taken as empty lines."
   173 
   173 
   174     ^ self asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs withCR:true
   174     ^ self asStringWithCRsFrom:firstLine to:lastLine compressTabs:compressTabs withCR:true
   175 !
   175 !
   176 
   176 
   177 asStringCRsfrom:firstLine to:lastLine compressTabs:compressTabs withCR:withCR
   177 asStringWithCRsfrom:firstLine to:lastLine compressTabs:compressTabs withCR:withCR
   178     "return part of myself as a string with embedded cr's.
   178     "return part of myself as a string with embedded cr's.
   179      My elements must be strings; nil entries and empty strings are
   179      My elements must be strings or nil; nil entries and empty strings are
   180      taken as empty lines.
   180      taken as empty lines.
   181      If the argument compressTabs is true, leading spaces are converted
   181      If the argument compressTabs is true, leading spaces are converted
   182      to tab-characters (8col tabs). WithCR controls whether the last line
   182      to tab-characters (8col tabs). WithCR controls whether the last line
   183      should be followed by a cr or not."
   183      should be followed by a cr or not."
   184 
   184 
   189 		  final:(withCR ifTrue:[Character cr] ifFalse:[nil])
   189 		  final:(withCR ifTrue:[Character cr] ifFalse:[nil])
   190 !
   190 !
   191 
   191 
   192 asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter
   192 asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter
   193     "return part of myself as a string with embedded sepCharacters.
   193     "return part of myself as a string with embedded sepCharacters.
   194      My elements must be strings; nil entries and empty strings are
   194      My elements must be strings or nil; nil entries and empty strings are
   195      taken as empty lines.
   195      taken as empty lines.
   196      If the argument compressTabs is true, leading spaces are converted
   196      If the argument compressTabs is true, leading spaces are converted
   197      to tab-characters (8col tabs). The last line is followed by a final
   197      to tab-characters (8col tabs). The last line is followed by a final
   198      character (if non-nil).
   198      character (if non-nil).
   199 
   199 
   200      This method is tuned for big collections, in not creating many
   200      This method is tuned for big collections, in not creating many
   201      intermediate strings (has linear runtime)."
   201      intermediate strings (has linear runtime). For very small collections
       
   202      and small strings, it may be faster to use the comma , operation."
   202 
   203 
   203     |totalLength "{ Class:SmallInteger }"
   204     |totalLength "{ Class:SmallInteger }"
   204      pos         "{ Class:SmallInteger }"
   205      pos         "{ Class:SmallInteger }"
   205      newString lineString spaces idx nTabs sepCnt|
   206      newString lineString spaces idx nTabs sepCnt|
   206 
   207