Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions core/variant/variant_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ const char *VariantParser::tk_name[TK_MAX] = {
static double stor_fix(const String &p_str) {
if (p_str == "inf") {
return INFINITY;
} else if (p_str == "inf_neg") {
} else if (p_str == "-inf" || p_str == "inf_neg") {
// inf_neg kept for compatibility.
return -INFINITY;
} else if (p_str == "nan") {
return NAN;
Expand Down Expand Up @@ -411,23 +412,20 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
if (cchar <= 32) {
break;
}

if (cchar == '-' || (cchar >= '0' && cchar <= '9')) {
StringBuffer<> token_text;
if (cchar == '-') {
token_text += '-';
cchar = p_stream->get_char();
}
if (cchar >= '0' && cchar <= '9') {
//a number

StringBuffer<> num;
#define READING_SIGN 0
#define READING_INT 1
#define READING_DEC 2
#define READING_EXP 3
#define READING_DONE 4
int reading = READING_INT;

if (cchar == '-') {
num += '-';
cchar = p_stream->get_char();
}

char32_t c = cchar;
bool exp_sign = false;
bool exp_beg = false;
Expand Down Expand Up @@ -474,7 +472,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
if (reading == READING_DONE) {
break;
}
num += c;
token_text += c;
c = p_stream->get_char();
}

Expand All @@ -483,25 +481,24 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
r_token.type = TK_NUMBER;

if (is_float) {
r_token.value = num.as_double();
r_token.value = token_text.as_double();
} else {
r_token.value = num.as_int();
r_token.value = token_text.as_int();
}
return OK;
} else if (is_ascii_alphabet_char(cchar) || is_underscore(cchar)) {
StringBuffer<> id;
bool first = true;

while (is_ascii_alphabet_char(cchar) || is_underscore(cchar) || (!first && is_digit(cchar))) {
id += cchar;
token_text += cchar;
cchar = p_stream->get_char();
first = false;
}

p_stream->saved = cchar;

r_token.type = TK_IDENTIFIER;
r_token.value = id.as_string();
r_token.value = token_text.as_string();
return OK;
} else {
r_err_str = "Unexpected character";
Expand Down Expand Up @@ -699,7 +696,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = Variant();
} else if (id == "inf") {
value = INFINITY;
} else if (id == "inf_neg") {
} else if (id == "-inf" || id == "inf_neg") {
// inf_neg kept for compatibility.
value = -INFINITY;
} else if (id == "nan") {
value = NAN;
Expand Down Expand Up @@ -1941,7 +1939,7 @@ static String rtos_fix(double p_value) {
if (p_value > 0) {
return "inf";
} else {
return "inf_neg";
return "-inf";
}
} else {
return rtoss(p_value);
Expand All @@ -1961,7 +1959,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::FLOAT: {
String s = rtos_fix(p_variant.operator double());
if (s != "inf" && s != "inf_neg" && s != "nan") {
if (s != "inf" && s != "-inf" && s != "nan") {
if (!s.contains_char('.') && !s.contains_char('e') && !s.contains_char('E')) {
s += ".0";
}
Expand Down