function to get the zero-based offset of a particular String in a list of strings with optional padding after each item (e.g. 1 for null terminator)

This commit is contained in:
Michael Becker 2019-11-17 02:42:56 -05:00
parent b6f6865e7a
commit 9064e144f0
No known key found for this signature in database
GPG Key ID: 389DFF5D73781A12

View File

@ -27,6 +27,16 @@ namespace UniversalEditor
{
public static class ExtensionMethods
{
public static long GetItemOffset(this List<string> list, int index, int additionalPadding = 0)
{
long offset = 0;
for (int i = 0; i < index; i++)
{
offset += list[i].Length + additionalPadding;
}
return offset;
}
public static bool get_EndOfStream(this System.IO.Stream stream)
{
return (stream.Position == stream.Length);