class: CharacterArray
added: #withSeparatorsReplacedBy:
comment/format in:
#trimBlanks
#trimSeparators
#withBlanksTrimmed
--- a/CharacterArray.st Mon Jun 08 17:51:54 2015 +0200
+++ b/CharacterArray.st Mon Jun 08 20:33:31 2015 +0200
@@ -956,7 +956,7 @@
trimBlanks
"return a copy of the receiver without leading and trailing spaces.
- This is an ST/V compatibility method."
+ This is an ST/V compatibility method and an alias for withoutSpaces."
^ self withoutSpaces
@@ -1239,7 +1239,9 @@
!
withBlanksTrimmed
- "Return a copy of the receiver from which leading and trailing blanks have been trimmed."
+ "Return a copy of the receiver from which leading and trailing whitespace have been trimmed.
+ Notice the bad naming - it is trimming separators, not just blanks.
+ Added for Squeak compatibility and an alias for withoutSeparators"
^ self withoutSeparators "withoutSpaces" "/ cg: it seems that squeak cares for any whitespace
@@ -1493,7 +1495,7 @@
trimSeparators
"return a copy of the receiver without leading and trailing whiteSpace.
- Added for VisualAge compatibility"
+ Added for VisualAge compatibility and an alias for withoutSeparators"
^ self withoutSeparators
! !
@@ -6359,6 +6361,31 @@
"
!
+withSeparatorsReplacedBy:replacementCharacter
+ "return a new string with each separator (whitespace) replaced by replacementCharacter.
+ Typically used with space as replacementCharacter"
+
+ ^ self species streamContents:[:s |
+ self do:[:ch |
+ ch isSeparator ifTrue:[
+ s nextPut:replacementCharacter
+ ] ifFalse:[
+ s nextPut:ch.
+ ]
+ ]
+ ]
+
+ "
+ 'hello wwww' withSeparatorsReplacedBy:$*
+ 'hello ww ww' withSeparatorsReplacedBy:$*
+ ' hello wwww' withSeparatorsReplacedBy:$*
+ 'hel lo www w' withSeparatorsReplacedBy:$*
+ 'hel
+ lo www
+w' withSeparatorsReplacedBy:$*
+ "
+!
+
withTabs
"return a string consisting of the receivers characters
where leading spaces are replaced by tabulator characters (assuming 8-col tabs).
@@ -7455,11 +7482,11 @@
!CharacterArray class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.590 2015-06-08 15:51:54 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.591 2015-06-08 18:33:31 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.590 2015-06-08 15:51:54 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.591 2015-06-08 18:33:31 cg Exp $'
! !