diff options
author | volzhs <volzhs@gmail.com> | 2015-07-01 15:13:10 +0900 |
---|---|---|
committer | volzhs <volzhs@gmail.com> | 2015-07-01 15:13:10 +0900 |
commit | f6668dc9db34fc4a3ef9e9e309e0fc248c3f51a8 (patch) | |
tree | 0c9a6e5cd8b6d3fdfab3cb6aff41458a08841133 /core/ustring.cpp | |
parent | 903e6b37c0ed94cd0b3447dd3ff471abbfaa4460 (diff) | |
parent | b4d5f7e154973e8fb93a9a0af6ffa0b065e2c50c (diff) |
Merge branch 'master' of https://github.com/okamstudio/godot into fix_android_payments
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index 5df95ac4c2..3cfc1e4a3c 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -67,11 +67,14 @@ void String::copy_from(const char *p_cstr) { return; } + resize(len+1); // include 0 - for(int i=0;i<len+1;i++) { - - set(i,p_cstr[i]); + CharType *dst = this->ptr(); + + for (int i=0;i<len+1;i++) { + + dst[i]=p_cstr[i]; } } @@ -486,7 +489,7 @@ String String::capitalize() const { String cap; for (int i=0;i<aux.get_slice_count(" ");i++) { - String slice=aux.get_slice(" ",i); + String slice=aux.get_slicec(' ',i); if (slice.length()>0) { slice[0]=_find_upper(slice[0]); @@ -577,6 +580,41 @@ String String::get_slice(String p_splitter, int p_slice) const { } +String String::get_slicec(CharType p_splitter, int p_slice) const { + + if (empty()) + return String(); + + if (p_slice<0) + return String(); + + const CharType *c=this->ptr(); + int i=0; + int prev=0; + int count=0; + while(true) { + + + if (c[i]==0 || c[i]==p_splitter) { + + if (p_slice==count) { + + return substr(prev,i-prev); + } else { + count++; + prev=i+1; + } + + } + + i++; + + } + + return String(); //no find! + +} + Vector<String> String::split_spaces() const { @@ -3333,8 +3371,8 @@ String String::path_to(const String& p_path) const { //nothing } else { //dos style - String src_begin=src.get_slice("/",0); - String dst_begin=dst.get_slice("/",0); + String src_begin=src.get_slicec('/',0); + String dst_begin=dst.get_slicec('/',0); if (src_begin!=dst_begin) return p_path; //impossible to do this |