diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2021-01-28 07:39:05 -0500 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2021-01-28 07:43:53 -0500 |
commit | a3e3bf822761c477d3a297fe004496ffc6c7b10d (patch) | |
tree | 60b1748d82a703388947294d927fde87534286b6 /core/string/ustring.cpp | |
parent | 726967f45318359d95e3b0c359e088ca6d430292 (diff) | |
download | redot-engine-a3e3bf822761c477d3a297fe004496ffc6c7b10d.tar.gz |
Make hex_to_int and bin_to_int handle the prefix automatically
Also add BinToInt to C#
Diffstat (limited to 'core/string/ustring.cpp')
-rw-r--r-- | core/string/ustring.cpp | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 64311a7cd7..a38395b1c7 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -2097,8 +2097,9 @@ String::String(const StrRange &p_range) { copy_from(p_range.c_str, p_range.len); } -int64_t String::hex_to_int(bool p_with_prefix) const { - if (p_with_prefix && length() < 3) { +int64_t String::hex_to_int() const { + int len = length(); + if (len == 0) { return 0; } @@ -2110,10 +2111,7 @@ int64_t String::hex_to_int(bool p_with_prefix) const { s++; } - if (p_with_prefix) { - if (s[0] != '0' || s[1] != 'x') { - return 0; - } + if (len > 2 && s[0] == '0' && s[1] == 'x') { s += 2; } @@ -2140,8 +2138,9 @@ int64_t String::hex_to_int(bool p_with_prefix) const { return hex * sign; } -int64_t String::bin_to_int(bool p_with_prefix) const { - if (p_with_prefix && length() < 3) { +int64_t String::bin_to_int() const { + int len = length(); + if (len == 0) { return 0; } @@ -2153,10 +2152,7 @@ int64_t String::bin_to_int(bool p_with_prefix) const { s++; } - if (p_with_prefix) { - if (s[0] != '0' || s[1] != 'b') { - return 0; - } + if (len > 2 && s[0] == '0' && s[1] == 'b') { s += 2; } @@ -4251,7 +4247,7 @@ bool String::is_valid_ip_address() const { continue; } if (n.is_valid_hex_number(false)) { - int64_t nint = n.hex_to_int(false); + int64_t nint = n.hex_to_int(); if (nint < 0 || nint > 0xffff) { return false; } |