diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-01-08 20:58:39 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-01-08 20:58:39 -0300 |
commit | 13cdccf23ba639d7a30a590698cfd36ee558c794 (patch) | |
tree | c5663aa7050d6d79ef1073ac26d8ff0104a27ad4 /core/ustring.cpp | |
parent | 94ee7798ced5bc79196c971921c3109e299f8306 (diff) | |
download | redot-engine-13cdccf23ba639d7a30a590698cfd36ee558c794.tar.gz |
Variant INT and REAL are now 64 bits (other types remain at 32)
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 96 |
1 files changed, 72 insertions, 24 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index 0c26fe90c6..27bb8eac72 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -1547,20 +1547,20 @@ String::String(const StrRange& p_range) { int String::hex_to_int(bool p_with_prefix) const { - int l = length(); + int l = length(); if (p_with_prefix && l<3) return 0; - const CharType *s=ptr(); + const CharType *s=ptr(); - int sign = s[0]=='-' ? -1 : 1; + int sign = s[0]=='-' ? -1 : 1; - if (sign<0) { - s++; - l--; + if (sign<0) { + s++; + l--; if (p_with_prefix && l<2) - return 0; - } + return 0; + } if (p_with_prefix) { if (s[0]!='0' || s[1]!='x') @@ -1569,26 +1569,74 @@ int String::hex_to_int(bool p_with_prefix) const { l-=2; }; - int hex=0; + int hex=0; - while(*s) { + 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; - } + 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; + } - hex*=16; - hex+=n; - s++; - } + hex*=16; + hex+=n; + s++; + } + + return hex*sign; + +} + + +int64_t String::hex_to_int64(bool p_with_prefix) const { + + int l = length(); + if (p_with_prefix && l<3) + return 0; + + const CharType *s=ptr(); + + int64_t sign = s[0]=='-' ? -1 : 1; + + if (sign<0) { + s++; + l--; + if (p_with_prefix && l<2) + return 0; + } + + if (p_with_prefix) { + if (s[0]!='0' || s[1]!='x') + return 0; + s+=2; + l-=2; + }; + + int64_t hex=0; + + while(*s) { + + CharType c = LOWERCASE(*s); + int64_t n; + if (c>='0' && c<='9') { + n=c-'0'; + } else if (c>='a' && c<='f') { + n=(c-'a')+10; + } else { + return 0; + } + + hex*=16; + hex+=n; + s++; + } - return hex*sign; + return hex*sign; } |