fix index-out-of-range error when StartsWith prefix is empty
This commit is contained in:
parent
eed1deb3c7
commit
4e3b2810e6
|
@ -139,21 +139,19 @@ namespace StardewModdingAPI.Framework.Content
|
||||||
if (prefix is null)
|
if (prefix is null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// get initial values
|
||||||
ReadOnlySpan<char> trimmed = prefix.AsSpan().Trim();
|
ReadOnlySpan<char> trimmed = prefix.AsSpan().Trim();
|
||||||
|
if (trimmed.Length == 0)
|
||||||
|
return true;
|
||||||
|
ReadOnlySpan<char> pathSeparators = new(ToolkitPathUtilities.PossiblePathSeparators); // just to simplify calling other span APIs
|
||||||
|
|
||||||
// just because most ReadOnlySpan/Span APIs expect a ReadOnlySpan/Span, easier to read.
|
// asset keys can't have a leading slash, but AssetPathYielder will trim them
|
||||||
ReadOnlySpan<char> pathSeparators = new(ToolkitPathUtilities.PossiblePathSeparators);
|
|
||||||
|
|
||||||
// asset keys can't have a leading slash, but AssetPathYielder won't yield that.
|
|
||||||
if (pathSeparators.Contains(trimmed[0]))
|
if (pathSeparators.Contains(trimmed[0]))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (trimmed.Length == 0)
|
// compare segments
|
||||||
return true;
|
|
||||||
|
|
||||||
AssetNamePartEnumerator curParts = new(this.Name);
|
AssetNamePartEnumerator curParts = new(this.Name);
|
||||||
AssetNamePartEnumerator prefixParts = new(trimmed);
|
AssetNamePartEnumerator prefixParts = new(trimmed);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
bool prefixHasMore = prefixParts.MoveNext();
|
bool prefixHasMore = prefixParts.MoveNext();
|
||||||
|
|
Loading…
Reference in New Issue