/**
 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ import diffSequences from '../diff-sequences' ; import { DIFF_DELETE , DIFF_EQUAL , DIFF_INSERT , Diff } from './cleanupSemantic' ; const diffStrings = ( a , b ) : Array < Diff > => { const isCommon = ( aIndex , bIndex ) => a [ aIndex ] === b [ bIndex ] ; let aIndex = 0 ; let bIndex = 0 ; const diffs = [ ] ; const foundSubsequence = ( nCommon , aCommon , bCommon ) => { if ( aIndex !== aCommon ) { diffs . push ( new Diff ( DIFF_DELETE , a . slice ( aIndex , aCommon ) ) ) ; } if ( bIndex !== bCommon ) { diffs . push ( new Diff ( DIFF_INSERT , b . slice ( bIndex , bCommon ) ) ) ; } aIndex = aCommon + nCommon ; bIndex = bCommon + nCommon ; diffs . push ( new Diff ( DIFF_EQUAL , b . slice ( bCommon , bIndex ) ) ) ; } ; diffSequences ( a . length , b . length , isCommon , foundSubsequence ) ; if ( aIndex !== a . length ) { diffs . push ( new Diff ( DIFF_DELETE , a . slice ( aIndex ) ) ) ; } if ( bIndex !== b . length ) { diffs . push ( new Diff ( DIFF_INSERT , b . slice ( bIndex ) ) ) ; } return diffs ; } ; export default diffStrings ;