2
// SearchPopupSearchPattern.cs
5
// Mike KrĆ¼ger <mkrueger@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using System.Threading;
29
using System.Threading.Tasks;
30
using MonoDevelop.Core;
31
using System.Collections.Generic;
34
using ICSharpCode.NRefactory.TypeSystem;
35
using MonoDevelop.Ide;
36
using MonoDevelop.Ide.CodeCompletion;
38
namespace MonoDevelop.Components.MainToolbar
40
public struct SearchPopupSearchPattern
42
public readonly string Tag;
43
public readonly string Pattern;
44
public readonly int LineNumber;
45
public readonly int Column;
47
public bool HasLineNumber {
49
return LineNumber >= 0;
52
public bool HasColumn {
58
public SearchPopupSearchPattern (string tag, string pattern, int lineNumber = -1, int column = -1)
62
LineNumber = lineNumber;
66
public static SearchPopupSearchPattern ParsePattern (string searchPattern)
69
string pattern = null;
74
string[] parts = new string[maxTag];
77
for (int i = 0; i < searchPattern.Length; i++) {
78
if (searchPattern[i] == ':') {
79
parts[foundTags++] = searchPattern.Substring (idx, i - idx);
81
if (foundTags >= maxTag)
85
if (foundTags < maxTag)
86
parts[foundTags++] = searchPattern.Substring (idx,searchPattern.Length - idx);
92
if (!string.IsNullOrEmpty (parts[1]) && TryParseLineColumn (parts[1], ref lineNumber, ref column)) {
93
if (!string.IsNullOrEmpty (parts [0]))
101
if (IsNumber (parts [1]) && IsNumber (parts [2])) {
102
if (!string.IsNullOrEmpty (parts [0]))
104
if (!TryParseLineColumn (parts [1] + "," + parts[2], ref lineNumber, ref column))
106
} else if (IsNumber (parts [1]) && string.IsNullOrEmpty (parts [2])) {
107
if (!string.IsNullOrEmpty (parts [0]))
109
if (!TryParseLineColumn (parts [1] + ",0", ref lineNumber, ref column))
113
pattern = parts [1] ?? "";
114
if (!TryParseLineColumn (parts [2], ref lineNumber, ref column))
121
if (!TryParseLineColumn (parts [2] +","+parts[3], ref lineNumber, ref column))
125
return new SearchPopupSearchPattern (tag, pattern, lineNumber, column);
128
static bool TryParseLineColumn (string str, ref int lineNumber, ref int columnNumber)
130
int idx = str.IndexOf (',');
135
line = str.Substring (0, idx).Trim ();
136
col = str.Substring (idx + 1).Trim ();
140
lineNumber = string.IsNullOrEmpty (line) ? 0 : int.Parse (line);
147
columnNumber = string.IsNullOrEmpty (col) ? 0 : int.Parse (col);
154
static bool IsNumber (string text)
159
} catch (Exception) {
164
public override int GetHashCode ()
166
return (Tag != null ? Tag.GetHashCode () : 0) ^ (Pattern != null ? Pattern.GetHashCode () : 0) ^ LineNumber.GetHashCode () ^ Column.GetHashCode ();
169
public override bool Equals (object obj)
171
if (!(obj is SearchPopupSearchPattern))
173
var other = (SearchPopupSearchPattern)obj;
174
return Tag == other.Tag && Pattern == other.Pattern && LineNumber == other.LineNumber && Column == other.Column;
177
public static bool operator ==(SearchPopupSearchPattern l, SearchPopupSearchPattern r)
182
public static bool operator !=(SearchPopupSearchPattern l, SearchPopupSearchPattern r)
187
static string FormatString (string pattern)
191
return '"' + pattern + '"';
194
public override string ToString ()
196
return string.Format ("[SearchPopupSearchPattern: Tag={0}, Pattern={1}, LineNumber={2}, Column={3}]", FormatString(Tag), FormatString(Pattern), LineNumber, Column);
b'\\ No newline at end of file'