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

FindData.cs « Find « TextLogic « Def « Text « src - github.com/microsoft/vs-editor-api.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0a5cd276b2e5d4e3ffdc823cb0cb1ab3a1e94db (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
//
//  Copyright (c) Microsoft Corporation. All rights reserved.
//  Licensed under the MIT License. See License.txt in the project root for license information.
//
using System;

namespace Microsoft.VisualStudio.Text.Operations
{
#pragma warning disable CA1066 // Type {0} should implement IEquatable<T> because it overrides Equals
    /// <summary>
    /// Represents the set of data used in a search by the <see cref="ITextSearchService"/>.
    /// </summary>
    public struct FindData
#pragma warning restore CA1066 // Type {0} should implement IEquatable<T> because it overrides Equals
    {
        private string _searchString;
        private ITextSnapshot _textSnapshotToSearch;

        /// <summary>
        /// Initializes a new instance of <see cref="FindData"/> with the specified search pattern, text snapshot,
        /// find options, and text structure navigator.
        /// </summary>
        /// <param name="searchPattern">The search pattern.</param>
        /// <param name="textSnapshot">The <see cref="ITextSnapshot"/> to search.</param>
        /// <param name="findOptions">The <see cref="FindOptions"/> to use during the search.</param>
        /// <param name="textStructureNavigator">The <see cref="ITextStructureNavigator"/> to use during the search.</param>
        /// <exception cref="ArgumentNullException"><paramref name="searchPattern"/> or <paramref name="textSnapshot"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="searchPattern"/> is an empty string.</exception>
        public FindData(string searchPattern, ITextSnapshot textSnapshot, FindOptions findOptions, ITextStructureNavigator textStructureNavigator)
        {
            if (searchPattern == null)
            {
                throw new ArgumentNullException(nameof(searchPattern));
            }
            if (searchPattern.Length == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(searchPattern));
            }

            _searchString = searchPattern;
            _textSnapshotToSearch = textSnapshot ?? throw new ArgumentNullException(nameof(textSnapshot));
            FindOptions = findOptions;
            TextStructureNavigator = textStructureNavigator;
        }

        /// <summary>
        /// Initializes a new instance of <see cref="FindData"/> with the specified search pattern and text snapshot.
        /// </summary>
        /// <param name="searchPattern">The search pattern.</param>
        /// <param name="textSnapshot">The <see cref="ITextSnapshot"/> to search.</param>
        public FindData(string searchPattern, ITextSnapshot textSnapshot)
            : this(searchPattern, textSnapshot, FindOptions.None, null)
        {
        }


        internal FindData(ITextSnapshot textSnapshot) // For unit testing
        {
            _searchString = null;
            _textSnapshotToSearch = textSnapshot;
            FindOptions = FindOptions.None;
            TextStructureNavigator = null;
        }

        /// <summary>
        /// Gets or sets the string to use in the search.
        /// </summary>
        /// <exception cref="ArgumentNullException">The value is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The value is an empty string.</exception>
        public string SearchString
        {
            get { return _searchString; }
            set 
            {
                if (value == null)
                {
                    throw new ArgumentNullException(nameof(value));
                }
                if (value.Length == 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(value));
                }
                _searchString = value;
            }
        }

        /// <summary>
        /// Determines whether two <see cref="FindData"/> objects are the same.
        /// </summary>
        /// <param name="obj">The object to compare.</param>
        /// <returns><c>true</c> if the objects are the same, otherwise <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            if (obj is FindData)
            {
                FindData other = (FindData)obj;

                return (string.Equals(_searchString, other._searchString, StringComparison.Ordinal)) &&
                       (FindOptions == other.FindOptions) &&
                       object.ReferenceEquals(_textSnapshotToSearch, other._textSnapshotToSearch) &&
                       object.ReferenceEquals(TextStructureNavigator, other.TextStructureNavigator);
            }
            return false;
        }

        /// <summary>
        /// Gets the hash code for the object.
        /// </summary>
        /// <returns>The hash code.</returns>
        public override int GetHashCode()
        {
            return _searchString.GetHashCode();
        }

        /// <summary>
        /// Converts the <see cref="FindData"/> object to a string.
        /// </summary>
        /// <returns>The string representation of the <see cref="FindData"/> object.</returns>
        public override string ToString()
        {
            return base.ToString();
        }

        /// <summary>
        /// Determines whether two <see cref="FindData"/> objects are the same.
        /// </summary>
        /// <param name="data1">The first object.</param>
        /// <param name="data2">The second object.</param>
        /// <returns><c>true</c> if the objects are the same, otherwise <c>false</c>.</returns>
        public static bool operator ==(FindData data1, FindData data2)
        {
            return data1.Equals(data2);
        }

        /// <summary>
        /// Determines whether two <see cref="FindData"/> objects are different.
        /// </summary>
        /// <param name="data1">The first object.</param>
        /// <param name="data2">The second object.</param>
        /// <returns><c>true</c> if the two objects are different, otherwise <c>false</c>.</returns>
        public static bool operator !=(FindData data1, FindData data2)
        {
            return data1.Equals(data2);
        }

        /// <summary>
        /// Gets or sets the options that are used for the search.
        /// </summary>
        public FindOptions FindOptions { get; set; }

        /// <summary>
        /// Gets or sets the <see cref="ITextSnapshot"/> on which to perform the search.
        /// </summary>
        ///  <exception cref="ArgumentNullException">The value is null.</exception>
        public ITextSnapshot TextSnapshotToSearch
        {
            get { return _textSnapshotToSearch; }
            set
            {
                _textSnapshotToSearch = value ?? throw new ArgumentNullException(nameof(value));
            }
        }

        /// <summary>
        /// Gets or sets the <see cref="ITextStructureNavigator"/> to use in determining word boundaries.
        /// </summary>
        public ITextStructureNavigator TextStructureNavigator { get; set; }
    }
}