|
Re: [rfc] regex rewrite: msg#00030lang.smalltalk.gnu.general
Paolo Bonzini wrote:
There's #matchRegex: '.*whatever.*' for that :) I just don't think that what it does is sufficiently useful to devote the =~ operator to it. Both Perl and Ruby return values that can be interpreted as true/false from =~, but both of them also capture the matched expression and sub-expressions into variables. We don't have that possibility, so I think =~ should work harder. Here is a new version of the patch (only the regex.st parts) that supports cute things like That is nice. I did wonder whether backslashes would be better, but eventually decided that I could live with percents. BTW there is a missing period in #copyFrom:to:replacingAllRegex:with:. Mike --- smalltalk-2.1g-regex/examples/regex.st 2005-05-30 17:05:02.399926760 +0000 +++ smalltalk-2.1g-mod/examples/regex.st 2005-05-30 23:33:38.161392248 +0000 @@ -436,19 +436,21 @@ regex := pattern asRegex. res := WriteStream on: (String new: to - from + 1). idx := from. - [ - regs := self searchRegex: regex from: idx to: to. - beg >= 1 - regs notNil - ] whileTrue: [ - beg := regs from. - end := regs to. - res next: beg - idx putAll: self startingAt: idx. - res nextPutAll: (str bindWithArguments: regs). - idx := end + 1. - beg > end ifTrue: [ res nextPut: (self at: idx). idx := idx + 1 ]. - idx > self size ifTrue: [ ^res contents ]. - ]. + [ regs := self searchRegex: regex from: idx to: to. + beg >= 1. + regs notNil ] + whileTrue: + [ beg := regs from. + end := regs to. + res next: beg - idx putAll: self startingAt: idx. + res nextPutAll: (str bindWithArguments: regs). + idx := end + 1. + beg > end + ifTrue: + [ res nextPut: (self at: idx). + idx := idx + 1 ]. + idx > self size + ifTrue: [ ^res contents ]. ]. res next: to - idx + 1 putAll: self startingAt: idx. ^res contents _______________________________________________ help-smalltalk mailing list help-smalltalk@xxxxxxx http://lists.gnu.org/mailman/listinfo/help-smalltalk |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: IO and Process Scheduler: 00030, kraehe |
|---|---|
| Next by Date: | Cialis - 75% OFF: 00030, Richard K . Lee |
| Previous by Thread: | Re: [rfc] regex rewritei: 00030, Mike Anderson |
| Next by Thread: | Re: [rfc] regex rewrite: 00030, Paolo Bonzini |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |