Move ClearEmpty to DatFile

This commit is contained in:
Matt Nadareski
2025-01-14 22:07:05 -05:00
parent 7e2d094ba5
commit 3e839e1249
5 changed files with 136 additions and 102 deletions

View File

@@ -190,45 +190,10 @@ namespace SabreTools.DatFiles
return key;
}
/// <summary>
/// Remove any keys that have null or empty values
/// </summary>
internal void ClearEmpty()
{
foreach (string key in SortedKeys)
{
#if NET40_OR_GREATER || NETCOREAPP
// If the key doesn't exist, skip
if (!_items.TryGetValue(key, out var value))
continue;
// If the value is null, remove
else if (value == null)
_items.TryRemove(key, out _);
// If there are no non-blank items, remove
else if (value!.FindIndex(i => i != null && i is not Blank) == -1)
_items.TryRemove(key, out _);
#else
// If the key doesn't exist, skip
if (!_items.ContainsKey(key))
continue;
// If the value is null, remove
else if (_items[key] == null)
_items.Remove(key);
// If there are no non-blank items, remove
else if (_items[key]!.FindIndex(i => i != null && i is not Blank) == -1)
_items.Remove(key);
#endif
}
}
/// <summary>
/// Remove all items marked for removal
/// </summary>
internal void ClearMarked()
public void ClearMarked()
{
foreach (string key in SortedKeys)
{