summaryrefslogtreecommitdiff
path: root/src/SMAPI/Utilities
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-11-12 15:15:56 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-11-12 15:15:56 -0500
commitb95d2a3f935dde0118205f94b32f05f115afdf71 (patch)
tree91dbfb80a2536dbd86bc1987805e874a90cb38f5 /src/SMAPI/Utilities
parent9ae69245b30f5cc6b52f1159a6e151079b699a10 (diff)
parent613946003d5a2a6ea7c13a4dca04bda4f2387957 (diff)
downloadSMAPI-b95d2a3f935dde0118205f94b32f05f115afdf71.tar.gz
SMAPI-b95d2a3f935dde0118205f94b32f05f115afdf71.tar.bz2
SMAPI-b95d2a3f935dde0118205f94b32f05f115afdf71.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Utilities')
-rw-r--r--src/SMAPI/Utilities/AssetPathUtilities/AssetNamePartEnumerator.cs70
-rw-r--r--src/SMAPI/Utilities/PerScreen.cs2
2 files changed, 71 insertions, 1 deletions
diff --git a/src/SMAPI/Utilities/AssetPathUtilities/AssetNamePartEnumerator.cs b/src/SMAPI/Utilities/AssetPathUtilities/AssetNamePartEnumerator.cs
new file mode 100644
index 00000000..11987ed6
--- /dev/null
+++ b/src/SMAPI/Utilities/AssetPathUtilities/AssetNamePartEnumerator.cs
@@ -0,0 +1,70 @@
+using System;
+using ToolkitPathUtilities = StardewModdingAPI.Toolkit.Utilities.PathUtilities;
+
+namespace StardewModdingAPI.Utilities.AssetPathUtilities
+{
+ /// <summary>Handles enumerating the normalized segments in an asset name.</summary>
+ internal ref struct AssetNamePartEnumerator
+ {
+ /*********
+ ** Fields
+ *********/
+ /// <summary>The backing field for <see cref="Remainder"/>.</summary>
+ private ReadOnlySpan<char> RemainderImpl;
+
+
+ /*********
+ ** Properties
+ *********/
+ /// <summary>The remainder of the asset name being enumerated, ignoring segments which have already been yielded.</summary>
+ public ReadOnlySpan<char> Remainder => this.RemainderImpl;
+
+ /// <summary>Get the current segment.</summary>
+ public ReadOnlySpan<char> Current { get; private set; } = default;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="assetName">The asset name to enumerate.</param>
+ public AssetNamePartEnumerator(ReadOnlySpan<char> assetName)
+ {
+ this.RemainderImpl = AssetNamePartEnumerator.TrimLeadingPathSeparators(assetName);
+ }
+
+ /// <summary>Move the enumerator to the next segment.</summary>
+ /// <returns>Returns true if a new value was found (accessible via <see cref="Current"/>).</returns>
+ public bool MoveNext()
+ {
+ if (this.RemainderImpl.Length == 0)
+ return false;
+
+ int index = this.RemainderImpl.IndexOfAny(ToolkitPathUtilities.PossiblePathSeparators);
+
+ // no more separator characters found, I'm done.
+ if (index < 0)
+ {
+ this.Current = this.RemainderImpl;
+ this.RemainderImpl = ReadOnlySpan<char>.Empty;
+ return true;
+ }
+
+ // Yield the next separate character bit
+ this.Current = this.RemainderImpl[..index];
+ this.RemainderImpl = AssetNamePartEnumerator.TrimLeadingPathSeparators(this.RemainderImpl[(index + 1)..]);
+ return true;
+ }
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>Trim path separators at the start of the given path or segment.</summary>
+ /// <param name="span">The path or segment to trim.</param>
+ private static ReadOnlySpan<char> TrimLeadingPathSeparators(ReadOnlySpan<char> span)
+ {
+ return span.TrimStart(new ReadOnlySpan<char>(ToolkitPathUtilities.PossiblePathSeparators));
+ }
+ }
+}
diff --git a/src/SMAPI/Utilities/PerScreen.cs b/src/SMAPI/Utilities/PerScreen.cs
index 468df0bd..87bf2027 100644
--- a/src/SMAPI/Utilities/PerScreen.cs
+++ b/src/SMAPI/Utilities/PerScreen.cs
@@ -59,7 +59,7 @@ namespace StardewModdingAPI.Utilities
null,
$"calling the {nameof(PerScreen<T>)} constructor with null",
"3.14.0",
- DeprecationLevel.Info
+ DeprecationLevel.PendingRemoval
);
#else
throw new ArgumentNullException(nameof(createNewState));