//****************************************************************************************************** // Diff.cs - Gbtc // // Copyright © 2019, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this // file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 09/17/2019 - Stephen C. Wills // Generated original version of source code. // //****************************************************************************************************** #region [ Contributor License Agreements ] /* * Diff Match and Patch * Copyright 2018 The diff-match-patch Authors. * https://github.com/google/diff-match-patch * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #endregion // ReSharper disable NonReadonlyMemberInGetHashCode namespace GSF.Text { /// /// The data structure representing a diff is a List of Diff objects: /// {Diff(Operation.DELETE, "Hello"), Diff(Operation.INSERT, "Goodbye"), /// Diff(Operation.EQUAL, " world.")} /// which means: delete "Hello", add "Goodbye" and keep " world." /// public enum Operation { /// /// Target deletes text /// DELETE, /// /// Target inserts text /// INSERT, /// /// Source and target are the same /// EQUAL } /// /// Class representing one diff operation. /// /// /// This class produces a dynamic hash code, do not use /// an instance of this class as key in a dictionary. /// public class Diff { /// /// One of: INSERT, DELETE or EQUAL. /// public Operation Operation { get; set; } /// /// The text associated with this diff operation. /// public string Text; /// /// Initializes the diff with the provided values. /// /// One of INSERT, DELETE or EQUAL. /// The text being applied. public Diff(Operation operation, string text) { // Construct a diff with the specified operation and text Operation = operation; Text = text; } /// /// Display a human-readable version of this Diff. /// /// text version public override string ToString() { string prettyText = Text.Replace('\n', '\u00b6'); return "Diff(" + Operation + ",\"" + prettyText + "\")"; } /// /// Is this Diff equivalent to another Diff? /// /// Another Diff to compare against. /// true or false public override bool Equals(object obj) { // If parameter is null return false. if (obj == null) return false; // If parameter cannot be cast to Diff return false. Diff p = obj as Diff; if (p == null) return false; // Return true if the fields match. return p.Operation == Operation && p.Text == Text; } /// /// Is this Diff equivalent to another Diff? /// /// Another Diff to compare against. /// true or false public bool Equals(Diff obj) { // If parameter is null return false. if (obj == null) return false; // Return true if the fields match. return obj.Operation == Operation && obj.Text == Text; } /// /// Hash function for the Diff. /// /// The Diff's hash code public override int GetHashCode() { return Text.GetHashCode() ^ Operation.GetHashCode(); } } }