浏览代码

Remove 32-bit String hex_to_int method

Aaron Franke 5 年之前
父节点
当前提交
e5ae89775a

+ 2 - 44
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;
 				}

+ 1 - 2
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);

+ 2 - 2
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) {

+ 1 - 1
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();

+ 1 - 1
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();
 					}