73 lines
No EOL
1.9 KiB
C#
73 lines
No EOL
1.9 KiB
C#
using System;
|
|
using LibAC.NBT.API;
|
|
|
|
namespace LibAC.NBT
|
|
{
|
|
public class StringTag : Tag
|
|
{
|
|
public string value { get; private set; } = "";
|
|
|
|
public StringTag() { }
|
|
|
|
public StringTag(string str)
|
|
{
|
|
value = str;
|
|
}
|
|
|
|
public static StringTag ValueOf(string str)
|
|
{
|
|
return new StringTag(str);
|
|
}
|
|
|
|
public override void ReadValue(ByteLayer data)
|
|
{
|
|
value = data.ReadString();
|
|
}
|
|
|
|
public override void WriteValue(ByteLayer data)
|
|
{
|
|
data.WriteString(value);
|
|
}
|
|
|
|
public override TagType GetTagType()
|
|
{
|
|
return TagType.String;
|
|
}
|
|
|
|
public override void SetValue(dynamic val)
|
|
{
|
|
if (val is string) value = val;
|
|
}
|
|
|
|
public override dynamic GetValue()
|
|
{
|
|
return value;
|
|
}
|
|
|
|
public override void PrettyPrint(int indent, bool recurse)
|
|
{
|
|
Console.WriteLine($"{new string('\t', indent)}{Tag.GetCanonicalName(GetTagType())}: {value}");
|
|
}
|
|
|
|
public override void WriteStringifiedValue(StringBuilder builder, int indent, bool isList)
|
|
{
|
|
if (ShouldQuote(value))
|
|
builder.Append($"{(isList ? new string('\t', indent) : "")}\"{value}\"");
|
|
else
|
|
builder.Append($"{(isList ? new string('\t', indent) : "")}{value}");
|
|
}
|
|
|
|
public override void ReadStringifiedValue(StringReader reader)
|
|
{
|
|
string str = reader.ReadString();
|
|
value = str;
|
|
}
|
|
|
|
// This method will need to be implemented for checking if a string should be quoted
|
|
private bool ShouldQuote(string str)
|
|
{
|
|
// Implement logic for determining if the string needs to be quoted
|
|
return false;
|
|
}
|
|
}
|
|
} |