servicepoint/crates/servicepoint_binding_cs/ServicePoint/Cp437Grid.cs
2024-10-19 14:21:50 +02:00

46 lines
995 B
C#

using System.Text;
namespace ServicePoint;
public sealed partial class Cp437Grid
{
public byte this[nuint x, nuint y]
{
get => Get(x, y);
set => Set(x, y, value);
}
public string this[nuint y]
{
set
{
var width = Width();
ArgumentOutOfRangeException.ThrowIfGreaterThan((nuint)value.Length, width);
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();
}