SeqColl.st
changeset 3602 dd53d372c250
parent 3482 6ac69c06ca0a
child 3645 e0f4833427a3
equal deleted inserted replaced
3601:c879b9a15f38 3602:dd53d372c250
   912     "return part of myself as a string or text with embedded sepCharacters.
   912     "return part of myself as a string or text with embedded sepCharacters.
   913      My elements must be strings or nil; nil entries and empty strings are
   913      My elements must be strings or nil; nil entries and empty strings are
   914      taken as empty lines.
   914      taken as empty lines.
   915      If the argument compressTabs is true, leading spaces are converted
   915      If the argument compressTabs is true, leading spaces are converted
   916      to tab-characters (8col tabs). The last line is followed by a final
   916      to tab-characters (8col tabs). The last line is followed by a final
       
   917      character (if non-nil)."
       
   918 
       
   919     ^ self
       
   920         asStringWith:sepCharacter 
       
   921         from:firstLine 
       
   922         to:lastLine 
       
   923         compressTabs:compressTabs 
       
   924         final:endCharacter 
       
   925         withEmphasis:true
       
   926 
       
   927     "Modified: / 17.6.1998 / 12:31:19 / cg"
       
   928 !
       
   929 
       
   930 asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter withEmphasis:withEmphasis
       
   931     "return part of myself as a string or text with embedded sepCharacters.
       
   932      My elements must be strings or nil; nil entries and empty strings are
       
   933      taken as empty lines.
       
   934      If the argument compressTabs is true, leading spaces are converted
       
   935      to tab-characters (8col tabs). The last line is followed by a final
   917      character (if non-nil).
   936      character (if non-nil).
   918 
   937      The withEmphais argument controls if the returned string should preserve
       
   938      any emphasis. If false, a plain string is returned.
   919      This method is tuned for big collections, in not creating many
   939      This method is tuned for big collections, in not creating many
   920      intermediate strings (has linear runtime). For very small collections
   940      intermediate strings (has linear runtime). For very small collections
   921      and small strings, it may be faster to use the comma , operation."
   941      and small strings, it may be faster to use the comma , operation."
   922 
   942 
   923     |idx1        "{ Class:SmallInteger }"
   943     |idx1        "{ Class:SmallInteger }"
   946         lineString := self at:lineIndex.
   966         lineString := self at:lineIndex.
   947 
   967 
   948         lineString isNil ifTrue:[
   968         lineString isNil ifTrue:[
   949             totalLength := totalLength + sepCnt
   969             totalLength := totalLength + sepCnt
   950         ] ifFalse: [
   970         ] ifFalse: [
   951             lineString hasChangeOfEmphasis ifTrue:[
   971             withEmphasis ifTrue:[
   952                 needEmphasis := true
   972                 lineString hasChangeOfEmphasis ifTrue:[
   953             ].
   973                     needEmphasis := true
   954             (lineString bitsPerCharacter == 16) ifTrue:[
   974                 ].
   955                 any16Bit := true.
   975                 (lineString bitsPerCharacter == 16) ifTrue:[
   956                 stringClass := lineString class
   976                     any16Bit := true.
       
   977                     stringClass := lineString class
       
   978                 ].
   957             ].
   979             ].
   958             totalLength := totalLength + lineString size + sepCnt
   980             totalLength := totalLength + lineString size + sepCnt
   959         ].
   981         ].
   960     ].
   982     ].
   961     endCharacter isNil ifTrue:[
   983     endCharacter isNil ifTrue:[
   978     pos := 1.
  1000     pos := 1.
   979     idx1 to:idx2 do:[:lineIndex |
  1001     idx1 to:idx2 do:[:lineIndex |
   980         lineString := self at:lineIndex.
  1002         lineString := self at:lineIndex.
   981         thisLen := lineString size.
  1003         thisLen := lineString size.
   982         thisLen ~~ 0 ifTrue:[
  1004         thisLen ~~ 0 ifTrue:[
       
  1005             withEmphasis ifFalse:[
       
  1006                 lineString := lineString string.
       
  1007             ].
       
  1008 
   983             (anyTab := compressTabs) ifTrue:[
  1009             (anyTab := compressTabs) ifTrue:[
   984                 "
  1010                 "
   985                  mhmh: could use withTabs from String-class here,
  1011                  mhmh: could use withTabs from String-class here,
   986                  but we should avoid creating too many temporary strings
  1012                  but we should avoid creating too many temporary strings
   987                  (especially, since this method is typically used when converting
  1013                  (especially, since this method is typically used when converting
  1105           from:1 to:4 
  1131           from:1 to:4 
  1106           compressTabs:false 
  1132           compressTabs:false 
  1107           final:(Character cr) 
  1133           final:(Character cr) 
  1108     "
  1134     "
  1109 
  1135 
  1110     "Modified: 16.8.1997 / 04:44:46 / cg"
  1136     "Created: / 17.6.1998 / 12:30:32 / cg"
       
  1137     "Modified: / 17.6.1998 / 12:31:59 / cg"
  1111 !
  1138 !
  1112 
  1139 
  1113 asStringWithCRs
  1140 asStringWithCRs
  1114     "return a string generated by concatenating my elements 
  1141     "return a string generated by concatenating my elements 
  1115      (which must be strings or nil) and embedding cr characters in between.
  1142      (which must be strings or nil) and embedding cr characters in between.
  4086 ! !
  4113 ! !
  4087 
  4114 
  4088 !SequenceableCollection class methodsFor:'documentation'!
  4115 !SequenceableCollection class methodsFor:'documentation'!
  4089 
  4116 
  4090 version
  4117 version
  4091     ^ '$Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.95 1998-05-25 11:40:58 tz Exp $'
  4118     ^ '$Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.96 1998-06-17 14:25:01 cg Exp $'
  4092 ! !
  4119 ! !