Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit feb1755

Browse files
committed
Tweak IndexOfAny
1 parent ffcc74d commit feb1755

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/ServiceStack.Text/StringExtensions.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,17 @@ public static int IndexOfAny(this string text, params string[] needles)
473473

474474
public static int IndexOfAny(this string text, int startIndex, params string[] needles)
475475
{
476-
if (text == null) return -1;
477-
478476
var firstPos = -1;
479-
foreach (var needle in needles)
477+
if (text != null)
480478
{
481-
var pos = text.IndexOf(needle);
482-
if (firstPos == -1 || pos < firstPos) firstPos = pos;
479+
foreach (var needle in needles)
480+
{
481+
var pos = text.IndexOf(needle, startIndex);
482+
if (firstPos == -1 || pos < firstPos)
483+
firstPos = pos;
484+
}
483485
}
486+
484487
return firstPos;
485488
}
486489

tests/ServiceStack.Text.Tests/StringExtensionsTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public void Does_find_IndexOfAny_strings()
8686
{
8787
var text = "text with /* and <!--";
8888
var pos = text.IndexOfAny("<!--", "/*");
89-
//Console.WriteLine(text.Substring(pos));
9089
Assert.That(pos, Is.EqualTo("text with ".Length));
9190
}
9291

0 commit comments

Comments
 (0)