2024-05-13 01:26:44 +02:00
|
|
|
using System.Text;
|
2024-05-13 00:17:40 +02:00
|
|
|
|
2024-05-25 11:16:37 +02:00
|
|
|
namespace ServicePoint;
|
2024-05-13 00:17:40 +02:00
|
|
|
|
2024-10-19 14:21:50 +02:00
|
|
|
public sealed partial class Cp437Grid
|
2024-05-13 00:17:40 +02:00
|
|
|
{
|
2024-10-20 13:31:41 +02:00
|
|
|
public static Cp437Grid Load(nuint width, nuint height, ReadOnlySpan<byte> bytes)
|
2024-10-19 16:04:01 +02:00
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
|
|
|
fixed (byte* bytesPtr = bytes)
|
|
|
|
{
|
|
|
|
return Load(width, height, bytesPtr, (nuint)bytes.Length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-16 22:46:34 +02:00
|
|
|
public byte this[nuint x, nuint y]
|
2024-05-13 00:17:40 +02:00
|
|
|
{
|
2024-10-19 14:21:50 +02:00
|
|
|
get => Get(x, y);
|
|
|
|
set => Set(x, y, value);
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|
|
|
|
|
2024-10-16 22:46:34 +02:00
|
|
|
public string this[nuint y]
|
2024-05-13 01:26:44 +02:00
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2024-10-19 14:21:50 +02:00
|
|
|
var width = Width();
|
2024-10-16 22:46:34 +02:00
|
|
|
ArgumentOutOfRangeException.ThrowIfGreaterThan((nuint)value.Length, width);
|
2024-05-13 01:26:44 +02:00
|
|
|
|
2024-10-16 22:46:34 +02:00
|
|
|
nuint x = 0;
|
|
|
|
for (; x < (nuint)value.Length; x++)
|
|
|
|
this[x, y] = (byte)value[(int)x];
|
2024-05-13 01:26:44 +02:00
|
|
|
|
|
|
|
for (; x < width; x++)
|
|
|
|
this[x, y] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var sb = new StringBuilder();
|
2024-10-19 14:21:50 +02:00
|
|
|
var width = Width();
|
|
|
|
for (nuint x = 0; x < width; x++)
|
2024-05-13 01:26:44 +02:00
|
|
|
{
|
|
|
|
var val = this[x, y];
|
|
|
|
if (val == 0)
|
|
|
|
break;
|
|
|
|
sb.Append((char)val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-19 14:21:50 +02:00
|
|
|
public Span<byte> Data => UnsafeDataRef().AsSpan();
|
2024-05-13 00:17:40 +02:00
|
|
|
}
|