--- a/String.st Mon Sep 11 00:30:37 1995 +0200
+++ b/String.st Mon Sep 11 00:31:43 1995 +0200
@@ -21,7 +21,7 @@
COPYRIGHT (c) 1988 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libbasic/String.st,v 1.45 1995-09-07 11:59:35 claus Exp $
+$Header: /cvs/stx/stx/libbasic/String.st,v 1.46 1995-09-10 22:31:43 claus Exp $
'!
!String class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libbasic/String.st,v 1.45 1995-09-07 11:59:35 claus Exp $
+$Header: /cvs/stx/stx/libbasic/String.st,v 1.46 1995-09-10 22:31:43 claus Exp $
"
!
@@ -500,6 +500,83 @@
^ self
"Modified: 1.9.1995 / 02:25:45 / claus"
+!
+
+withTabsExpanded
+ "return a copy of the receiver where all tabulator characters
+ are expanded into spaces (assuming 8-col tabs).
+ rewritten for speed - this is very heavily used when reading
+ big files in the FileBrowser."
+%{
+ char buffer[80*8];
+ char *srcP, *dstP, *cp0;
+ int idx, sz;
+ int any = 0;
+ OBJ newString;
+ char c;
+
+ if (__qClass(self) == String) {
+ /*
+ * for small strings (< 80), do it without a prescan ...
+ */
+ if (__stringSize(self) < 80) {
+ for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
+ if (c == '\t') {
+ any = 1;
+ idx = (dstP-buffer+1) % 8;
+ while (idx <= 8) {
+ idx++;
+ *dstP++ = ' ';
+ }
+ } else {
+ *dstP++ = c;
+ }
+ }
+ if (! any) RETURN(self);
+ *dstP++ = '\0';
+ RETURN (__MKSTRING(buffer));
+ }
+ /*
+ * scan for size ...
+ */
+ for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
+ if (c == '\t') {
+ any = 1;
+ idx = (dstP-buffer+1) % 8;
+ while (idx <= 8) {
+ idx++;
+ dstP++;
+ }
+ } else {
+ dstP++;
+ }
+ }
+ if (! any) RETURN(self);
+
+ /*
+ * get the string
+ */
+ sz = OHDR_SIZE + (dstP-buffer) + 1;
+ _qNew(newString, sz, __context);
+ if (newString != nil) {
+ _InstPtr(newString)->o_class = String;
+ for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) {
+ if (c == '\t') {
+ idx = (dstP-cp0+1) % 8;
+ while (idx <= 8) {
+ idx++;
+ *dstP++ = ' ';
+ }
+ } else {
+ *dstP++ = c;
+ }
+ }
+ *dstP++ = '\0';
+ RETURN (newString);
+ }
+ }
+%}.
+ ^ super withTabsExpanded
! !
!String class methodsFor:'binary storage'!