CharacterArray.st
changeset 5741 3a6086774d38
parent 5739 4fd3be7ccc75
child 5757 2511dcddce73
--- a/CharacterArray.st	Fri Dec 08 18:08:59 2000 +0100
+++ b/CharacterArray.st	Sun Dec 10 15:33:14 2000 +0100
@@ -4920,6 +4920,42 @@
      otherwise a new string is returned.
      This does handle multiline strings."
 
+    ^ self withTabsExpanded:8
+
+    "
+     ('1' , Character tab asString , 'x') withTabsExpanded          
+     ('12345' , Character tab asString , 'x') withTabsExpanded      
+     ('123456' , Character tab asString , 'x') withTabsExpanded     
+     ('1234567' , Character tab asString , 'x') withTabsExpanded   
+     ('12345678' , Character tab asString , 'x') withTabsExpanded   
+     ('123456789' , Character tab asString , 'x') withTabsExpanded 
+
+     (String with:Character tab
+             with:Character tab
+             with:$1) withTabsExpanded
+
+     (String with:Character tab
+             with:$1
+             with:Character tab
+             with:$2) withTabsExpanded  
+
+     (String with:Character tab
+             with:$1
+             with:Character cr
+             with:Character tab
+             with:$2) withTabsExpanded  
+    "
+
+    "Modified: 12.5.1996 / 13:05:10 / cg"
+!
+
+withTabsExpanded:numSpaces
+    "return a string consisting of the receivers characters,
+     where all tabulator characters are expanded into spaces (assuming numSpaces-col tabs). 
+     Notice: if the receiver does not contain any tabs, it is returned unchanged;
+     otherwise a new string is returned.
+     This does handle multiline strings."
+
     |col    "{ SmallInteger }" 
      str ch
      dstIdx "{ SmallInteger }"
@@ -4944,7 +4980,7 @@
                 col := 1
             ].
         ] ifTrue:[
-            (col \\ 8) to:8 do:[:ii |
+            (col \\ numSpaces) to:numSpaces do:[:ii |
                 newSz := newSz + 1.
                 col := col + 1
             ].
@@ -4971,7 +5007,7 @@
             str at:dstIdx put:ch.
             dstIdx := dstIdx + 1
         ] ifTrue:[
-            (col \\ 8) to:8 do:[:ii |
+            (col \\ numSpaces) to:numSpaces do:[:ii |
                 str at:dstIdx put:Character space.
                 dstIdx := dstIdx + 1.
                 col := col + 1
@@ -4982,6 +5018,7 @@
 
     "
      ('1' , Character tab asString , 'x') withTabsExpanded          
+     ('1' , Character tab asString , 'x') withTabsExpanded:4          
      ('12345' , Character tab asString , 'x') withTabsExpanded      
      ('123456' , Character tab asString , 'x') withTabsExpanded     
      ('1234567' , Character tab asString , 'x') withTabsExpanded   
@@ -5661,6 +5698,6 @@
 !CharacterArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.193 2000-12-08 16:47:16 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.194 2000-12-10 14:33:14 cg Exp $'
 ! !
 CharacterArray initialize!