Il 17/10/2012 17:43, Rick Flower ha scritto: > By the way.. I added a few methods that I found very helpful in my text > processing I've been doing lately.. Perhaps someone else might find these > of interest -- they're modeled after similar methods already present but > these work for stings instead of single characters. Enjoy! > > Stream extend [ > skipToString: aString [ > <comment: 'Skip to the specified string in the file -- must match > the entire line!!'> > [self atEnd] whileFalse: [ > self nextLine = aString ifTrue: [^true]]. > ^false > ] > > findSubstring: aString [ > <comment: 'Skip to the specified sub-string in the stream'> > | string | > [self atEnd] whileFalse: [ > string := self nextLine. > (string includesSubstring: aString caseSensitive: false) > ifTrue: [ > "match found.. back the stream up to the start of the line" > self position: (self position - string size - 1). > ^true > ] > ]. > ^false > ]
Isn't this skipToAll: ? > > upToString: aString [ > | nextLine ws | > ws := WriteStream on: (self species new: 8). > [self atEnd or: [(nextLine := self nextLine) = aString]] > whileFalse: [ws nextPutAll: nextLine. ws nextPut: Character > nl]. > ^ws contents > ] This is a bit like upToAll: but not quite, what about calling it upToLine: instead? > upUntilStringPrefixMissing: aString [ > | nextLine ws | > ws := WriteStream on: (self species new: 8). > [self atEnd or: [(nextLine := self nextLine) startsWith: aString]] > whileTrue: [ws nextPutAll: nextLine. ws nextPut: Character nl]. > ^ws contents > ] upToLineStartingWith: Paolo > ] > > > _______________________________________________ > help-smalltalk mailing list > [email protected] > https://lists.gnu.org/mailman/listinfo/help-smalltalk > _______________________________________________ help-smalltalk mailing list [email protected] https://lists.gnu.org/mailman/listinfo/help-smalltalk
