Skip to content

Commit

Permalink
Renamed EndianExtensions to NumberExtensions, included SNBT-related m…
Browse files Browse the repository at this point in the history
…ethods.

The Tag class no longer used Regex to identify if a name needs quoted or not.
  • Loading branch information
ForeverZer0 committed Aug 27, 2023
1 parent 95af348 commit 5d974ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 10 additions & 1 deletion SharpNBT/EndianExtensions.cs → SharpNBT/NumberExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SharpNBT;
/// Contains extension methods dealing with endianness of numeric types.
/// </summary>
[PublicAPI]
public static class EndianExtensions
public static class NumberExtensions
{
/// <summary>
/// Swap the endian of the given <paramref name="value"/>.
Expand Down Expand Up @@ -71,4 +71,13 @@ public static double SwapEndian(this double value)
var n = BitConverter.DoubleToInt64Bits(value);
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';
}
}
11 changes: 1 addition & 10 deletions SharpNBT/SNBT/StringNbt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static string ParseUnquotedString(ref Scanner scanner)
var start = scanner.Position;
for (var length = 0; scanner.MoveNext(false, true); length++)
{
if (AllowedInUnquoted(scanner.Current))
if (scanner.Current.IsValidUnquoted())
continue;

// Step back one character so not to consume the one that failed the permission check.
Expand Down Expand Up @@ -365,15 +365,6 @@ private static T[] ParseArrayValues<T>(ref Scanner scanner) where T : INumber<T>
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 static readonly char[] SplitSeparators = new[] { ',', 'b', 'B', 'l', 'L' };
}

0 comments on commit 5d974ee

Please sign in to comment.