summaryrefslogtreecommitdiff
path: root/core/ustring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r--core/ustring.cpp110
1 files changed, 80 insertions, 30 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 6ed4dfcf25..9fb8cfc00f 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -560,7 +560,7 @@ String String::get_slice(String p_splitter, int p_slice) const {
int pos=0;
int prev_pos=0;
-// int slices=1;
+ //int slices=1;
if (p_slice<0)
return "";
if (find(p_splitter)==-1)
@@ -574,7 +574,7 @@ String String::get_slice(String p_splitter, int p_slice) const {
pos=length(); //reached end
int from=prev_pos;
- // int to=pos;
+ //int to=pos;
if (p_slice==i) {
@@ -612,6 +612,8 @@ String String::get_slicec(CharType p_splitter, int p_slice) const {
if (p_slice==count) {
return substr(prev,i-prev);
+ } else if (c[i]==0) {
+ return String();
} else {
count++;
prev=i+1;
@@ -1418,7 +1420,7 @@ bool String::parse_utf8(const char* p_utf8,int p_len) {
}
}
-// printf("char %i, len %i\n",unichar,len);
+ //printf("char %i, len %i\n",unichar,len);
if (sizeof(wchar_t)==2 && unichar>0xFFFF) {
unichar=' '; //too long for windows
@@ -1545,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')
@@ -1567,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;
}
@@ -3834,7 +3884,7 @@ String String::get_file() const {
return substr(sep+1,length());
}
-String String::extension() const {
+String String::get_extension() const {
int pos = find_last(".");
if (pos<0)
@@ -3913,7 +3963,7 @@ String String::percent_decode() const {
return String::utf8(pe.ptr());
}
-String String::basename() const {
+String String::get_basename() const {
int pos = find_last(".");
if (pos<0)