'From etoys2.3 of 28 November 2007 [latest update: #1846] on 15 December 2007 at 1:49:17 am'! "Change Set: WideFindStringMinimumFix-yo Date: 15 December 2007 Author: Yoshiki Ohshima A minimalist fix for the WideString findSubstring issue."! !String methodsFor: 'system primitives' stamp: 'yo 12/15/2007 01:36'! findSubstring: key in: body startingAt: start matchTable: matchTable "Answer the index in the string body at which the substring key first occurs, at or beyond start. The match is determined using matchTable, which can be used to effect, eg, case-insensitive matches. If no match is found, zero will be returned." | index c1 c2 c1Index c2Index | matchTable == nil ifTrue: [ key size = 0 ifTrue: [^ 0]. start to: body size - key size + 1 do: [:startIndex | index _ 1. [(body at: startIndex+index-1) = (key at: index)] whileTrue: [index = key size ifTrue: [^ startIndex]. index _ index+1]]. ^ 0 ]. key size = 0 ifTrue: [^ 0]. start to: body size - key size + 1 do: [:startIndex | index _ 1. [c1 _ body at: startIndex+index-1. c2 _ key at: index. c1Index _ c1 asciiValue + 1. c2Index _ c2 asciiValue + 1. ((c1 leadingChar = 0) ifTrue: [ c1Index > matchTable size ifTrue: [c1Index] ifFalse: [matchTable at: c1Index]] ifFalse: [c1Index]) = ((c2 leadingChar = 0) ifTrue: [ c2Index > matchTable size ifTrue: [c2Index] ifFalse: [matchTable at: c2Index]] ifFalse: [c2Index])] whileTrue: [index = key size ifTrue: [^ startIndex]. index _ index+1]]. ^ 0 ! !