|
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | using System; |
5 | | -using System.Linq; |
6 | | -using System.Collections.Generic; |
7 | | -using System.Management.Automation.Language; |
8 | 5 | using System.Text; |
9 | 6 |
|
10 | 7 | namespace Microsoft.PowerShell.EditorServices.Utility |
@@ -33,126 +30,6 @@ public static string SafeToString(this object obj) |
33 | 30 | return str; |
34 | 31 | } |
35 | 32 |
|
36 | | - /// <summary> |
37 | | - /// Get the maximum of the elements from the given enumerable. |
38 | | - /// </summary> |
39 | | - /// <typeparam name="T">Type of object for which the enumerable is defined.</typeparam> |
40 | | - /// <param name="elements">An enumerable object of type T</param> |
41 | | - /// <param name="comparer">A comparer for ordering elements of type T. The comparer should handle null values.</param> |
42 | | - /// <returns>An object of type T. If the enumerable is empty or has all null elements, then the method returns null.</returns> |
43 | | - public static T MaxElement<T>(this IEnumerable<T> elements, Func<T, T, int> comparer) where T : class |
44 | | - { |
45 | | - if (elements == null) |
46 | | - { |
47 | | - throw new ArgumentNullException(nameof(elements)); |
48 | | - } |
49 | | - |
50 | | - if (comparer == null) |
51 | | - { |
52 | | - throw new ArgumentNullException(nameof(comparer)); |
53 | | - } |
54 | | - |
55 | | - if (!elements.Any()) |
56 | | - { |
57 | | - return null; |
58 | | - } |
59 | | - |
60 | | - T maxElement = elements.First(); |
61 | | - foreach (T element in elements.Skip(1)) |
62 | | - { |
63 | | - if (element != null && comparer(element, maxElement) > 0) |
64 | | - { |
65 | | - maxElement = element; |
66 | | - } |
67 | | - } |
68 | | - |
69 | | - return maxElement; |
70 | | - } |
71 | | - |
72 | | - /// <summary> |
73 | | - /// Get the minimum of the elements from the given enumerable. |
74 | | - /// </summary> |
75 | | - /// <typeparam name="T">Type of object for which the enumerable is defined.</typeparam> |
76 | | - /// <param name="elements">An enumerable object of type T</param> |
77 | | - /// <param name="comparer">A comparer for ordering elements of type T. The comparer should handle null values.</param> |
78 | | - /// <returns>An object of type T. If the enumerable is empty or has all null elements, then the method returns null.</returns> |
79 | | - public static T MinElement<T>(this IEnumerable<T> elements, Func<T, T, int> comparer) where T : class => MaxElement(elements, (elementX, elementY) => -1 * comparer(elementX, elementY)); |
80 | | - |
81 | | - /// <summary> |
82 | | - /// Compare extents with respect to their widths. |
83 | | - /// |
84 | | - /// Width of an extent is defined as the difference between its EndOffset and StartOffest properties. |
85 | | - /// </summary> |
86 | | - /// <param name="extentX">Extent of type IScriptExtent.</param> |
87 | | - /// <param name="extentY">Extent of type IScriptExtent.</param> |
88 | | - /// <returns>0 if extentX and extentY are equal in width. 1 if width of extent X is greater than that of extent Y. Otherwise, -1.</returns> |
89 | | - public static int ExtentWidthComparer(this IScriptExtent extentX, IScriptExtent extentY) |
90 | | - { |
91 | | - if (extentX == null && extentY == null) |
92 | | - { |
93 | | - return 0; |
94 | | - } |
95 | | - |
96 | | - if (extentX != null && extentY == null) |
97 | | - { |
98 | | - return 1; |
99 | | - } |
100 | | - |
101 | | - if (extentX == null) |
102 | | - { |
103 | | - return -1; |
104 | | - } |
105 | | - |
106 | | - int extentWidthX = extentX.EndOffset - extentX.StartOffset; |
107 | | - int extentWidthY = extentY.EndOffset - extentY.StartOffset; |
108 | | - if (extentWidthX > extentWidthY) |
109 | | - { |
110 | | - return 1; |
111 | | - } |
112 | | - else if (extentWidthX < extentWidthY) |
113 | | - { |
114 | | - return -1; |
115 | | - } |
116 | | - else |
117 | | - { |
118 | | - return 0; |
119 | | - } |
120 | | - } |
121 | | - |
122 | | - /// <summary> |
123 | | - /// Check if the given coordinates are wholly contained in the instance's extent. |
124 | | - /// </summary> |
125 | | - /// <param name="scriptExtent">Extent of type IScriptExtent.</param> |
126 | | - /// <param name="line">1-based line number.</param> |
127 | | - /// <param name="column">1-based column number</param> |
128 | | - /// <returns>True if the coordinates are wholly contained in the instance's extent, otherwise, false.</returns> |
129 | | - public static bool Contains(this IScriptExtent scriptExtent, int line, int column) |
130 | | - { |
131 | | - if (scriptExtent.StartLineNumber > line || scriptExtent.EndLineNumber < line) |
132 | | - { |
133 | | - return false; |
134 | | - } |
135 | | - |
136 | | - if (scriptExtent.StartLineNumber == line) |
137 | | - { |
138 | | - if (scriptExtent.StartLineNumber == scriptExtent.EndLineNumber) |
139 | | - { |
140 | | - return scriptExtent.StartColumnNumber <= column && scriptExtent.EndColumnNumber >= column; |
141 | | - } |
142 | | - else |
143 | | - { |
144 | | - return scriptExtent.StartColumnNumber <= column; |
145 | | - } |
146 | | - } |
147 | | - |
148 | | - if (scriptExtent.EndLineNumber == line) |
149 | | - { |
150 | | - return scriptExtent.EndColumnNumber >= column; |
151 | | - } |
152 | | - |
153 | | - return true; |
154 | | - } |
155 | | - |
156 | 33 | /// <summary> |
157 | 34 | /// Same as <see cref="StringBuilder.AppendLine()" /> but never CRLF. Use this when building |
158 | 35 | /// formatting for clients that may not render CRLF correctly. |
|
0 commit comments