ListView.st
changeset 4444 3cffa8b45961
parent 4435 3cacb6eddf23
child 4448 2e4bb12f298c
equal deleted inserted replaced
4443:a5a69820a9b5 4444:3cffa8b45961
  4219     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  4219     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  4220      found evaluate block2.
  4220      found evaluate block2.
  4221      Sorry, but pattern is no regular expression pattern (yet)"
  4221      Sorry, but pattern is no regular expression pattern (yet)"
  4222 
  4222 
  4223     |lineString
  4223     |lineString
  4224      found firstChar1 firstChar2 c pc
  4224      found firstChar1 firstChar2 c pc col1
  4225      col         "{ Class: SmallInteger }"
  4225      col         "{ Class: SmallInteger }"
  4226      cc          "{ Class: SmallInteger }"
  4226      cc          "{ Class: SmallInteger }"
  4227      patternSize "{ Class: SmallInteger }"
  4227      patternSize "{ Class: SmallInteger }"
  4228      line1       "{ Class: SmallInteger }"
  4228      line1       "{ Class: SmallInteger }"
  4229      lineSize    "{ Class: SmallInteger }" |
  4229      lineSize    "{ Class: SmallInteger }" |
  4231     patternSize := pattern size.
  4231     patternSize := pattern size.
  4232     (list notNil
  4232     (list notNil
  4233     and:[startLine > 0
  4233     and:[startLine > 0
  4234     and:[patternSize ~~ 0]])
  4234     and:[patternSize ~~ 0]])
  4235     ifTrue:[
  4235     ifTrue:[
  4236 	self withCursor:Cursor questionMark do:[
  4236         self withCursor:Cursor questionMark do:[
  4237 	    col := startCol - 1.
  4237             col := startCol - 1.
  4238 	    firstChar1 := pattern at:1.
  4238             firstChar1 := pattern at:1.
  4239 	    ignCase ifTrue:[
  4239             ignCase ifTrue:[
  4240 		firstChar1 := firstChar1 asLowercase.
  4240                 firstChar1 := firstChar1 asLowercase.
  4241 		firstChar2 := firstChar1 asUppercase.
  4241                 firstChar2 := firstChar1 asUppercase.
  4242 	    ] ifFalse:[
  4242             ] ifFalse:[
  4243 		firstChar2 := firstChar1
  4243                 firstChar2 := firstChar1
  4244 	    ].
  4244             ].
  4245 
  4245 
  4246 	    line1 := startLine.
  4246             line1 := startLine.
  4247 	    line1 > list size ifTrue:[
  4247             line1 > list size ifTrue:[
  4248 		line1 := list size.
  4248                 line1 := list size.
  4249 		col := -999
  4249                 col := -999
  4250 	    ] ifFalse:[
  4250             ] ifFalse:[
  4251 		col > (list at:line1) size ifTrue:[
  4251                 col > (list at:line1) size ifTrue:[
  4252 		    col := -999
  4252                     col := -999
  4253 		]
  4253                 ]
  4254 	    ].
  4254             ].
  4255 	    line1 to:1 by:-1 do:[:lnr |
  4255             line1 to:1 by:-1 do:[:lnr |
  4256 		lineString := list at:lnr.
  4256                 lineString := list at:lnr.
  4257 		lineString notNil ifTrue:[
  4257                 lineString notNil ifTrue:[
  4258 		    lineString := lineString asString
  4258                     lineString := lineString asString.
  4259 		].
  4259                     lineString isString ifTrue:[
  4260 		lineString notNil ifTrue:[
  4260                         "/ quick check if pattern is present
  4261 		    lineSize := lineString size.
  4261                         col1 := lineString
  4262 		    col == -999 ifTrue:[col := lineSize - patternSize + 1].
  4262                                 findString:pattern
  4263 		    [(col > 0)
  4263                                 startingAt:1
  4264 		     and:[(c := lineString at:col) ~= firstChar1
  4264                                 ifAbsent:0
  4265 		     and:[c ~= firstChar2]]] whileTrue:[
  4265                                 caseSensitive: ignCase not.
  4266 			col := col - 1
  4266                         col1 ~~ 0 ifTrue:[
  4267 		    ].
  4267                             lineSize := lineString size.
  4268 		    [col > 0] whileTrue:[
  4268                             col == -999 ifTrue:[col := lineSize - patternSize + 1].
  4269 			cc := col.
  4269                             [(col > 0)
  4270 			found := true.
  4270                              and:[(c := lineString at:col) ~= firstChar1
  4271 			1 to:patternSize do:[:cnr |
  4271                              and:[c ~= firstChar2]]] whileTrue:[
  4272 			    cc > lineSize ifTrue:[
  4272                                 col := col - 1
  4273 				found := false
  4273                             ].
  4274 			    ] ifFalse:[
  4274                             [col > 0] whileTrue:[
  4275 				pc := pattern at:cnr.
  4275                                 cc := col.
  4276 				c := lineString at:cc.
  4276                                 found := true.
  4277 				pc ~= c ifTrue:[
  4277                                 1 to:patternSize do:[:cnr |
  4278 				    (ignCase not or:[pc asLowercase ~= c asLowercase]) ifTrue:[
  4278                                     cc > lineSize ifTrue:[
  4279 					found := false
  4279                                         found := false
  4280 				    ]
  4280                                     ] ifFalse:[
  4281 				]
  4281                                         pc := pattern at:cnr.
  4282 			    ].
  4282                                         c := lineString at:cc.
  4283 			    cc := cc + 1
  4283                                         pc ~= c ifTrue:[
  4284 			].
  4284                                             (ignCase not or:[pc asLowercase ~= c asLowercase]) ifTrue:[
  4285 			found ifTrue:[
  4285                                                 found := false
  4286 			    ^ block1 value:lnr value:col.
  4286                                             ]
  4287 			].
  4287                                         ]
  4288 			col := col - 1.
  4288                                     ].
  4289 			[(col > 0)
  4289                                     cc := cc + 1
  4290 			and:[(c := lineString at:col) ~= firstChar1
  4290                                 ].
  4291 			and:[c ~= firstChar2]]] whileTrue:[
  4291                                 found ifTrue:[
  4292 			    col := col - 1
  4292                                     ^ block1 value:lnr value:col.
  4293 			]
  4293                                 ].
  4294 		    ]
  4294                                 col := col - 1.
  4295 		].
  4295                                 [(col > 0)
  4296 		col := -999.
  4296                                 and:[(c := lineString at:col) ~= firstChar1
  4297 	    ]
  4297                                 and:[c ~= firstChar2]]] whileTrue:[
  4298 	]
  4298                                     col := col - 1
       
  4299                                 ]
       
  4300                             ]
       
  4301                         ]
       
  4302                     ].
       
  4303                 ].
       
  4304                 col := -999.
       
  4305             ]
       
  4306         ]
  4299     ].
  4307     ].
  4300     "not found"
  4308     "not found"
  4301 
  4309 
  4302     ^ block2 value
  4310     ^ block2 value
  4303 
  4311 
  4304     "Created: / 13.9.1997 / 01:06:19 / cg"
  4312     "Created: / 13-09-1997 / 01:06:19 / cg"
  4305     "Modified: / 23.12.2001 / 13:14:23 / cg"
  4313     "Modified: / 05-08-2012 / 12:16:31 / cg"
  4306 !
  4314 !
  4307 
  4315 
  4308 searchBackwardFor:pattern startingAtLine:startLine col:startCol ifFound:block1 ifAbsent:block2
  4316 searchBackwardFor:pattern startingAtLine:startLine col:startCol ifFound:block1 ifAbsent:block2
  4309     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  4317     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  4310      found evaluate block2.
  4318      found evaluate block2.
  4318 	ifAbsent:block2
  4326 	ifAbsent:block2
  4319 
  4327 
  4320     "Modified: 13.9.1997 / 01:07:36 / cg"
  4328     "Modified: 13.9.1997 / 01:07:36 / cg"
  4321 !
  4329 !
  4322 
  4330 
  4323 searchForwardFor:pattern ignoreCase:ignCase match: match startingAtLine:startLine col:startCol ifFound:block1 ifAbsent:block2
  4331 searchForwardFor:pattern ignoreCase:ignCase match:match startingAtLine:startLine col:startCol ifFound:block1 ifAbsent:block2
  4324     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  4332     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  4325      found evaluate block2."
  4333      found evaluate block2."
  4326 
  4334 
  4327     |lineString col patternSize
  4335     |lineString col patternSize
  4328      line1 "{Class: SmallInteger}"
  4336      line1 "{Class: SmallInteger}"
  4329      line2 "{Class: SmallInteger}"
  4337      line2 "{Class: SmallInteger}"
  4330      p realPattern|
  4338      p realPattern|
  4331 
  4339 
  4332     patternSize := pattern size.
  4340     patternSize := pattern size.
  4333     (list notNil and:[patternSize ~~ 0]) ifTrue:[
  4341     (list notNil and:[patternSize ~~ 0]) ifTrue:[
  4334 	self withCursor:Cursor questionMark do:[
  4342         self withCursor:Cursor questionMark do:[
  4335 
  4343 
  4336 	    col := startCol + 1.
  4344             col := startCol + 1.
  4337 	    line1 := startLine.
  4345             line1 := startLine.
  4338 	    line2 := list size.
  4346             line2 := list size.
  4339 
  4347 
  4340 	    (match and:[pattern includesUnescapedMatchCharacters]) ifTrue:[
  4348             (match and:[pattern includesUnescapedMatchCharacters]) ifTrue:[
  4341 		"perform a findMatchString (matching)"
  4349                 "perform a findMatchString (matching)"
  4342 		p := pattern species new:0.
  4350                 p := pattern species new:0.
  4343 		(pattern startsWith:$*) ifFalse:[
  4351                 (pattern startsWith:$*) ifFalse:[
  4344 		    p := p , '*'
  4352                     p := p , '*'
  4345 		].
  4353                 ].
  4346 		p := p , pattern.
  4354                 p := p , pattern.
  4347 		(pattern endsWith:$*) ifFalse:[
  4355                 (pattern endsWith:$*) ifFalse:[
  4348 		    p := p , '*'
  4356                     p := p , '*'
  4349 		].
  4357                 ].
  4350 		realPattern := pattern.
  4358                 realPattern := pattern.
  4351 		(realPattern startsWith:$*) ifTrue:[
  4359                 (realPattern startsWith:$*) ifTrue:[
  4352 		    realPattern := realPattern copyFrom:2
  4360                     realPattern := realPattern copyFrom:2
  4353 		].
  4361                 ].
  4354 		line1 to:line2 do:[:lnr |
  4362                 line1 to:line2 do:[:lnr |
  4355 		    lineString := list at:lnr.
  4363                     lineString := list at:lnr.
  4356 		    lineString notNil ifTrue:[
  4364                     lineString notNil ifTrue:[
  4357 			"/ first a crude check ...
  4365                         lineString := lineString asString string.
  4358 			(p match:lineString ignoreCase:ignCase) ifTrue:[
  4366                         lineString isString ifTrue:[
  4359 			    "/ ok, there it is; look at which position
  4367                             "/ first a crude check ...
  4360 			    col := lineString
  4368                             (p match:lineString ignoreCase:ignCase) ifTrue:[
  4361 					findMatchString:realPattern
  4369                                 "/ ok, there it is; look at which position
  4362 					startingAt:col
  4370                                 col := lineString
  4363 					ignoreCase:ignCase
  4371                                         findMatchString:realPattern
  4364 					ifAbsent:0.
  4372                                         startingAt:col
  4365 			    col ~~ 0 ifTrue:[
  4373                                         ignoreCase:ignCase
  4366 				^ block1 value:lnr value:col.
  4374                                         ifAbsent:0.
  4367 			    ]
  4375                                 col ~~ 0 ifTrue:[
  4368 			].
  4376                                     ^ block1 value:lnr value:col.
  4369 		    ].
  4377                                 ]
  4370 		    col := 1
  4378                             ]
  4371 		]
  4379                         ].
  4372 	    ] ifFalse:[
  4380                     ].
  4373 		"perform a findString (no matching)"
  4381                     col := 1
  4374 		p := pattern "withoutMatchEscapes".
  4382                 ]
  4375 		line1 to:line2 do:[:lnr |
  4383             ] ifFalse:[
  4376 		    lineString := list at:lnr.
  4384                 "perform a findString (no matching)"
  4377 		    lineString notNil ifTrue:[
  4385                 p := pattern "withoutMatchEscapes".
  4378 			lineString := lineString asString
  4386                 line1 to:line2 do:[:lnr |
  4379 		    ].
  4387                     lineString := list at:lnr.
  4380 		    lineString isString ifTrue:[
  4388                     lineString notNil ifTrue:[
  4381 			col := lineString
  4389                         lineString := lineString asString string.
  4382 				    findString:p
  4390                         lineString isString ifTrue:[
  4383 				    startingAt:col
  4391                             col := lineString
  4384 				    ifAbsent:0
  4392                                     findString:p
  4385 				    caseSensitive: ignCase not.
  4393                                     startingAt:col
  4386 			col ~~ 0 ifTrue:[
  4394                                     ifAbsent:0
  4387 			    ^ block1 value:lnr value:col.
  4395                                     caseSensitive: ignCase not.
  4388 			]
  4396                             col ~~ 0 ifTrue:[
  4389 		    ].
  4397                                 ^ block1 value:lnr value:col.
  4390 		    col := 1
  4398                             ]
  4391 		]
  4399                         ]
  4392 	    ].
  4400                     ].
  4393 	]
  4401                     col := 1
       
  4402                 ]
       
  4403             ].
       
  4404         ]
  4394     ].
  4405     ].
  4395     "not found"
  4406     "not found"
  4396 
  4407 
  4397     ^ block2 value
  4408     ^ block2 value
  4398 
  4409 
  4399     "Created: 13.9.1997 / 01:06:31 / cg"
  4410     "Created: / 13-09-1997 / 01:06:31 / cg"
  4400     "Modified: 13.9.1997 / 01:11:28 / cg"
  4411     "Modified: / 05-08-2012 / 12:22:42 / cg"
  4401 !
  4412 !
  4402 
  4413 
  4403 searchForwardFor:pattern ignoreCase:ignCase startingAtLine:startLine col:startCol ifFound:block1 ifAbsent:block2
  4414 searchForwardFor:pattern ignoreCase:ignCase startingAtLine:startLine col:startCol ifFound:block1 ifAbsent:block2
  4404     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  4415     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  4405      found evaluate block2."
  4416      found evaluate block2."
  4697 ! !
  4708 ! !
  4698 
  4709 
  4699 !ListView class methodsFor:'documentation'!
  4710 !ListView class methodsFor:'documentation'!
  4700 
  4711 
  4701 version_CVS
  4712 version_CVS
  4702     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.352 2012-07-25 23:25:17 cg Exp $'
  4713     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.353 2012-08-05 10:24:12 cg Exp $'
  4703 ! !
  4714 ! !