forked from GerHobbelt/gitignore-parser
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Extensions.cs
259 lines (238 loc) · 14.5 KB
/
Extensions.cs
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
using System;
#if !NET7_0_OR_GREATER
using System.Collections.Generic;
using System.Linq;
#endif
using System.Text;
namespace GitignoreParserNet;
internal static class Extensions
{
/// <summary>
/// Prepends the string representation of a specified System.Char object to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The character to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, char value) => builder.Insert(0, value);
/// <summary>
/// Prepends a specified number of copies of the string representation of a Unicode character to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The character to prepend.</param>
/// <param name="repeatCount">The number of times to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// repeatCount is less than zero,
/// or enlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, char value, int repeatCount)
{
return builder.Insert(0, new string(value, repeatCount));
}
/// <summary>
/// Prepends the string representation of the Unicode characters in a specified array to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The array of characters to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, char[] value) => builder.Insert(0, value);
/// <summary>
/// Prepends a copy of the specified string to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The string to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, string value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified 64-bit unsigned integer to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, ulong value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified 64-bit signed integer to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, long value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified 32-bit unsigned integer to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, uint value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified 32-bit signed integer to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, int value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified 16-bit unsigned integer to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, ushort value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified 16-bit signed integer to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, short value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified 8-bit unsigned integer to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, byte value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified 8-bit signed integer to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, sbyte value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified decimal number to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, decimal value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified double-precision floating-point number to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, double value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified single-precision floating-point number to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, float value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified boolean value to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The boolean value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, bool value) => builder.Insert(0, value);
/// <summary>
/// Prepends the string representation of a specified object to this instance.
/// </summary>
/// <param name="builder">The instance to prepend.</param>
/// <param name="value">The object value to prepend.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Eenlarging the value of this instance would exceed <see cref="StringBuilder.MaxCapacity"/>.
/// </exception>
/// <exception cref="OutOfMemoryException">Out of memory.</exception>
internal static StringBuilder Prepend(this StringBuilder builder, object value) => builder.Insert(0, value);
#if !NETSTANDARD2_1_OR_GREATER && !NETCOREAPP2_0_OR_GREATER
/// <summary>
/// Determines whether the beginning of this string instance matches the specified character.
/// </summary>
/// <param name="string">The string instance to test.</param>
/// <param name="value">The character to find.</param>
/// <returns><see langword="true"/> if value matches the beginning of this string; otherwise, <see langword="false"/>.</returns>
internal static bool StartsWith(this string @string, char value) => @string.Length >= 1 && @string[0] == value;
/// <summary>
/// Determines whether the end of this string instance matches the specified character.
/// </summary>
/// <param name="string">The string instance to test.</param>
/// <param name="value">The character to find.</param>
/// <returns><see langword="true"/> if value matches the end of this instance; otherwise, <see langword="false"/>.</returns>
internal static bool EndsWith(this string @string, char value) => @string.Length >= 1 && @string[@string.Length - 1] == value;
#endif
#if !NET7_0_OR_GREATER
/// <summary>
/// Sorts the elements of a sequence in ascending order.
/// </summary>
/// <typeparam name="T">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">A sequence of values to order.</param>
/// <returns>An <see cref="IOrderedEnumerable{TElement}"/> whose elements are sorted.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
/// <remarks>
/// <para>
/// This method is implemented by using deferred execution. The immediate return value is an object
/// that stores all the information that is required to perform the action.
/// The query represented by this method is not executed until the object is enumerated by calling
/// its <see cref="IEnumerable{T}.GetEnumerator"/> method.
///
/// This method compares elements by using the default comparer <see cref="Comparer{T}.Default"/>.
/// </para>
/// </remarks>
internal static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source) => source.OrderBy(static x => x);
#endif
}