diff --git a/core/ustring.cpp b/core/ustring.cpp index 986bf089c81..698187cc293 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -1618,49 +1618,7 @@ String::String(const StrRange &p_range) { copy_from(p_range.c_str, p_range.len); } -int String::hex_to_int(bool p_with_prefix) const { - if (p_with_prefix && length() < 3) { - return 0; - } - - const CharType *s = ptr(); - - int sign = s[0] == '-' ? -1 : 1; - - if (sign < 0) { - s++; - } - - if (p_with_prefix) { - if (s[0] != '0' || s[1] != 'x') { - return 0; - } - s += 2; - } - - int hex = 0; - - while (*s) { - CharType c = LOWERCASE(*s); - int n; - if (c >= '0' && c <= '9') { - n = c - '0'; - } else if (c >= 'a' && c <= 'f') { - n = (c - 'a') + 10; - } else { - return 0; - } - - ERR_FAIL_COND_V_MSG(hex > INT32_MAX / 16, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + *this + " as integer, provided value is " + (sign == 1 ? "too big." : "too small.")); - hex *= 16; - hex += n; - s++; - } - - return hex * sign; -} - -int64_t String::hex_to_int64(bool p_with_prefix) const { +int64_t String::hex_to_int(bool p_with_prefix) const { if (p_with_prefix && length() < 3) { return 0; } @@ -3813,7 +3771,7 @@ bool String::is_valid_ip_address() const { continue; } if (n.is_valid_hex_number(false)) { - int nint = n.hex_to_int(false); + int64_t nint = n.hex_to_int(false); if (nint < 0 || nint > 0xffff) { return false; } diff --git a/core/ustring.h b/core/ustring.h index f82e31f9956..c48bca5552d 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -245,9 +245,8 @@ public: bool is_numeric() const; double to_double() const; float to_float() const; - int hex_to_int(bool p_with_prefix = true) const; - int64_t hex_to_int64(bool p_with_prefix = true) const; + int64_t hex_to_int(bool p_with_prefix = true) const; int64_t bin_to_int64(bool p_with_prefix = true) const; int64_t to_int() const; static int to_int(const char *p_str, int p_len = -1); diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index be02a8fc319..f89f647acab 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -613,13 +613,13 @@ int64_t GDAPI godot_string_char_to_int64_with_len(const wchar_t *p_str, int p_le int64_t GDAPI godot_string_hex_to_int64(const godot_string *p_self) { const String *self = (const String *)p_self; - return self->hex_to_int64(false); + return self->hex_to_int(false); } int64_t GDAPI godot_string_hex_to_int64_with_prefix(const godot_string *p_self) { const String *self = (const String *)p_self; - return self->hex_to_int64(); + return self->hex_to_int(); } int64_t GDAPI godot_string_to_int64(const godot_string *p_self) { diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 1c1104552b8..f87b6367a47 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -952,7 +952,7 @@ void GDScriptTokenizerText::_advance() { INCPOS(i); if (hexa_found) { - int64_t val = str.hex_to_int64(); + int64_t val = str.hex_to_int(); _make_constant(val); } else if (bin_found) { int64_t val = str.bin_to_int64(); diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 2ec65b7ea8e..68621e60703 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -643,7 +643,7 @@ ShaderLanguage::Token ShaderLanguage::_get_token() { } if (hexa_found) { - tk.constant = (double)str.hex_to_int64(true); + tk.constant = (double)str.hex_to_int(true); } else { tk.constant = str.to_double(); }