Welcome to mirror list, hosted at ThFree Co, Russian Federation.

StringDifferenceOptions.cs « Differencing « TextData « Def « Text « src - github.com/microsoft/vs-editor-api.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02e9e88b8b929e594abc251f0e8996e41456452f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//
//  Copyright (c) Microsoft Corporation. All rights reserved.
//  Licensed under the MIT License. See License.txt in the project root for license information.
//
using System;
using System.Globalization;

namespace Microsoft.VisualStudio.Text.Differencing
{
// Ignore the warnings about deprecated properties
#pragma warning disable 0618

    /// <summary>
    /// Options to use in computing string differences.
    /// </summary>
    public struct StringDifferenceOptions
    {
        // These need to be fields and specifically in this order in order for the COM-friendly
        // interfaces to be generated correctly.
        private StringDifferenceTypes differenceType;
        private int locality;
        private bool ignoreTrimWhiteSpace;

        /// <summary>
        /// The type of string differencing to do, as a combination
        /// of line, word, and character differencing.
        /// </summary>
        public StringDifferenceTypes DifferenceType 
        { 
            get { return differenceType; }
            set { differenceType = value; }
        }

        /// <summary>
        /// The greatest distance a differencing element (line, span, or character) can move 
        /// and still be considered part of the same source.  A value of 0 disables locality checking.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The use of locality in the default differencing implementation is now deprecated, and
        /// the value of this field is ignored (the same as being <c>0</c>).
        /// </para>
        /// <para>
        /// For example, if Locality is set to 100, a line is considered the same line 
        /// if it is separated by 100 or fewer lines from its neighboring lines. 
        /// If it is separated by more than 100 lines, it is considered a different line.
        /// </para>
        /// </remarks>
        [Obsolete("This value is no longer used and will be ignored.")]
        public int Locality
        {
            get { return locality; }
            set { locality = value; }
        }

        /// <summary>
        /// Gets or sets whether to ignore white space.
        /// </summary>
        public bool IgnoreTrimWhiteSpace
        {
            get { return ignoreTrimWhiteSpace; }
            set { ignoreTrimWhiteSpace = value; }
        }

        /// <summary>
        /// The behavior to use when splitting words, if word differencing is requested
        /// by the <see cref="DifferenceType" />.
        /// </summary>
        public WordSplitBehavior WordSplitBehavior { get; set; }

        /// <summary>
        /// An optional callback to override the locality for a specific round of differencing.
        /// </summary>
        /// <remarks>
        /// This callback is no longer used by the default <see cref="ITextDifferencingService"/>, and is not
        /// required to be used by an extensions that provide an implementation of a text differencing service.
        /// </remarks>
        [Obsolete("This callback is no longer used and will be ignored.")]
        public DetermineLocalityCallback DetermineLocalityCallback { get; set; }

        /// <summary>
        /// An optional predicate that allows clients to cancel differencing before it has completely finished.
        /// </summary>
        public ContinueProcessingPredicate<string> ContinueProcessingPredicate { get; set; }

        /// <summary>
        /// Constructs a <see cref="StringDifferenceOptions"/>.
        /// </summary>
        /// <param name="differenceType">The type of string differencing to do, as a combination of line, word, and character differencing.</param>
        /// <param name="locality">The greatest distance a differencing element (line, span, or character) can move and still be considered part of the same source.  A value of 0 disables locality checking.</param>
        /// <param name="ignoreTrimWhiteSpace">Determines whether whitespace should be ignored.</param>
        public StringDifferenceOptions(StringDifferenceTypes differenceType, int locality, bool ignoreTrimWhiteSpace) : this()
        {
            this.differenceType = differenceType;
            this.locality = locality;
            this.ignoreTrimWhiteSpace = ignoreTrimWhiteSpace;
        }

        /// <summary>
        /// Constructs a <see cref="StringDifferenceOptions"/> from a given <see cref="StringDifferenceOptions"/>.
        /// </summary>
        /// <param name="other">The <see cref="StringDifferenceOptions"/> to use in constructing a new <see cref="StringDifferenceOptions"/>.</param>
        public StringDifferenceOptions(StringDifferenceOptions other) : this()
        {
            this.differenceType = other.DifferenceType;
            this.locality = other.Locality;
            this.ignoreTrimWhiteSpace = other.IgnoreTrimWhiteSpace;
            this.WordSplitBehavior = other.WordSplitBehavior;
            this.DetermineLocalityCallback = other.DetermineLocalityCallback;
            this.ContinueProcessingPredicate = other.ContinueProcessingPredicate;
        }

        #region Overridden methods and operators

        /// <summary>
        /// Provides a string representation of these difference options.
        /// </summary>
        public override string ToString()
        {
            return string.Format(CultureInfo.InvariantCulture,
                    "Type: {0}, Locality: {1}, IgnoreTrimWhiteSpace: {2}, WordSplitBehavior: {3}, DetermineLocalityCallback: {4}, ContinueProcessingPredicate: {5}",
                    DifferenceType, Locality, IgnoreTrimWhiteSpace, WordSplitBehavior, DetermineLocalityCallback, ContinueProcessingPredicate);
        }

        /// <summary>
        /// Provides a hash function for the type.
        /// </summary>
        public override int GetHashCode()
        {
            int callbackHashCode = (DetermineLocalityCallback != null) ? DetermineLocalityCallback.GetHashCode() : 0;
            int predicateHashCode = (ContinueProcessingPredicate != null)? ContinueProcessingPredicate.GetHashCode() : 0;
            return (DifferenceType.GetHashCode() ^ Locality.GetHashCode() ^ IgnoreTrimWhiteSpace.GetHashCode() ^ WordSplitBehavior.GetHashCode() ^ callbackHashCode ^ predicateHashCode);
        }

        /// <summary>
        /// Determines whether two StringDifferenceOptions are the same.
        /// </summary>
        /// <param name="obj">The object to compare.</param>
        public override bool Equals(object obj)
        {
            if (!(obj is StringDifferenceOptions))
                return false;

            return this == (StringDifferenceOptions)obj;
        }

        /// <summary>
        /// Determines whether two StringDifferenceOptions are the same
        /// </summary>
        public static bool operator ==(StringDifferenceOptions left, StringDifferenceOptions right)
        {
            if (object.ReferenceEquals(left, right))
                return true;

            if ((object)left == null || (object)right == null)
                return false;

            return left.DifferenceType == right.DifferenceType &&
                   left.Locality == right.Locality &&
                   left.IgnoreTrimWhiteSpace == right.IgnoreTrimWhiteSpace &&
                   left.WordSplitBehavior == right.WordSplitBehavior &&
                   left.DetermineLocalityCallback == right.DetermineLocalityCallback &&
                   left.ContinueProcessingPredicate == right.ContinueProcessingPredicate;
        }

        /// <summary>
        /// Determines whether two StringDifferenceOptions are different.
        /// </summary>
        public static bool operator !=(StringDifferenceOptions left, StringDifferenceOptions right)
        {
            return !(left == right);
        }

        #endregion // Overridden methods and operators

    }

#pragma warning restore 0618
}