summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/hash_map.h4
-rw-r--r--core/math/expression.cpp2
-rw-r--r--core/ustring.cpp85
-rw-r--r--core/ustring.h10
-rw-r--r--core/variant.cpp2
5 files changed, 17 insertions, 86 deletions
diff --git a/core/hash_map.h b/core/hash_map.h
index 843430d082..10fc931e7a 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -280,13 +280,13 @@ public:
const TData &get(const TKey &p_key) const {
const TData *res = getptr(p_key);
- ERR_FAIL_COND_V(!res, *res);
+ CRASH_COND_MSG(!res, "Map key not found.");
return *res;
}
TData &get(const TKey &p_key) {
TData *res = getptr(p_key);
- ERR_FAIL_COND_V(!res, *res);
+ CRASH_COND_MSG(!res, "Map key not found.");
return *res;
}
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index 6421606ca2..13a49feb6b 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -1064,7 +1064,7 @@ Error Expression::_get_token(Token &r_token) {
if (is_float) {
r_token.value = num.to_double();
} else {
- r_token.value = num.to_int64();
+ r_token.value = num.to_int();
}
return OK;
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 444338d5ae..be242140a2 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;
}
@@ -1702,7 +1660,7 @@ int64_t String::hex_to_int64(bool p_with_prefix) const {
return hex * sign;
}
-int64_t String::bin_to_int64(bool p_with_prefix) const {
+int64_t String::bin_to_int(bool p_with_prefix) const {
if (p_with_prefix && length() < 3) {
return 0;
}
@@ -1742,32 +1700,7 @@ int64_t String::bin_to_int64(bool p_with_prefix) const {
return binary * sign;
}
-int String::to_int() const {
- if (length() == 0) {
- return 0;
- }
-
- int to = (find(".") >= 0) ? find(".") : length();
-
- int integer = 0;
- int sign = 1;
-
- for (int i = 0; i < to; i++) {
- CharType c = operator[](i);
- if (c >= '0' && c <= '9') {
- ERR_FAIL_COND_V_MSG(integer > INT32_MAX / 10, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + *this + " as integer, provided value is " + (sign == 1 ? "too big." : "too small."));
- integer *= 10;
- integer += c - '0';
-
- } else if (integer == 0 && c == '-') {
- sign = -sign;
- }
- }
-
- return integer * sign;
-}
-
-int64_t String::to_int64() const {
+int64_t String::to_int() const {
if (length() == 0) {
return 0;
}
@@ -1780,7 +1713,7 @@ int64_t String::to_int64() const {
for (int i = 0; i < to; i++) {
CharType c = operator[](i);
if (c >= '0' && c <= '9') {
- ERR_FAIL_COND_V_MSG(integer > INT64_MAX / 10, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as 64-bit integer, provided value is " + (sign == 1 ? "too big." : "too small."));
+ ERR_FAIL_COND_V_MSG(integer > INT64_MAX / 10, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as an integer, provided value is " + (sign == 1 ? "too big." : "too small."));
integer *= 10;
integer += c - '0';
@@ -1792,7 +1725,7 @@ int64_t String::to_int64() const {
return integer * sign;
}
-int String::to_int(const char *p_str, int p_len) {
+int64_t String::to_int(const char *p_str, int p_len) {
int to = 0;
if (p_len >= 0) {
to = p_len;
@@ -1802,13 +1735,13 @@ int String::to_int(const char *p_str, int p_len) {
}
}
- int integer = 0;
- int sign = 1;
+ int64_t integer = 0;
+ int64_t sign = 1;
for (int i = 0; i < to; i++) {
char c = p_str[i];
if (c >= '0' && c <= '9') {
- ERR_FAIL_COND_V_MSG(integer > INT32_MAX / 10, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + String(p_str).substr(0, to) + " as integer, provided value is " + (sign == 1 ? "too big." : "too small."));
+ ERR_FAIL_COND_V_MSG(integer > INT64_MAX / 10, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + String(p_str).substr(0, to) + " as an integer, provided value is " + (sign == 1 ? "too big." : "too small."));
integer *= 10;
integer += c - '0';
@@ -3838,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 5b13a1c704..a86849b932 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -245,13 +245,11 @@ public:
bool is_numeric() const;
double to_double() const;
float to_float() const;
- int hex_to_int(bool p_with_prefix = true) const;
- int to_int() const;
- int64_t hex_to_int64(bool p_with_prefix = true) const;
- int64_t bin_to_int64(bool p_with_prefix = true) const;
- int64_t to_int64() const;
- static int to_int(const char *p_str, int p_len = -1);
+ int64_t hex_to_int(bool p_with_prefix = true) const;
+ int64_t bin_to_int(bool p_with_prefix = true) const;
+ int64_t to_int() const;
+ static int64_t to_int(const char *p_str, int p_len = -1);
static double to_double(const char *p_str);
static double to_double(const CharType *p_str, const CharType **r_end = nullptr);
static int64_t to_int(const CharType *p_str, int p_len = -1, bool p_clamp = false);
diff --git a/core/variant.cpp b/core/variant.cpp
index 21aaa0fe9e..f6b7e2821a 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -1409,7 +1409,7 @@ Variant::operator int64_t() const {
case FLOAT:
return _data._float;
case STRING:
- return operator String().to_int64();
+ return operator String().to_int();
default: {
return 0;
}