From 9064e144f070fec41df6422f5bd11b158aa64084 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sun, 17 Nov 2019 02:42:56 -0500 Subject: [PATCH] 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) --- .../Libraries/UniversalEditor.Core/ExtensionMethods.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CSharp/Libraries/UniversalEditor.Core/ExtensionMethods.cs b/CSharp/Libraries/UniversalEditor.Core/ExtensionMethods.cs index 55e3166d..593d0171 100644 --- a/CSharp/Libraries/UniversalEditor.Core/ExtensionMethods.cs +++ b/CSharp/Libraries/UniversalEditor.Core/ExtensionMethods.cs @@ -27,6 +27,16 @@ namespace UniversalEditor { public static class ExtensionMethods { + public static long GetItemOffset(this List 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);