[DatFile] Clean empty keys in a saner way

This commit is contained in:
Matt Nadareski
2017-12-21 15:59:42 -08:00
parent 6478e15605
commit 417aafe746

View File

@@ -1435,12 +1435,6 @@ namespace SabreTools.Library.DatFiles
i--; // This make sure that the pointer stays on the correct since one was removed
}
}
// Now remove the old key (if different than the current key)
if (!currentkey)
{
Remove(key);
}
}
}
@@ -1472,6 +1466,9 @@ namespace SabreTools.Library.DatFiles
AddRange(key, sortedlist);
});
}
// Now clean up all empty keys
CleanEmptyKeys();
}
/// <summary>
@@ -1558,6 +1555,21 @@ namespace SabreTools.Library.DatFiles
return key;
}
/// <summary>
/// Clean out all empty keys in the dictionary
/// </summary>
private void CleanEmptyKeys()
{
List<string> keys = Keys;
foreach(string key in keys)
{
if (this[key].Count == 0)
{
Remove(key);
}
}
}
#endregion
#region Constructors