servicepoint/crates/servicepoint_binding_cs/ServicePoint/Cp437Grid.cs

57 lines
1.2 KiB
C#
Raw Normal View History

using System.Text;
2024-05-13 00:17:40 +02:00
namespace ServicePoint;
2024-05-13 00:17:40 +02:00
public sealed partial class Cp437Grid
2024-05-13 00:17:40 +02:00
{
2024-10-19 16:04:01 +02:00
public static Cp437Grid Load(nuint width, nuint height, Span<byte> bytes)
{
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
{
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]
{
set
{
var width = Width();
2024-10-16 22:46:34 +02:00
ArgumentOutOfRangeException.ThrowIfGreaterThan((nuint)value.Length, width);
2024-10-16 22:46:34 +02:00
nuint x = 0;
for (; x < (nuint)value.Length; x++)
this[x, y] = (byte)value[(int)x];
for (; x < width; x++)
this[x, y] = 0;
}
get
{
var sb = new StringBuilder();
var width = Width();
for (nuint x = 0; x < width; x++)
{
var val = this[x, y];
if (val == 0)
break;
sb.Append((char)val);
}
return sb.ToString();
}
}
public Span<byte> Data => UnsafeDataRef().AsSpan();
2024-05-13 00:17:40 +02:00
}