Changeset 1687

Show
Ignore:
Timestamp:
2008-03-10 03:33:25 (2 years ago)
Author:
martinkou
Message:

Fixed #1828 : Fixed the issue where it is still possible that the pattern logic in Find/Replace Dialog would go wrong with xxxxxy (for any distinct characters x and y, and for any 2+ repetitions of x) patterns.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/editor/dialog/fck_replace.html

    r1565 r1687  
    232232// Knuth-Morris-Pratt Algorithm for stream input 
    233233KMP_NOMATCH = 0 ; 
    234 KMP_STARTED = 1 ; 
    235 KMP_ADVANCED = 2 ; 
    236 KMP_MATCHED = 3 ; 
     234KMP_ADVANCED = 1 ; 
     235KMP_MATCHED = 2 ; 
    237236function KmpMatch( pattern, ignoreCase ) 
    238237{ 
     
    269268                                        return KMP_MATCHED; 
    270269                                } 
    271                                 return this._State > 1 ? KMP_ADVANCED : KMP_STARTED ; 
     270                                return KMP_ADVANCED ; 
    272271                        } 
    273272                        else if ( this._State == 0 ) 
     
    292291        var matchState = KMP_NOMATCH ; 
    293292        var matchBookmark = null ; 
     293        var matchBookmarkStart = [] ; 
    294294 
    295295        // Match finding. 
     
    306306                                { 
    307307                                        matcher.Reset(); 
    308                                         matchBookmark = null ; 
     308                                        matchBookmarkStart = [] ; 
    309309                                } 
    310310                        } 
     
    316316                                // So delete any positional information. 
    317317                                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                                } 
    322326                                // Found a complete match! Mark down the ending position as well. 
    323327                                else if ( matchState == KMP_MATCHED ) 
    324328                                { 
    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. 
    326330                                        // So need to check and mark down the starting position as well. 
    327                                         if ( matchBookmark == null ) 
    328                                                 matchBookmark = { Start : cursor.concat( [] ) } ; 
    329  
    330                                         matchBookmark.End = cursor.concat( [] ) ; 
     331                                        if ( matchBookmarkStart.length == 0 ) 
     332                                                matchBookmarkStart = [cursor.concat( [] )] ; 
     333 
     334                                        matchBookmark = { 'Start' : matchBookmarkStart.shift(), 'End' : cursor.concat( [] ) } ; 
    331335                                        matchBookmark.End[ matchBookmark.End.length - 1 ]++; 
    332336