--- a/CharacterArray.st Thu Jun 05 12:17:59 2008 +0200
+++ b/CharacterArray.st Mon Jun 09 19:25:17 2008 +0200
@@ -4003,6 +4003,37 @@
"Modified: / 24-10-2006 / 12:32:26 / cg"
!
+contractLeftTo:maxLen
+ "if the receivers size is less or equal to maxLen, return it.
+ Otherwise, return a copy of the receiver, where some characters
+ near the first quarter have been replaced by '...' for a total string length
+ of maxLen.
+ Very similar to contractTo:, but better to abbreviate long filename entries,
+ where the right part is of more use than the left."
+
+ |sz "{ SmallInteger }"
+ halfSize quarterSize "{ SmallInteger }"
+ leftEnd rightEnd rightStart|
+
+ (sz := self size) <= maxLen ifTrue:[ ^ self ].
+
+ halfSize := maxLen // 2.
+ quarterSize := maxLen // 4.
+ leftEnd := quarterSize-1.
+ rightEnd := maxLen - leftEnd - 3.
+ rightStart := sz - rightEnd + 1.
+ ^ (self copyTo:leftEnd),'...',(self copyFrom:rightStart)
+
+ "
+ '12345678901234' contractLeftTo:15
+ '123456789012345' contractLeftTo:15
+ '1234567890123456' contractLeftTo:15
+ 'aShortString' contractLeftTo:15
+ 'aVeryLongNameForAStringThatShouldBeShortened' contractLeftTo:15
+ 'C:\Dokumente und Einstellungen\cg\work\bosch\dapas\hw_schnittstellen\DAPAS__HpibDLL.st' contractLeftTo:40
+ "
+!
+
contractTo:maxLen
"if the receivers size is less or equal to maxLen, return it.
Otherwise, return a copy of the receiver, where some characters
@@ -5455,7 +5486,7 @@
!CharacterArray class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.375 2008-05-28 09:41:59 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.376 2008-06-09 17:25:17 cg Exp $'
! !
CharacterArray initialize!