Ticket #1828: 1828_2.patch
File 1828_2.patch, 2.8 KB (added by , 16 years ago) |
---|
-
editor/dialog/fck_replace.html
231 231 232 232 // Knuth-Morris-Pratt Algorithm for stream input 233 233 KMP_NOMATCH = 0 ; 234 KMP_STARTED = 1 ; 235 KMP_ADVANCED = 2 ; 236 KMP_MATCHED = 3 ; 234 KMP_ADVANCED = 1 ; 235 KMP_MATCHED = 2 ; 237 236 function KmpMatch( pattern, ignoreCase ) 238 237 { 239 238 var overlap = [ -1 ] ; … … 268 267 this._State = 0; 269 268 return KMP_MATCHED; 270 269 } 271 return this._State > 1 ? KMP_ADVANCED : KMP_STARTED ;270 return KMP_ADVANCED ; 272 271 } 273 272 else if ( this._State == 0 ) 274 273 return KMP_NOMATCH; … … 291 290 var cursor = GlobalRange.CreateBookmark2().End ; 292 291 var matchState = KMP_NOMATCH ; 293 292 var matchBookmark = null ; 293 var matchBookmarkStart = [] ; 294 294 295 295 // Match finding. 296 296 while ( true ) … … 305 305 if ( oEditor.FCKListsLib.BlockElements[ data.tagName.toLowerCase() ] ) 306 306 { 307 307 matcher.Reset(); 308 matchBookmark = null;308 matchBookmarkStart = [] ; 309 309 } 310 310 } 311 311 else if ( data.charAt != undefined ) … … 315 315 // No possible match of any useful substring in the pattern for the currently scanned character. 316 316 // So delete any positional information. 317 317 if ( matchState == KMP_NOMATCH ) 318 matchBookmark = null ; 319 // The currently scanned character is a possible start, so mark down the starting position. 320 else if ( matchState == KMP_STARTED ) 321 matchBookmark = { Start : cursor.concat( [] ) } ; 318 matchBookmarkStart = [] ; 319 // We've matched something, but it's not a complete match, so let's just mark down the position for backtracking later. 320 else if ( matchState == KMP_ADVANCED ) 321 { 322 matchBookmarkStart.push( cursor.concat( [] ) ) ; 323 if ( matchBookmarkStart.length > matcher._State ) 324 matchBookmarkStart.shift() ; 325 } 322 326 // Found a complete match! Mark down the ending position as well. 323 327 else if ( matchState == KMP_MATCHED ) 324 328 { 325 // It is possible to get a KMP_MATCHED without KMP_ STARTED when the match pattern is only 1 character.329 // It is possible to get a KMP_MATCHED without KMP_ADVANCED when the match pattern is only 1 character. 326 330 // So need to check and mark down the starting position as well. 327 if ( matchBookmark == null)328 matchBookmark = { Start : cursor.concat( [] ) };331 if ( matchBookmarkStart.length == 0 ) 332 matchBookmarkStart = [cursor.concat( [] )] ; 329 333 330 matchBookmark .End = cursor.concat( [] );334 matchBookmark = { 'Start' : matchBookmarkStart.shift(), 'End' : cursor.concat( [] ) } ; 331 335 matchBookmark.End[ matchBookmark.End.length - 1 ]++; 332 336 333 337 // Wait, do we have to match a whole word?