fixed bug with Stringify giving ToString output
This commit is contained in:
parent
f22ae236b6
commit
82399f243b
|
@ -0,0 +1 @@
|
|||
../README.md
|
|
@ -13,11 +13,13 @@
|
|||
<PackageTags>nbt;named binary tag;minecraft;serialization;java;bedrock;pocket edition;varint;varlong;zlib</PackageTags>
|
||||
<Copyright>Copyright © Eric Freed 2021</Copyright>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageVersion>1.2.0</PackageVersion>
|
||||
<AssemblyVersion>1.2.0</AssemblyVersion>
|
||||
<FileVersion>1.2.0</FileVersion>
|
||||
<PackageVersion>1.3.1</PackageVersion>
|
||||
<AssemblyVersion>1.3.1</AssemblyVersion>
|
||||
<FileVersion>1.3.1</FileVersion>
|
||||
<LangVersion>latestmajor</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<PackageReleaseNotes>Hotfix to correct bug with Stringified output.</PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
|
@ -25,6 +27,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="README.md" Pack="true" Visible="true" PackagePath="/"/>
|
||||
<None Include="icon.png" Pack="true" Visible="true" PackagePath="" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -82,10 +82,12 @@ public abstract class ArrayTag<T> : Tag, IReadOnlyList<T> where T : unmanaged, I
|
|||
/// <returns>A reference to the first value in the underlying array.</returns>
|
||||
public ref T GetPinnableReference() => ref array[0] ;
|
||||
|
||||
private protected string Stringify(char prefix, char? suffix)
|
||||
private protected string Stringify(bool named, char prefix, char? suffix)
|
||||
{
|
||||
var sb = new StringBuilder(32 + array.Length * 4);
|
||||
sb.Append($"{StringifyName}:[{prefix};");
|
||||
if (named)
|
||||
sb.Append($"{StringifyName}:");
|
||||
sb.Append($"[{prefix};");
|
||||
|
||||
for (var i = 0; i < array.Length; i++)
|
||||
{
|
||||
|
|
|
@ -50,11 +50,11 @@ public class BoolTag : Tag
|
|||
/// <returns>The tag represented as a <see cref="byte"/>.</returns>
|
||||
public static implicit operator bool(BoolTag tag) => tag.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => $"{StringifyName}:{(Value ? "true" : "false")}";
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true)
|
||||
{
|
||||
var value = Value ? "true" : "false";
|
||||
return named ? $"{StringifyName}:{value}" : value;
|
||||
}
|
||||
|
||||
}
|
|
@ -76,10 +76,6 @@ public class ByteArrayTag : ArrayTag<byte>
|
|||
return $"TAG_Byte_Array({PrettyName}): [{Count} {word}]";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => Stringify('B', 'b');
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true) => Stringify(named, 'B', 'b');
|
||||
}
|
|
@ -132,10 +132,6 @@ public class ByteTag : NumericTag<byte>
|
|||
[CLSCompliant(false)]
|
||||
public static implicit operator sbyte(ByteTag tag) => unchecked((sbyte)tag.Value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => $"{StringifyName}:{Value}B";
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true) => named ? $"{StringifyName}:{Value}B" : $"{Value}B";
|
||||
}
|
|
@ -242,22 +242,20 @@ public class CompoundTag : Tag, IDictionary<string, Tag>, ICollection<Tag>
|
|||
buffer.AppendLine(space + "}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify()
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append($"{StringifyName}:{{");
|
||||
if (named)
|
||||
sb.Append($"{StringifyName}:");
|
||||
sb.Append('{');
|
||||
|
||||
var i = 0;
|
||||
foreach (var value in dict.Values)
|
||||
{
|
||||
if (i++ > 0)
|
||||
sb.Append(',');
|
||||
sb.Append(value);
|
||||
sb.Append(value.Stringify(true));
|
||||
}
|
||||
sb.Append('}');
|
||||
return sb.ToString();
|
||||
|
@ -267,11 +265,12 @@ public class CompoundTag : Tag, IDictionary<string, Tag>, ICollection<Tag>
|
|||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <param name="topLevel">Flag indicating if this is the top-level tag that should be wrapped in braces.</param>
|
||||
/// <param name="named">Flag indicating if the name of the NBT should be written.</param>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public string Stringify(bool topLevel)
|
||||
public string Stringify(bool topLevel, bool named)
|
||||
{
|
||||
var str = Stringify();
|
||||
var str = Stringify(named);
|
||||
return topLevel ? $"{{{str}}}" : str;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,10 +41,6 @@ public class DoubleTag : NumericTag<double>
|
|||
/// <returns>The tag represented as a <see cref="double"/>.</returns>
|
||||
public static implicit operator double(DoubleTag tag) => tag.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => $"{StringifyName}:{Value:0.0}D";
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true) => named ? $"{StringifyName}:{Value}D" : $"{Value}D";
|
||||
}
|
|
@ -32,10 +32,6 @@ public sealed class EndTag : Tag
|
|||
// Do nothing
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => string.Empty;
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true) => string.Empty;
|
||||
}
|
|
@ -41,10 +41,6 @@ public class FloatTag : NumericTag<float>
|
|||
/// <returns>The tag represented as a <see cref="float"/>.</returns>
|
||||
public static implicit operator float(FloatTag tag) => tag.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => $"{StringifyName}:{Value:0.0}F";
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true) => named ? $"{StringifyName}:{Value}F" : $"{Value}F";
|
||||
}
|
|
@ -74,10 +74,6 @@ public class IntArrayTag : ArrayTag<int>
|
|||
return $"TAG_Int_Array({PrettyName}): [{Count} {word}]";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => Stringify('I', null);
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true) => Stringify(named, 'I', null);
|
||||
}
|
|
@ -69,10 +69,6 @@ public class IntTag : NumericTag<int>
|
|||
[CLSCompliant(false)]
|
||||
public static implicit operator uint(IntTag tag) => unchecked((uint)tag.Value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => $"{StringifyName}:{Value}";
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true) => named ? $"{StringifyName}:{Value}" : $"{Value}";
|
||||
}
|
|
@ -175,15 +175,21 @@ public class ListTag : Tag, IList<Tag>
|
|||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify()
|
||||
public override string Stringify(bool named = true)
|
||||
{
|
||||
var strings = new string[Count];
|
||||
for (var i = 0; i < strings.Length; i++)
|
||||
strings[i] = this[i].Stringify();
|
||||
var sb = new StringBuilder();
|
||||
if (named)
|
||||
sb.Append($"{StringifyName}:");
|
||||
|
||||
// TODO: Use StringBuilder
|
||||
|
||||
return $"{StringifyName}:[{string.Join(',', strings)}]";
|
||||
sb.Append('[');
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
sb.Append(',');
|
||||
sb.Append(list[i].Stringify(false));
|
||||
}
|
||||
sb.Append(']');
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
|
|
@ -71,10 +71,6 @@ public class LongArrayTag : ArrayTag<long>
|
|||
return $"TAG_Long_Array({PrettyName}): [{Count} {word}]";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => Stringify('L', 'l');
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true) => Stringify(named, 'L', 'l');
|
||||
}
|
|
@ -69,10 +69,6 @@ public class LongTag : NumericTag<long>
|
|||
[CLSCompliant(false)]
|
||||
public static implicit operator ulong(LongTag tag) => unchecked((ulong)tag.Value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => $"{StringifyName}:{Value}L";
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true) => named ? $"{StringifyName}:{Value}L" : $"{Value}L";
|
||||
}
|
|
@ -75,10 +75,6 @@ public class ShortTag : NumericTag<short>
|
|||
[CLSCompliant(false)]
|
||||
public static implicit operator ushort(ShortTag tag) => unchecked((ushort)tag.Value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => $"{StringifyName}:{Value}S";
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true) => named ? $"{StringifyName}:{Value}S" : $"{Value}S";
|
||||
}
|
|
@ -48,12 +48,11 @@ public class StringTag : Tag, IEquatable<StringTag>
|
|||
/// <returns>The tag represented as a <see cref="string"/>.</returns>
|
||||
public static implicit operator string(StringTag tag) => tag.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public override string Stringify() => $"{StringifyName}:\"{Value}\""; // TODO: Does this get properly escaped?
|
||||
/// <inheritdoc />
|
||||
public override string Stringify(bool named = true)
|
||||
{
|
||||
return named ? $"{StringifyName}:\"{Value}\"" : $"\"{Value}\"";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(StringTag? other)
|
||||
|
|
|
@ -212,9 +212,10 @@ public abstract class Tag : IEquatable<Tag>, ICloneable
|
|||
/// <summary>
|
||||
/// Gets the <i>string</i> representation of this NBT tag (SNBT).
|
||||
/// </summary>
|
||||
/// <param name="named">Flag indicating if the name of the tag should be written.</param>
|
||||
/// <returns>This NBT tag in SNBT format.</returns>
|
||||
/// <seealso href="https://minecraft.fandom.com/wiki/NBT_format#SNBT_format"/>
|
||||
public abstract string Stringify();
|
||||
public abstract string Stringify(bool named = true);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name in a formatted properly for SNBT.
|
||||
|
|
Loading…
Reference in New Issue