You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.5 KiB
78 lines
2.5 KiB
using MultiTerm.Core.ViewModel;
|
|
using System.Text;
|
|
|
|
namespace MultiTerm.Core.Helpers;
|
|
|
|
public static class ByteDataViewModelHelpers
|
|
{
|
|
public static string GetCharacterStringOfBytesDataViewModels(IEnumerable<ByteDataViewModel> collection)
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
int prevLineIdentifier = collection.First().LineIdentifier;
|
|
|
|
foreach (var item in collection)
|
|
{
|
|
// add newline if line identifier increased
|
|
if(item.LineIdentifier > prevLineIdentifier)
|
|
{
|
|
stringBuilder.Append(Environment.NewLine);
|
|
}
|
|
prevLineIdentifier = item.LineIdentifier;
|
|
// add item as character
|
|
stringBuilder.Append(item.DisplayStringChar);
|
|
}
|
|
return stringBuilder.ToString();
|
|
}
|
|
|
|
public static string GetHexadecimalStringOfBytesDataViewModels(IEnumerable<ByteDataViewModel> collection)
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
int prevLineIdentifier = collection.First().LineIdentifier;
|
|
|
|
foreach (var item in collection)
|
|
{
|
|
// add newline if line identifier increased
|
|
if (item.LineIdentifier > prevLineIdentifier)
|
|
{
|
|
stringBuilder.Append(Environment.NewLine);
|
|
}
|
|
prevLineIdentifier = item.LineIdentifier;
|
|
|
|
// add item as hex byte
|
|
stringBuilder.Append(item.DisplayStringHex);
|
|
|
|
// add spacing if it is not the last item
|
|
if (item != collection.Last())
|
|
{
|
|
stringBuilder.Append(' ');
|
|
}
|
|
}
|
|
return stringBuilder.ToString();
|
|
}
|
|
|
|
public static string GetBinaryStringOfEBytesDataViewModels(IEnumerable<ByteDataViewModel> collection)
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
int prevLineIdentifier = collection.First().LineIdentifier;
|
|
|
|
foreach (var item in collection)
|
|
{
|
|
// add newline if line identifier increased
|
|
if (item.LineIdentifier > prevLineIdentifier)
|
|
{
|
|
stringBuilder.Append(Environment.NewLine);
|
|
}
|
|
prevLineIdentifier = item.LineIdentifier;
|
|
|
|
// add item as binary byte
|
|
stringBuilder.Append(item.DisplayStringBin);
|
|
|
|
// add spacing if it is not the last item
|
|
if (item != collection.Last())
|
|
{
|
|
stringBuilder.Append(' ');
|
|
}
|
|
}
|
|
return stringBuilder.ToString();
|
|
}
|
|
}
|
|
|