mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Move ClearEmpty to DatFile
This commit is contained in:
@@ -128,6 +128,15 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <summary>
|
||||
/// Remove any keys that have null or empty values
|
||||
/// </summary>
|
||||
public void ClearEmpty()
|
||||
{
|
||||
ClearEmptyImpl();
|
||||
ClearEmptyImplDB();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the internal header
|
||||
/// </summary>
|
||||
@@ -138,6 +147,42 @@ namespace SabreTools.DatFiles
|
||||
Header = datHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove any keys that have null or empty values
|
||||
/// </summary>
|
||||
private void ClearEmptyImpl()
|
||||
{
|
||||
foreach (string key in Items.SortedKeys)
|
||||
{
|
||||
// If the value is empty, remove
|
||||
List<DatItem> value = GetItemsForBucket(key);
|
||||
if (value.Count == 0)
|
||||
RemoveBucket(key);
|
||||
|
||||
// If there are no non-blank items, remove
|
||||
else if (value.FindIndex(i => i != null && i is not Blank) == -1)
|
||||
RemoveBucket(key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove any keys that have null or empty values
|
||||
/// </summary>
|
||||
private void ClearEmptyImplDB()
|
||||
{
|
||||
foreach (string key in ItemsDB.SortedKeys)
|
||||
{
|
||||
// If the value is empty, remove
|
||||
List<DatItem> value = [.. GetItemsForBucketDB(key).Values];
|
||||
if (value.Count == 0)
|
||||
RemoveBucketDB(key);
|
||||
|
||||
// If there are no non-blank items, remove
|
||||
else if (value.FindIndex(i => i != null && i is not Blank) == -1)
|
||||
RemoveBucketDB(key);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Item Dictionary Passthrough - Accessors
|
||||
@@ -182,15 +227,6 @@ namespace SabreTools.DatFiles
|
||||
return ItemsDB.AddSource(source);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove any keys that have null or empty values
|
||||
/// </summary>
|
||||
public void ClearEmpty()
|
||||
{
|
||||
Items.ClearEmpty();
|
||||
ItemsDB.ClearEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all items marked for removal
|
||||
/// </summary>
|
||||
@@ -227,6 +263,15 @@ namespace SabreTools.DatFiles
|
||||
return Items.RemoveBucket(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a key from the file dictionary if it exists
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to remove</param>
|
||||
public bool RemoveBucketDB(string key)
|
||||
{
|
||||
return ItemsDB.RemoveBucket(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the first instance of a value from the file dictionary if it exists
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user