|
3 | 3 |
|
4 | 4 | namespace AlgorithmForce.Searching
|
5 | 5 | {
|
| 6 | + /// <summary> |
| 7 | + /// Provides a set of extensions for searching specified collection in another collection. |
| 8 | + /// </summary> |
6 | 9 | public static class Extensions
|
7 | 10 | {
|
8 | 11 | #region IReadOnlyList(T) (IndexOf)
|
@@ -69,21 +72,71 @@ public static int IndexOf<T>(this IReadOnlyList<T> s, IReadOnlyList<T> t, int st
|
69 | 72 |
|
70 | 73 | #region String (IndexOf)
|
71 | 74 |
|
| 75 | + /// <summary> |
| 76 | + /// Reports the zero-based index of the first occurrence of the specified character collection in this instance. |
| 77 | + /// </summary> |
| 78 | + /// <param name="s">The string instance.</param> |
| 79 | + /// <param name="t">The character collection to seek.</param> |
| 80 | + /// <returns> |
| 81 | + /// The zero-based index position of value if that string is found, or -1 if it is not. |
| 82 | + /// If <see cref="t"/> is empty, the return value is 0. |
| 83 | + /// </returns> |
| 84 | + /// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception> |
72 | 85 | public static int IndexOf(this string s, IReadOnlyList<char> t)
|
73 | 86 | {
|
74 | 87 | return s.AsReadOnlyList().IndexOf(t, 0, EqualityComparer<char>.Default);
|
75 | 88 | }
|
76 | 89 |
|
| 90 | + /// <summary> |
| 91 | + /// Reports the zero-based index of the first occurrence of the specified character collection in this instance |
| 92 | + /// and uses the specified <see cref="IEqualityComparer{Char}"/>. |
| 93 | + /// </summary> |
| 94 | + /// <param name="s">The string instance.</param> |
| 95 | + /// <param name="t">The character collection to seek.</param> |
| 96 | + /// <param name="comparer">The specified <see cref="IEqualityComparer{Char}"/> instance.</param> |
| 97 | + /// <returns> |
| 98 | + /// The zero-based index position of value if that string is found, or -1 if it is not. |
| 99 | + /// If <see cref="t"/> is empty, the return value is 0. |
| 100 | + /// </returns> |
| 101 | + /// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception> |
77 | 102 | public static int IndexOf(this string s, IReadOnlyList<char> t, EqualityComparer<char> comparer)
|
78 | 103 | {
|
79 | 104 | return s.AsReadOnlyList().IndexOf(t, 0, comparer);
|
80 | 105 | }
|
81 | 106 |
|
| 107 | + /// <summary> |
| 108 | + /// Reports the zero-based index of the first occurrence of the specified character collection in this instance. |
| 109 | + /// The search starts at a specified character position. |
| 110 | + /// </summary> |
| 111 | + /// <param name="s">The string instance.</param> |
| 112 | + /// <param name="t">The character collection to seek.</param> |
| 113 | + /// <param name="startIndex">The search starting position.</param> |
| 114 | + /// <returns> |
| 115 | + /// The zero-based index position of value if that string is found, or -1 if it is not. |
| 116 | + /// If <see cref="t"/> is empty, the return value is 0. |
| 117 | + /// </returns> |
| 118 | + /// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception> |
| 119 | + /// <exception cref="ArgumentOutOfRangeException"><paramref name="startIndex"/> is less than 0 or greater than the length of this string.</exception> |
82 | 120 | public static int IndexOf(this string s, IReadOnlyList<char> t, int startIndex)
|
83 | 121 | {
|
84 | 122 | return s.AsReadOnlyList().IndexOf(t, startIndex, EqualityComparer<char>.Default);
|
85 | 123 | }
|
86 | 124 |
|
| 125 | + /// <summary> |
| 126 | + /// Reports the zero-based index of the first occurrence of the specified character collection in this instance |
| 127 | + /// and uses the specified <see cref="IEqualityComparer{Char}"/>. |
| 128 | + /// The search starts at a specified character position. |
| 129 | + /// </summary> |
| 130 | + /// <param name="s">The string instance.</param> |
| 131 | + /// <param name="t">The character collection to seek.</param> |
| 132 | + /// <param name="startIndex">The search starting position.</param> |
| 133 | + /// <param name="comparer">The specified <see cref="IEqualityComparer{Char}"/> instance.</param> |
| 134 | + /// <returns> |
| 135 | + /// The zero-based index position of value if that string is found, or -1 if it is not. |
| 136 | + /// If <see cref="t"/> is empty, the return value is 0. |
| 137 | + /// </returns> |
| 138 | + /// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception> |
| 139 | + /// <exception cref="ArgumentOutOfRangeException"><paramref name="startIndex"/> is less than 0 or greater than the length of this string.</exception> |
87 | 140 | public static int IndexOf(this string s, IReadOnlyList<char> t, int startIndex, EqualityComparer<char> comparer)
|
88 | 141 | {
|
89 | 142 | return s.AsReadOnlyList().IndexOf(t, startIndex, comparer);
|
@@ -155,21 +208,72 @@ public static int LastIndexOf<T>(this IReadOnlyList<T> s, IReadOnlyList<T> t, in
|
155 | 208 |
|
156 | 209 | #region String (LastIndexOf)
|
157 | 210 |
|
| 211 | + /// <summary> |
| 212 | + /// Reports the zero-based index of the first occurrence of the specified character collection in this instance. |
| 213 | + /// </summary> |
| 214 | + /// <param name="s">The string instance.</param> |
| 215 | + /// <param name="t">The character collection to seek.</param> |
| 216 | + /// <returns> |
| 217 | + /// The zero-based index position of value if that string is found, or -1 if it is not. |
| 218 | + /// If <see cref="t"/> is empty, the return value is the last index position in this instance. |
| 219 | + /// </returns> |
| 220 | + /// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception> |
158 | 221 | public static int LastIndexOf(this string s, IReadOnlyList<char> t)
|
159 | 222 | {
|
160 | 223 | return s.AsReadOnlyList().LastIndexOf(t, s == null ? -1 : s.Length - 1, EqualityComparer<char>.Default);
|
161 | 224 | }
|
162 | 225 |
|
| 226 | + /// <summary> |
| 227 | + /// Reports the zero-based index of the first occurrence of the specified character collection in this instance |
| 228 | + /// and uses the specified <see cref="IEqualityComparer{Char}"/>. |
| 229 | + /// </summary> |
| 230 | + /// <param name="s">The string instance.</param> |
| 231 | + /// <param name="t">The character collection to seek.</param> |
| 232 | + /// <param name="comparer">The specified <see cref="IEqualityComparer{Char}"/> instance.</param> |
| 233 | + /// <returns> |
| 234 | + /// The zero-based index position of value if that string is found, or -1 if it is not. |
| 235 | + /// If <see cref="t"/> is empty, the return value is the last index position in this instance. |
| 236 | + /// </returns> |
| 237 | + /// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception> |
163 | 238 | public static int LastIndexOf(this string s, IReadOnlyList<char> t, EqualityComparer<char> comparer)
|
164 | 239 | {
|
165 | 240 | return s.AsReadOnlyList().LastIndexOf(t, s == null ? -1 : s.Length - 1, comparer);
|
166 | 241 | }
|
167 | 242 |
|
| 243 | + /// <summary> |
| 244 | + /// Reports the zero-based index of the first occurrence of the specified character collection in this instance. |
| 245 | + /// The search starts at a specified character position. |
| 246 | + /// </summary> |
| 247 | + /// <param name="s">The string instance.</param> |
| 248 | + /// <param name="t">The character collection to seek.</param> |
| 249 | + /// <param name="startIndex">The search starting position.</param> |
| 250 | + /// <returns> |
| 251 | + /// The zero-based index position of value if that string is found, or -1 if it is not. |
| 252 | + /// If <see cref="t"/> is empty, the return value is the last index position in this instance. |
| 253 | + /// </returns> |
| 254 | + /// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception> |
| 255 | + /// <exception cref="ArgumentOutOfRangeException"><paramref name="startIndex"/> is less than 0 or greater than the length of this string.</exception> |
168 | 256 | public static int LastIndexOf(this string s, IReadOnlyList<char> t, int startIndex)
|
169 | 257 | {
|
170 | 258 | return s.AsReadOnlyList().LastIndexOf(t, startIndex, EqualityComparer<char>.Default);
|
171 | 259 | }
|
172 | 260 |
|
| 261 | + |
| 262 | + /// <summary> |
| 263 | + /// Reports the zero-based index of the first occurrence of the specified character collection in this instance |
| 264 | + /// and uses the specified <see cref="IEqualityComparer{Char}"/>. |
| 265 | + /// The search starts at a specified character position. |
| 266 | + /// </summary> |
| 267 | + /// <param name="s">The string instance.</param> |
| 268 | + /// <param name="t">The character collection to seek.</param> |
| 269 | + /// <param name="startIndex">The search starting position.</param> |
| 270 | + /// <param name="comparer">The specified <see cref="IEqualityComparer{Char}"/> instance.</param> |
| 271 | + /// <returns> |
| 272 | + /// The zero-based index position of value if that string is found, or -1 if it is not. |
| 273 | + /// If <see cref="t"/> is empty, the return value is the last index position in this instance. |
| 274 | + /// </returns> |
| 275 | + /// <exception cref="ArgumentNullException"><paramref name="s"/> or <paramref name="t"/> is null.</exception> |
| 276 | + /// <exception cref="ArgumentOutOfRangeException"><paramref name="startIndex"/> is less than 0 or greater than the length of this string.</exception> |
173 | 277 | public static int LastIndexOf(this string s, IReadOnlyList<char> t, int startIndex, EqualityComparer<char> comparer)
|
174 | 278 | {
|
175 | 279 | return s.AsReadOnlyList().LastIndexOf(t, startIndex, comparer);
|
|
0 commit comments