CharacterArray.st
changeset 5741 3a6086774d38
parent 5739 4fd3be7ccc75
child 5757 2511dcddce73
equal deleted inserted replaced
5740:a634006d10be 5741:3a6086774d38
  4918      where all tabulator characters are expanded into spaces (assuming 8-col tabs). 
  4918      where all tabulator characters are expanded into spaces (assuming 8-col tabs). 
  4919      Notice: if the receiver does not contain any tabs, it is returned unchanged;
  4919      Notice: if the receiver does not contain any tabs, it is returned unchanged;
  4920      otherwise a new string is returned.
  4920      otherwise a new string is returned.
  4921      This does handle multiline strings."
  4921      This does handle multiline strings."
  4922 
  4922 
       
  4923     ^ self withTabsExpanded:8
       
  4924 
       
  4925     "
       
  4926      ('1' , Character tab asString , 'x') withTabsExpanded          
       
  4927      ('12345' , Character tab asString , 'x') withTabsExpanded      
       
  4928      ('123456' , Character tab asString , 'x') withTabsExpanded     
       
  4929      ('1234567' , Character tab asString , 'x') withTabsExpanded   
       
  4930      ('12345678' , Character tab asString , 'x') withTabsExpanded   
       
  4931      ('123456789' , Character tab asString , 'x') withTabsExpanded 
       
  4932 
       
  4933      (String with:Character tab
       
  4934              with:Character tab
       
  4935              with:$1) withTabsExpanded
       
  4936 
       
  4937      (String with:Character tab
       
  4938              with:$1
       
  4939              with:Character tab
       
  4940              with:$2) withTabsExpanded  
       
  4941 
       
  4942      (String with:Character tab
       
  4943              with:$1
       
  4944              with:Character cr
       
  4945              with:Character tab
       
  4946              with:$2) withTabsExpanded  
       
  4947     "
       
  4948 
       
  4949     "Modified: 12.5.1996 / 13:05:10 / cg"
       
  4950 !
       
  4951 
       
  4952 withTabsExpanded:numSpaces
       
  4953     "return a string consisting of the receivers characters,
       
  4954      where all tabulator characters are expanded into spaces (assuming numSpaces-col tabs). 
       
  4955      Notice: if the receiver does not contain any tabs, it is returned unchanged;
       
  4956      otherwise a new string is returned.
       
  4957      This does handle multiline strings."
       
  4958 
  4923     |col    "{ SmallInteger }" 
  4959     |col    "{ SmallInteger }" 
  4924      str ch
  4960      str ch
  4925      dstIdx "{ SmallInteger }"
  4961      dstIdx "{ SmallInteger }"
  4926      newSz  "{ SmallInteger }"
  4962      newSz  "{ SmallInteger }"
  4927      sz "{ SmallInteger }"
  4963      sz "{ SmallInteger }"
  4942             newSz := newSz + 1.
  4978             newSz := newSz + 1.
  4943             ch == Character cr ifTrue:[
  4979             ch == Character cr ifTrue:[
  4944                 col := 1
  4980                 col := 1
  4945             ].
  4981             ].
  4946         ] ifTrue:[
  4982         ] ifTrue:[
  4947             (col \\ 8) to:8 do:[:ii |
  4983             (col \\ numSpaces) to:numSpaces do:[:ii |
  4948                 newSz := newSz + 1.
  4984                 newSz := newSz + 1.
  4949                 col := col + 1
  4985                 col := col + 1
  4950             ].
  4986             ].
  4951         ]
  4987         ]
  4952     ].
  4988     ].
  4969                 str emphasisAt:dstIdx put:e
  5005                 str emphasisAt:dstIdx put:e
  4970             ].
  5006             ].
  4971             str at:dstIdx put:ch.
  5007             str at:dstIdx put:ch.
  4972             dstIdx := dstIdx + 1
  5008             dstIdx := dstIdx + 1
  4973         ] ifTrue:[
  5009         ] ifTrue:[
  4974             (col \\ 8) to:8 do:[:ii |
  5010             (col \\ numSpaces) to:numSpaces do:[:ii |
  4975                 str at:dstIdx put:Character space.
  5011                 str at:dstIdx put:Character space.
  4976                 dstIdx := dstIdx + 1.
  5012                 dstIdx := dstIdx + 1.
  4977                 col := col + 1
  5013                 col := col + 1
  4978             ].
  5014             ].
  4979         ]
  5015         ]
  4980     ].
  5016     ].
  4981     ^ str
  5017     ^ str
  4982 
  5018 
  4983     "
  5019     "
  4984      ('1' , Character tab asString , 'x') withTabsExpanded          
  5020      ('1' , Character tab asString , 'x') withTabsExpanded          
       
  5021      ('1' , Character tab asString , 'x') withTabsExpanded:4          
  4985      ('12345' , Character tab asString , 'x') withTabsExpanded      
  5022      ('12345' , Character tab asString , 'x') withTabsExpanded      
  4986      ('123456' , Character tab asString , 'x') withTabsExpanded     
  5023      ('123456' , Character tab asString , 'x') withTabsExpanded     
  4987      ('1234567' , Character tab asString , 'x') withTabsExpanded   
  5024      ('1234567' , Character tab asString , 'x') withTabsExpanded   
  4988      ('12345678' , Character tab asString , 'x') withTabsExpanded   
  5025      ('12345678' , Character tab asString , 'x') withTabsExpanded   
  4989      ('123456789' , Character tab asString , 'x') withTabsExpanded 
  5026      ('123456789' , Character tab asString , 'x') withTabsExpanded 
  5659 ! !
  5696 ! !
  5660 
  5697 
  5661 !CharacterArray class methodsFor:'documentation'!
  5698 !CharacterArray class methodsFor:'documentation'!
  5662 
  5699 
  5663 version
  5700 version
  5664     ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.193 2000-12-08 16:47:16 cg Exp $'
  5701     ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.194 2000-12-10 14:33:14 cg Exp $'
  5665 ! !
  5702 ! !
  5666 CharacterArray initialize!
  5703 CharacterArray initialize!