Christoph Thiede uploaded a new version of Collections to project The Trunk: http://source.squeak.org/trunk/Collections-ct.1033.mcz
==================== Summary ====================
Name: Collections-ct.1033 Author: ct Time: 20 May 2023, 1:04:49.847278 pm UUID: 52d747d7-dbb4-464d-b619-ba629ff9e2ec Ancestors: Collections-mt.1032
Complements Text protocols for #findString:, #lines, #empty, and #withoutTrailingBlanks. Revises #withBlanksTrimmed and #withoutLeadingBlanks to answer an empty text rather than an empty string when no separator was found.
See https://lists.squeakfoundation.org/archives/list/squeak-dev@lists.squeakfoun....
=============== Diff against Collections-mt.1032 ===============
Item was added: + ----- Method: Text class>>empty (in category 'instance creation') ----- + empty + + ^ self new!
Item was added: + ----- Method: Text>>findString: (in category 'accessing') ----- + findString: subString + "Answer the index of subString within the receiver, starting at start. If the receiver does not contain subString, answer 0." + + ^ self findString: subString startingAt: 1!
Item was added: + ----- Method: Text>>lineCorrespondingToIndex: (in category 'accessing') ----- + lineCorrespondingToIndex: anIndex + "Answer a text containing the line at the given character position." + + self lineIndicesDo: [:start :endWithoutDelimiters :end | + anIndex <= end ifTrue: [^ self copyFrom: start to: endWithoutDelimiters]]. + ^ Text empty!
Item was added: + ----- Method: Text>>lineIndicesDo: (in category 'accessing') ----- + lineIndicesDo: aBlock + "execute aBlock with 3 arguments for each line: + - start index of line + - end index of line without line delimiter + - end index of line including line delimiter(s) CR, LF or CRLF" + + ^ self string lineIndicesDo: aBlock!
Item was added: + ----- Method: Text>>lineNumber: (in category 'accessing') ----- + lineNumber: anIndex + "Answer a text containing the characters in the given line number." + + | lineCount | + lineCount := 0. + self lineIndicesDo: [:start :endWithoutDelimiters :end | + (lineCount := lineCount + 1) = anIndex ifTrue: [ + ^ self copyFrom: start to: endWithoutDelimiters]]. + ^ nil!
Item was added: + ----- Method: Text>>lines (in category 'accessing') ----- + lines + "Answer an array of lines composing this receiver without the line ending delimiters." + + ^ Array new: (self size // 60 max: 16) streamContents: [:lines | + self linesDo: [:aLine | lines nextPut: aLine]]!
Item was added: + ----- Method: Text>>linesDo: (in category 'accessing') ----- + linesDo: aBlock + "Execute aBlock with each line in the receiver. The terminating line delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock." + + self lineIndicesDo: [:start :endWithoutDelimiters :end | + aBlock value: (self copyFrom: start to: endWithoutDelimiters)].!
Item was changed: ----- Method: Text>>withBlanksTrimmed (in category 'converting') ----- withBlanksTrimmed "Return a copy of the receiver from which leading and trailing blanks have been trimmed."
| first last | first := string indexOfAnyOf: CharacterSet nonSeparators startingAt: 1. + first = 0 ifTrue: [ ^Text empty ]. "no non-separator character" - first = 0 ifTrue: [ ^'' ]. "no non-separator character" last := string lastIndexOfAnyOf: CharacterSet nonSeparators startingAt: self size ifAbsent: [self size]. (first = 1 and: [ last = self size ]) ifTrue: [ ^self copy ]. ^self copyFrom: first to: last !
Item was changed: ----- Method: Text>>withoutLeadingBlanks (in category 'converting') ----- withoutLeadingBlanks "Return a copy of the receiver from which leading blanks have been trimmed."
| first | first := string indexOfAnyOf: CharacterSet nonSeparators startingAt: 1. + first = 0 ifTrue: [ ^Text empty ]. "no non-separator character" - first = 0 ifTrue: [ ^'' ]. "no non-separator character" first = 1 ifTrue: [ ^self copy ]. ^self copyFrom: first to: self size !
Item was added: + ----- Method: Text>>withoutTrailingBlanks (in category 'converting') ----- + withoutTrailingBlanks + "Answer a copy of the receiver from which trailing blanks have been trimmed." + + | last | + last := self findLast: [:c | c isSeparator not]. + last = 0 ifTrue: [^ Text empty]. "no non-separator character" + ^ self copyFrom: 1 to: last!
squeak-dev@lists.squeakfoundation.org