Fix negative number handling for snbt parsers
This commit is contained in:
parent
18e98ca918
commit
900a5358a8
7 changed files with 32 additions and 7 deletions
|
@ -1,3 +1,4 @@
|
||||||
class Constants {
|
class Constants {
|
||||||
static const VERSION = "1.3.010625+1127";
|
static const VERSION = "1.3.012225+0304";
|
||||||
|
static const NBT_REVISION = "1.3.012225+0304";
|
||||||
}
|
}
|
||||||
|
|
|
@ -537,7 +537,8 @@ class StringReader {
|
||||||
// Read a number (int or double)
|
// Read a number (int or double)
|
||||||
String readNumber() {
|
String readNumber() {
|
||||||
StringBuffer result = StringBuffer();
|
StringBuffer result = StringBuffer();
|
||||||
while (canRead && (isDigit(peek()) || peek() == '.' || peek() == '-')) {
|
while (canRead &&
|
||||||
|
(isDigit(peek()) || peek() == '.' || peek() == '-' || peek() == "+")) {
|
||||||
result.write(next());
|
result.write(next());
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
|
|
|
@ -73,6 +73,10 @@ enum TagType {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (val == "-" || val == "+") {
|
||||||
|
reader.next();
|
||||||
|
}
|
||||||
|
|
||||||
if (val == '{') {
|
if (val == '{') {
|
||||||
ret = TagType.Compound; // Detected a CompoundTag
|
ret = TagType.Compound; // Detected a CompoundTag
|
||||||
reader.next(); // Consume '{'
|
reader.next(); // Consume '{'
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
import '../Stream.dart';
|
import '../Stream.dart';
|
||||||
import '../Tag.dart';
|
import '../Tag.dart';
|
||||||
|
|
||||||
|
@ -41,13 +43,16 @@ class DoubleTag extends Tag {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void prettyPrint(int indent, bool recurse) {
|
void prettyPrint(int indent, bool recurse) {
|
||||||
|
NumberFormat nf = NumberFormat("###.##", "en_US");
|
||||||
print(
|
print(
|
||||||
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: $value");
|
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: ${nf.format(value)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void writeStringifiedValue(StringBuilder builder, int indent, bool isList) {
|
void writeStringifiedValue(StringBuilder builder, int indent, bool isList) {
|
||||||
builder.append("${isList ? "".padLeft(indent, '\t') : ""}${value}d");
|
NumberFormat nf = NumberFormat("###.##", "en_US");
|
||||||
|
builder.append(
|
||||||
|
"${isList ? "".padLeft(indent, '\t') : ""}${nf.format(value)}d");
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
import '../Stream.dart';
|
import '../Stream.dart';
|
||||||
import '../Tag.dart';
|
import '../Tag.dart';
|
||||||
|
|
||||||
|
@ -40,13 +42,16 @@ class FloatTag extends Tag {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void prettyPrint(int indent, bool recurse) {
|
void prettyPrint(int indent, bool recurse) {
|
||||||
|
NumberFormat nf = NumberFormat("###.##", "en_US");
|
||||||
print(
|
print(
|
||||||
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: $value");
|
"${"".padLeft(indent, '\t')}${Tag.getCanonicalName(getTagType())}: ${nf.format(value)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void writeStringifiedValue(StringBuilder builder, int indent, bool isList) {
|
void writeStringifiedValue(StringBuilder builder, int indent, bool isList) {
|
||||||
builder.append("${isList ? "".padLeft(indent, '\t') : ""}${value}f");
|
NumberFormat nf = NumberFormat("###.##", "en_US");
|
||||||
|
builder.append(
|
||||||
|
"${isList ? "".padLeft(indent, '\t') : ""}${nf.format(value)}f");
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: libac_dart
|
name: libac_dart
|
||||||
description: "Aria's Creations code library"
|
description: "Aria's Creations code library"
|
||||||
version: 1.3.010625+1127
|
version: 1.3.012225+0304
|
||||||
homepage: "https://zontreck.com"
|
homepage: "https://zontreck.com"
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
@ -11,6 +11,7 @@ dependencies:
|
||||||
crypto: ^3.0.3
|
crypto: ^3.0.3
|
||||||
dio: ^5.5.0+1
|
dio: ^5.5.0+1
|
||||||
encrypt: ^5.0.3
|
encrypt: ^5.0.3
|
||||||
|
intl: ^0.20.1
|
||||||
# path: ^1.8.0
|
# path: ^1.8.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|
|
@ -144,4 +144,12 @@ void main() {
|
||||||
CompoundTag CT =
|
CompoundTag CT =
|
||||||
await SnbtIo.readFromFile("test/displayLoreTest.snbt") as CompoundTag;
|
await SnbtIo.readFromFile("test/displayLoreTest.snbt") as CompoundTag;
|
||||||
}, timeout: Timeout(Duration(minutes: 10)));
|
}, timeout: Timeout(Duration(minutes: 10)));
|
||||||
|
|
||||||
|
test("Test negative numbers from SNBT", () async {
|
||||||
|
String snbt = "{test: -932.0d}";
|
||||||
|
|
||||||
|
CompoundTag ct = await SnbtIo.readFromString(snbt) as CompoundTag;
|
||||||
|
expect(ct["test"]!.getTagType(), TagType.Double);
|
||||||
|
expect(ct["test"]!.asDouble(), -932.0);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue