@@ -144,6 +144,86 @@ public static int IndexOf<T>(this IEnumerable<T> s, IReadOnlyList<T> t, int star
144
144
145
145
#endregion
146
146
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
+
147
227
#region Others
148
228
149
229
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)
179
259
return enumerator ;
180
260
}
181
261
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 )
183
263
{
184
264
if ( s == null ) throw new ArgumentNullException ( nameof ( s ) ) ;
185
265
if ( t == null ) throw new ArgumentNullException ( nameof ( t ) ) ;
0 commit comments