Skip to content

Commit 4ccd805

Browse files
committed
Fixed FindFirst/FindLast
1 parent 79f9e7c commit 4ccd805

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/LinkDotNet.StringBuilder/NaiveSearch.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public static int FindFirst(ReadOnlySpan<char> text, ReadOnlySpan<char> word)
5959
return -1;
6060
}
6161

62-
var index = -1;
63-
6462
for (var i = 0; i <= text.Length - word.Length; i++)
6563
{
6664
for (var j = 0; j < word.Length; j++)
@@ -72,12 +70,12 @@ public static int FindFirst(ReadOnlySpan<char> text, ReadOnlySpan<char> word)
7270

7371
if (j == word.Length - 1)
7472
{
75-
return index;
73+
return i;
7674
}
7775
}
7876
}
7977

80-
return index;
78+
return -1;
8179
}
8280

8381
/// <summary>
@@ -98,8 +96,6 @@ public static int FindLast(ReadOnlySpan<char> text, ReadOnlySpan<char> word)
9896
return -1;
9997
}
10098

101-
var index = -1;
102-
10399
for (var i = text.Length - word.Length + 1; i >= 0; i--)
104100
{
105101
for (var j = 0; j < word.Length; j++)
@@ -111,11 +107,11 @@ public static int FindLast(ReadOnlySpan<char> text, ReadOnlySpan<char> word)
111107

112108
if (j == word.Length - 1)
113109
{
114-
return index;
110+
return i;
115111
}
116112
}
117113
}
118114

119-
return index;
115+
return -1;
120116
}
121117
}

0 commit comments

Comments
 (0)