Community support: Inlined changesets
--- isSeparator.1.cs ---
'From Squeak6.0alpha of 29 April 2021 [latest update: #20483] on 6 May 2021 at 10:21:24 pm'!
!Character methodsFor: 'testing' stamp: 'ct 5/6/2021 21:41'!
isSeparator
"Answer whether the receiver is a separator such as space, cr, tab, line feed, or form feed."
^ self encodedCharSet isSeparator: self! !
!EncodedCharSet class methodsFor: 'character classification' stamp: 'ct 5/6/2021 21:46'!
isSeparator: char
"Answer whether char has the code of a separator in this encoding."
^ self isSeparatorCode: char charCode! !
!EncodedCharSet class methodsFor: 'character classification' stamp: 'ct 5/6/2021 21:39'!
isSeparatorCode: anInteger
"Answer whether anInteger is the code of a separator."
^ Character separators includesCode: anInteger! !
!Unicode class methodsFor: 'character classification' stamp: 'ct 5/6/2021 21:51'!
isSeparatorCode: charCode
| cat |
cat := self generalCategoryOf: charCode.
^ cat = Cc or: [cat >= Zl and: [cat <= Zs]]! !
------
--- withAllBlanksTrimmed.1.cs ---
'From Squeak6.0alpha of 29 April 2021 [latest update: #20483] on 6 May 2021 at 10:24:39 pm'!
!String methodsFor: 'converting' stamp: 'ct 5/6/2021 21:56'!
withBlanksTrimmed
"Return a copy of the receiver from which leading and trailing blanks have been trimmed."
| first last |
first := (self findFirst: [:character | character isSeparator not]).
first = 0 ifTrue: [^ ''].
"no non-separator character"
last := self findLast: [:character | character isSeparator not].
last = 0 ifTrue: [last := self size].
(first = 1 and: [last = self size]) ifTrue: [^ self copy].
^ self copyFrom: first to: last! !
!StringTest methodsFor: 'tests - converting' stamp: 'ct 5/6/2021 22:00'!
testWithBlanksTrimmed
| s |
self assert: ' abc d ' withBlanksTrimmed = 'abc d'.
self assert: 'abc d ' withBlanksTrimmed = 'abc d'.
self assert: ' abc d' withBlanksTrimmed = 'abc d'.
self assert: (((0 to: 255) collect: [:each | each asCharacter] thenSelect: [:each | each isSeparator]) as: String) withBlanksTrimmed = ''.
self assert: ' nbsps around ' withBlanksTrimmed = 'nbsps around'.
s := 'abcd'.
self assert: s withBlanksTrimmed = s.
self assert: s withBlanksTrimmed ~~ s! !
!Text methodsFor: 'converting' stamp: 'ct 5/6/2021 21:57'!
withBlanksTrimmed
"Return a copy of the receiver from which leading and trailing blanks have been trimmed."
| first last |
first := string findFirst: [:character | character isSeparator not].
first = 0 ifTrue: [^ ''].
"no non-separator character"
last := string findLast: [:character | character isSeparator not].
last = 0 ifTrue: [last := self size].
(first = 1 and: [last = self size]) ifTrue: [^ self copy].
^ self copyFrom: first to: last! !
------