Renamed EndianExtensions to NumberExtensions, included SNBT-related methods.

The Tag class no longer used Regex to identify if a name needs quoted or not.
This commit is contained in:
Eric Freed 2023-08-27 15:25:50 -04:00
parent 95af348ddc
commit 5d974eeeb4
2 changed files with 11 additions and 11 deletions

View File

@ -8,7 +8,7 @@ namespace SharpNBT;
/// Contains extension methods dealing with endianness of numeric types. /// Contains extension methods dealing with endianness of numeric types.
/// </summary> /// </summary>
[PublicAPI] [PublicAPI]
public static class EndianExtensions public static class NumberExtensions
{ {
/// <summary> /// <summary>
/// Swap the endian of the given <paramref name="value"/>. /// Swap the endian of the given <paramref name="value"/>.
@ -71,4 +71,13 @@ public static class EndianExtensions
var n = BitConverter.DoubleToInt64Bits(value); var n = BitConverter.DoubleToInt64Bits(value);
return BitConverter.Int64BitsToDouble(n.SwapEndian()); return BitConverter.Int64BitsToDouble(n.SwapEndian());
} }
public static bool IsValidUnquoted(this char c)
{
return c == '_' || c == '-' ||
c == '.' || c == '+' ||
c >= '0' && c <= '9' ||
c >= 'A' && c <= 'Z' ||
c >= 'a' && c <= 'z';
}
} }

View File

@ -175,7 +175,7 @@ public static class StringNbt
var start = scanner.Position; var start = scanner.Position;
for (var length = 0; scanner.MoveNext(false, true); length++) for (var length = 0; scanner.MoveNext(false, true); length++)
{ {
if (AllowedInUnquoted(scanner.Current)) if (scanner.Current.IsValidUnquoted())
continue; continue;
// Step back one character so not to consume the one that failed the permission check. // Step back one character so not to consume the one that failed the permission check.
@ -365,15 +365,6 @@ public static class StringNbt
return values; return values;
} }
private static bool AllowedInUnquoted(char c)
{
return c == '_' || c == '-' ||
c == '.' || c == '+' ||
c >= '0' && c <= '9' ||
c >= 'A' && c <= 'Z' ||
c >= 'a' && c <= 'z';
}
private const StringSplitOptions SplitOpts = StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries; private const StringSplitOptions SplitOpts = StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries;
private static readonly char[] SplitSeparators = new[] { ',', 'b', 'B', 'l', 'L' }; private static readonly char[] SplitSeparators = new[] { ',', 'b', 'B', 'l', 'L' };
} }