Ticket #1828: 1828_2.patch

File 1828_2.patch, 2.8 kB (added by martinkou, 7 months ago)
  • editor/dialog/fck_replace.html

     
    231231 
    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{ 
    239238        var overlap = [ -1 ] ; 
     
    268267                                        this._State = 0; 
    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 ) 
    274273                                return KMP_NOMATCH; 
     
    291290        var cursor = GlobalRange.CreateBookmark2().End ; 
    292291        var matchState = KMP_NOMATCH ; 
    293292        var matchBookmark = null ; 
     293        var matchBookmarkStart = [] ; 
    294294 
    295295        // Match finding. 
    296296        while ( true ) 
     
    305305                                if ( oEditor.FCKListsLib.BlockElements[ data.tagName.toLowerCase() ] ) 
    306306                                { 
    307307                                        matcher.Reset(); 
    308                                         matchBookmark = null ; 
     308                                        matchBookmarkStart = [] ; 
    309309                                } 
    310310                        } 
    311311                        else if ( data.charAt != undefined ) 
     
    315315                                // No possible match of any useful substring in the pattern for the currently scanned character. 
    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( [] ) } ; 
     331                                        if ( matchBookmarkStart.length == 0 ) 
     332                                                matchBookmarkStart = [cursor.concat( [] )] ; 
    329333 
    330                                         matchBookmark.End = cursor.concat( [] ) ; 
     334                                        matchBookmark = { 'Start' : matchBookmarkStart.shift(), 'End' : cursor.concat( [] ) } ; 
    331335                                        matchBookmark.End[ matchBookmark.End.length - 1 ]++; 
    332336 
    333337                                        // Wait, do we have to match a whole word?