Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit accc67c

Browse files
committed
Add string overloads
1 parent d781336 commit accc67c

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

‎src/AlgorithmForce.Searching/Deferred/EnumerableExtensions.cs‎

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,86 @@ public static int IndexOf<T>(this IEnumerable<T> s, IReadOnlyList<T> t, int star
144144

145145
#endregion
146146

147+
#region string (IndexOf)
148+
149+
/// <summary>
150+
/// Reports the zero-based index of the first occurrence of the specified collection in this instance.
151+
/// </summary>
152+
/// <param name="s">The current collection.</param>
153+
/// <param name="t">The collection to seek.</param>
154+
/// <returns>
155+
/// The zero-based index position of value if <paramref name="t"/> is found, or -1 if it is not.
156+
/// If <paramref name="t"/> is empty, the return value is 0.
157+
/// </returns>
158+
/// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception>
159+
public static int IndexOf(this IEnumerable<char> s, string t)
160+
{
161+
return s.IndexOf(t, 0, EqualityComparer<char>.Default);
162+
}
163+
164+
/// <summary>
165+
/// Reports the zero-based index of the first occurrence of the specified collection in this instance
166+
/// and uses the specified <see cref="IEqualityComparer{T}"/>.
167+
/// </summary>
168+
/// <param name="s">The current collection.</param>
169+
/// <param name="t">The collection to seek.</param>
170+
/// <param name="comparer">The specified <see cref="IEqualityComparer{T}"/> instance.</param>
171+
/// <returns>
172+
/// The zero-based index position of value if <paramref name="t"/> is found, or -1 if it is not.
173+
/// If <paramref name="t"/> is empty, the return value is 0.
174+
/// </returns>
175+
/// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception>
176+
public static int IndexOf(this IEnumerable<char> s, string t, IEqualityComparer<char> comparer)
177+
{
178+
return s.IndexOf(t, 0, comparer);
179+
}
180+
181+
/// <summary>
182+
/// Reports the zero-based index of the first occurrence of the specified collection in this instance.
183+
/// The search starts at a specified position.
184+
/// </summary>
185+
/// <param name="s">The current collection.</param>
186+
/// <param name="t">The collection to seek.</param>
187+
/// <param name="startIndex">The search starting position.</param>
188+
/// <returns>
189+
/// The zero-based index position of value if <paramref name="t"/> is found, or -1 if it is not.
190+
/// If <paramref name="t"/> is empty, the return value is 0.
191+
/// </returns>
192+
/// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception>
193+
/// <exception cref="ArgumentOutOfRangeException">
194+
/// <paramref name="startIndex"/> is less than zero.
195+
/// </exception>
196+
public static int IndexOf(this IEnumerable<char> s, string t, int startIndex)
197+
{
198+
return s.IndexOf(t, startIndex, EqualityComparer<char>.Default);
199+
}
200+
201+
/// <summary>
202+
/// Reports the zero-based index of the first occurrence of the specified string in this instance
203+
/// and uses the specified <see cref="IEqualityComparer{T}"/>.
204+
/// The search starts at a specified position.
205+
/// </summary>
206+
/// <param name="s">The current collection.</param>
207+
/// <param name="t">The string to seek.</param>
208+
/// <param name="startIndex">The search starting position.</param>
209+
/// <param name="comparer">The specified <see cref="IEqualityComparer{T}"/> instance.</param>
210+
/// <returns>
211+
/// The zero-based index position of value if <paramref name="t"/> is found, or -1 if it is not.
212+
/// If <paramref name="t"/> is empty, the return value is 0.
213+
/// </returns>
214+
/// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception>
215+
/// <exception cref="ArgumentOutOfRangeException">
216+
/// <paramref name="startIndex"/> is less than zero.
217+
/// </exception>
218+
public static int IndexOf(this IEnumerable<char> s, string t, int startIndex, IEqualityComparer<char> comparer)
219+
{
220+
Validate(s, t, startIndex);
221+
222+
return s.IndexOf(t.AsReadOnlyList(), startIndex, comparer);
223+
}
224+
225+
#endregion
226+
147227
#region Others
148228

149229
internal static int IndexOf<T>(this IEnumerable<T> s, T t, int startIndex, IEqualityComparer<T> comparer)
@@ -179,7 +259,7 @@ internal static IEnumerator<T> Skip<T>(IEnumerator<T> enumerator, int count)
179259
return enumerator;
180260
}
181261

182-
internal static void Validate<T>(IEnumerable<T> s, IReadOnlyList<T> t, int startIndex)
262+
internal static void Validate<T>(IEnumerable<T> s, IEnumerable<T> t, int startIndex)
183263
{
184264
if (s == null) throw new ArgumentNullException(nameof(s));
185265
if (t == null) throw new ArgumentNullException(nameof(t));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /